summaryrefslogtreecommitdiffstats
path: root/pyLoadCore.py
diff options
context:
space:
mode:
authorGravatar therazer <devnull@localhost> 2010-11-12 21:18:46 +0100
committerGravatar therazer <devnull@localhost> 2010-11-12 21:18:46 +0100
commit75105988cf66c99c531b2bc62b5b047c22345d7e (patch)
tree0bc1bf459bf979cdeb5c60182f20420e1611138e /pyLoadCore.py
parentclosed #185 (diff)
downloadpyload-75105988cf66c99c531b2bc62b5b047c22345d7e.tar.xz
adding pidfile support
Diffstat (limited to 'pyLoadCore.py')
-rwxr-xr-xpyLoadCore.py30
1 files changed, 26 insertions, 4 deletions
diff --git a/pyLoadCore.py b/pyLoadCore.py
index c08b29f60..9cf51e100 100755
--- a/pyLoadCore.py
+++ b/pyLoadCore.py
@@ -80,6 +80,8 @@ class Core(object):
def __init__(self):
self.doDebug = False
self.arg_links = []
+
+ self.pidfile = "./pyload.pid"
if len(argv) > 1:
try:
@@ -162,10 +164,28 @@ class Core(object):
self.shutdown()
self.log.info(_("Received Quit signal"))
_exit(1)
-
+
+ def writePidFile(self):
+ self.deletePidFile()
+ pid = os.getpid()
+ f = open(self.pidfile, "w")
+ f.write(str(pid))
+ f.close()
+
+ def deletePidFile(self):
+ if self.checkPidFile():
+ self.log.debug("deleting old pidfile %s" % self.pidfile)
+ os.remove(self.pidfile)
+
+ def checkPidFile(self):
+ if os.path.isfile(self.pidfile):
+ return True
+ else:
+ return False
+
def start(self, xmlrpc=True, web=True):
""" starts the fun :D """
-
+
if not exists("pyload.conf"):
from module.setup import Setup
@@ -315,13 +335,15 @@ class Core(object):
f.close()
self.scheduler.addJob(0, self.accountManager.getAccountInfos)
-
+
+ self.writePidFile()
+
while True:
sleep(2)
if self.do_restart:
self.log.info(_("restarting pyLoad"))
self.restart()
- if self.do_kill:
+ if self.do_kill or not self.checkPidFile():
self.shutdown()
self.log.info(_("pyLoad quits"))
self.removeLogger()