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:
sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror))
sys.exit(1)
+ self.write_pid()
# redirect standard file descriptors
sys.stdout.flush()
sys.stderr.flush()
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):
"""
sys.stderr.write(message % self.pidfile)
sys.exit(1)
- self.write_pid()
# Start the daemon
self.daemonize()
self.run()