1- #!/usr/bin/env python2
1+ #!/usr/bin/python
22
33import os , sys
44from os .path import join as J
@@ -11,7 +11,7 @@ sys.path.insert(0, root_path)
1111from pwl .utils .daemon import BaseDaemon
1212from application import app
1313
14- run_path = J (app .config .root_path , ' var/run' )
14+ run_path = J (app .config .root_path , app . config . get ( 'RUN_PATH' , ' var/run') )
1515
1616try :
1717 action = sys .argv [1 ]
@@ -23,7 +23,7 @@ class RstedDaemon(BaseDaemon):
2323 NO_WRITE_PID = True
2424
2525 def run (self ):
26- os .system (J (app .config .root_path , 'rsted.fcgi' ))
26+ os .system ('python ' + J (app .config .root_path , 'rsted.fcgi' ))
2727
2828 def print_status (self ):
2929 pidexists = os .path .exists (self .pidfile )
@@ -33,7 +33,26 @@ class RstedDaemon(BaseDaemon):
3333 count = int (os .popen ("ps --pid %d --no-heading| wc -l" % pid ).read ().strip ())
3434 running = count > 0
3535 print "Running: %s" % ('Yes' if running else 'No' )
36-
36+
37+ def is_running (self ):
38+ pidexists = os .path .exists (self .pidfile )
39+ if pidexists :
40+ pid = self .readpid ()
41+ count = int (os .popen ("ps --pid %d --no-heading| wc -l" % pid ).read ().strip ())
42+ return count > 0
43+ return False
44+
45+ def ensure_started (self ):
46+ if not self .is_running ():
47+ self .delpid ()
48+ self .start ()
49+
50+ chmod_socket = app .config .get ('CHMOD_SOCKET' )
51+ socket_file = os .path .join (run_path , app .config .get ('SOCKET_FILE' , 'rsted.sock' ))
52+
53+ if chmod_socket :
54+ chmod_socket = str (chmod_socket )
55+ os .popen ("chmod %s %s" % (chmod_socket , socket_file ))
3756
3857pidfile = J (run_path , 'fastcgi.pid' )
3958daemon = RstedDaemon (pidfile )
@@ -46,6 +65,10 @@ elif action == 'restart':
4665 daemon .restart ()
4766elif action == 'status' :
4867 daemon .print_status ()
49-
68+ elif action == 'check' :
69+ if not daemon .is_running ():
70+ sys .exit (1 )
71+ elif action == 'ensure_started' :
72+ daemon .ensure_started ()
5073
5174
0 commit comments