Usage: subclass the Daemon class and override the run() method
"""
+ version = "0.2"
+
def __init__(self, pidfile,
stdin='/dev/null',
stdout='/dev/null',
self.stdout = stdout
self.stderr = stderr
self.pidfile = pidfile
+ self.umask = 0
def daemonize(self):
"""
# Decouple from parent environment
os.chdir("/")
os.setsid()
- os.umask(0)
+ self.umask = os.umask(0)
# Do second fork
try:
return
pid = str(os.getpid())
try:
+ os.umask(self.umask)
file(self.pidfile, 'w').write('%s\n' % pid)
#except IOError, wpid_err:
except Exception, wpid_err:
sys.stderr.write(u'Error trying to write pid file to %s: %s\n' %
(unicode(self.pidfile, 'utf-8'), wpid_err))
sys.exit(1)
+ os.umask(0)
atexit.register(self.delpid)
def signal_management(self):
sys.exit(1)
def delpid(self):
- os.remove(self.pidfile)
+ os.unlink(self.pidfile)
def start(self):
"""