]> git.parisson.com Git - mezzo.git/commitdiff
Add cron rules as a symlink to app own cron file
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Fri, 10 Mar 2017 12:29:31 +0000 (13:29 +0100)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Fri, 10 Mar 2017 12:29:31 +0000 (13:29 +0100)
bin/install.py
etc/cron.d/app [new file with mode: 0644]
etc/crontab [deleted file]

index 86a9c046e06620ec794101e930ab1c54c8559a55..ba340c67bcfae0fa435a9e6f49cdbe654649f58e 100755 (executable)
@@ -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 (file)
index 0000000..ce1d383
--- /dev/null
@@ -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 (file)
index 5413b26..0000000
+++ /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