6
6
7
7
from __future__ import with_statement
8
8
9
- import logging , os , signal , sys , time
9
+ import logging , os , signal , sys , time , errno
10
10
11
11
__all__ = ['start' , 'stop' , 'restart' , 'execute' ]
12
12
@@ -100,8 +100,14 @@ def stop(self, run=None, exit=None):
100
100
signal to the process with that as its pid. This will also wait until
101
101
the running process stops running.
102
102
"""
103
- with open (self .pid_file , 'r' ) as stream :
104
- pid = int (stream .read ())
103
+ try :
104
+ with open (self .pid_file , 'r' ) as stream :
105
+ pid = int (stream .read ())
106
+ except IOError as ioe :
107
+ if ioe .errno != errno .ENOENT :
108
+ raise
109
+ sys .stdout .write ('Stopped.\n ' )
110
+ return
105
111
sys .stdout .write ('Stopping.' )
106
112
sys .stdout .flush ()
107
113
os .kill (pid , signal .SIGTERM )
@@ -123,7 +129,7 @@ def restart(self, run, exit=None):
123
129
if os .path .exists (self .pid_file ):
124
130
self .stop (self .pid_file )
125
131
print 'Starting.'
126
- self .start (run , self . pid_file , self . log_file )
132
+ self .start (run , exit = exit )
127
133
128
134
129
135
def execute (self , action , run = None , exit = None ):
0 commit comments