From 0f2c37f1917e71bb5855283f74ad0238991802bf Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Fri, 10 Mar 2017 13:29:31 +0100 Subject: [PATCH] Add cron rules as a symlink to app own cron file --- bin/install.py | 25 +++++++------------------ etc/cron.d/app | 7 +++++++ etc/crontab | 3 --- 3 files changed, 14 insertions(+), 21 deletions(-) create mode 100644 etc/cron.d/app delete mode 100644 etc/crontab diff --git a/bin/install.py b/bin/install.py index 86a9c046..ba340c67 100755 --- a/bin/install.py +++ b/bin/install.py @@ -106,17 +106,14 @@ class DockerCompositionInstaller(object): docker_compose = '/usr/local/bin/docker-compose' cron_rule = "0 */6 * * * %s %s" - def __init__(self, config='docker-compose.yml', init_type='sysvinit', cron=False, user=None): + def __init__(self, config='docker-compose.yml', init_type='sysvinit', cron=False): self.init_type = init_type self.path = os.path.dirname(os.path.realpath(__file__)) self.config = config - self.config = os.path.abspath(self.get_root() + os.sep + self.config) + self.root = self.get_root() + self.config = os.path.abspath(self.root + os.sep + self.config) self.name = self.config.split(os.sep)[-2].lower() self.cron = cron - if user: - self.user = user - else: - self.user = "root" def get_root(self): path = self.path @@ -156,18 +153,11 @@ class DockerCompositionInstaller(object): os.system('systemctl daemon-reload') def install_cron(self): - # version with migration - # without migration - log_path = "/var/log/"+ self.name + cron_path = os.sep.join([self.root, 'etc', 'cron.d', 'app']) + log_path = os.sep.join([self.root, 'var', 'log', 'cron']) if not os.path.exists(log_path) : os.makedirs(log_path, 0o755) - os.chown(log_path, getpwnam(self.user).pw_uid, getgrnam(self.user).gr_gid) - path = "PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin\n" - command = "cd /srv/"+self.name+" && ./bin/push.sh >> /var/log/"+ self.name +"/"+self.name+"-push.log 2>&1 \n" - rule = self.cron_rule % (self.user, command) - f = open('/etc/cron.d/' + self.name, 'w') - f.write(path + rule) - f.close() + os.symlink(cron_path, '/etc/cron.d/' + self.name) def uninstall_daemon_sysvinit(self): script = '/etc/init.d/' + self.name @@ -210,7 +200,6 @@ def main(): parser = argparse.ArgumentParser(description=description) parser.add_argument('--uninstall', help='uninstall the daemon', action='store_true') parser.add_argument('--cron', help='install cron backup rule', action='store_true') - parser.add_argument('--user', help='specify user', type=str) parser.add_argument('--systemd', help='use systemd', action='store_true') parser.add_argument('composition_file', nargs='?', help='the path of the YAML composition file to use (optional)') @@ -223,7 +212,7 @@ def main(): if args['composition_file']: config = args['composition_file'] - installer = DockerCompositionInstaller(config, init_type, args['cron'], args['user']) + installer = DockerCompositionInstaller(config, init_type, args['cron']) if args['uninstall']: installer.uninstall() else: diff --git a/etc/cron.d/app b/etc/cron.d/app new file mode 100644 index 00000000..ce1d3837 --- /dev/null +++ b/etc/cron.d/app @@ -0,0 +1,7 @@ +APP=vertigo +LOG=/srv/$APP/var/log +PATH=$PATH/usr/sbin:/sbin:/bin:/srv/$APP/bin/ + +0 */6 * * * root push.sh >> $LOG/push.log 2>&1 +*/10 * * * * root poll_twitter.sh >> $LOG/pull_twitter.log 2>&1 +#0,30 * * * * root upgrade.sh >> $LOG/upgrade.log 2>&1 diff --git a/etc/crontab b/etc/crontab deleted file mode 100644 index 5413b26c..00000000 --- a/etc/crontab +++ /dev/null @@ -1,3 +0,0 @@ -0 */6 * * * push.sh >> $LOG/push.log 2>&1 -*/10 * * * * poll_twitter.sh >> $LOG/pull_twitter.log 2>&1 -#0,30 * * * * upgrade.sh >> $LOG/vertigo-upgrade.log 2>&1 -- 2.39.5