[_modules/cubicweb] duplicate start function fix. Add force reload by removing pid if process is not running
authorArthur Lutz <arthur.lutz@logilab.fr>
Fri, 10 Jul 2015 17:55:51 +0200
changeset 44 74bfdb78987d
parent 43 854eb1b5998c
child 45 8ef114703e33
[_modules/cubicweb] duplicate start function fix. Add force reload by removing pid if process is not running
_modules/cubicweb.py
--- a/_modules/cubicweb.py	Tue Jun 09 18:12:51 2015 +0200
+++ b/_modules/cubicweb.py	Fri Jul 10 17:55:51 2015 +0200
@@ -46,13 +46,24 @@
 
 def start(name):
     '''
-    Start a Cubicweb instance
+    Start a Cubicweb instance 
 
     CLI Example::
 
         salt '*' cubicweb.start myinstance
     '''
-    return __salt__['cmd.run']('cubicweb-ctl start {0}'.format(name))
+    start_cmd = __salt__['cmd.run']('cubicweb-ctl start {0}'.format(name))
+    log.debug('start {0}: {1!r}'.format(name, start_cmd))
+    # TODO use force-restart when implemented 
+    if '--force' in start_cmd:
+        with file('/var/run/cubicweb/{0}-all-in-one.pid'.format(name), 'r') as f:
+            if __salt__['status.pid'](f.read()):
+                return start_cmd
+        __salt__['file.remove']('/var/run/cubicweb/{0}-all-in-one.pid'.format(name))
+        second_start = __salt__['cmd.run']('cubicweb-ctl start {0}'.format(name))
+        log.debug('start {0}: {1!r}'.format(name, second_start))
+        return second_start
+    return start_cmd
 
 
 def list(verbose=False):
@@ -279,14 +290,6 @@
     log.debug('delete: {0} => {1!r}'.format(name, result))
     return result
 
-def start(name):
-    '''Start an instance
-    '''
-    cmd = ('cubicweb-ctl start {0}').format(name)
-    result = __salt__['cmd.run'](cmd)
-    log.debug('start {0}: {1!r}'.format(name, result))
-    return result
-
 def stop(name):
     '''Stop an instance
     '''