summaryrefslogtreecommitdiff
path: root/paste
diff options
context:
space:
mode:
authorianb <devnull@localhost>2005-06-10 21:57:06 +0000
committerianb <devnull@localhost>2005-06-10 21:57:06 +0000
commit5fa60f809e59704cc24cd9024f0c425b293d4cc4 (patch)
tree9d84d14f141151f495c78e25bf73d1e4960e169f /paste
parentd7bd5530e7c55f0af4a5830b41af6889cc827a89 (diff)
downloadpaste-5fa60f809e59704cc24cd9024f0c425b293d4cc4.tar.gz
Check for existance of PID file, warn if PID file exists, raise error when the process still exists
Diffstat (limited to 'paste')
-rw-r--r--paste/app_setup.py28
1 files changed, 25 insertions, 3 deletions
diff --git a/paste/app_setup.py b/paste/app_setup.py
index a227c2a..9cd9f20 100644
--- a/paste/app_setup.py
+++ b/paste/app_setup.py
@@ -306,6 +306,8 @@ class CommandServe(Command):
conf = self.config
verbose = conf.get('verbose') or 0
if conf.get('daemon'):
+ if not conf.get('pid_file'):
+ conf['pid_file'] = 'server.pid'
# We must enter daemon mode!
if verbose > 1:
print 'Entering daemon mode'
@@ -313,11 +315,27 @@ class CommandServe(Command):
if pid:
sys.exit()
# Always record PID and output when daemonized
- if not conf.get('pid_file'):
- conf['pid_file'] = 'server.pid'
if not conf.get('log_file'):
conf['log_file'] = 'server.log'
if conf.get('pid_file'):
+ pid_file = conf['pid_file']
+ if os.path.exists(pid_file):
+ f = open(pid_file)
+ pid = int(f.read().strip())
+ f.close()
+ pid_exists = False
+ try:
+ os.kill(pid, 0)
+ except OSError:
+ print 'Warning: PID file %s exists, but process does not exist' % pid_file
+ os.unlink(pid_file)
+ except Exception, e:
+ raise InvalidCommand(
+ 'Could not check for process existance: %s' % e)
+ else:
+ raise InvalidCommand(
+ 'Server process already running with pid %s' % pid)
+
# @@: We should check if the pid file exists and has
# an active process in it
if verbose > 1:
@@ -334,7 +352,11 @@ class CommandServe(Command):
+ ' Starting server PID: %s ' % os.getpid()
+ '-'*20 + '\n')
self.change_user_group(conf.get('user'), conf.get('group'))
- sys.exit(server.run_server(conf, self.app))
+ try:
+ sys.exit(server.run_server(conf, self.app))
+ finally:
+ if conf.get('pid_file'):
+ os.unlink(conf['pid_file'])
def change_user_group(self, user, group):
if not user and not group: