mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-04-13 09:42:01 +00:00
24 lines
643 B
Python
24 lines
643 B
Python
import errno
|
|
import os
|
|
|
|
|
|
def daemonize():
|
|
"""
|
|
Detach from the terminal and continue as a daemon.
|
|
"""
|
|
# swiped from twisted/scripts/twistd.py
|
|
# See http://www.erlenstar.demon.co.uk/unix/faq_toc.html#TOC16
|
|
if os.fork(): # launch child and...
|
|
os._exit(0) # kill off parent
|
|
os.setsid()
|
|
if os.fork(): # launch child and...
|
|
os._exit(0) # kill off parent again.
|
|
os.umask(0o77)
|
|
null = os.open("/dev/null", os.O_RDWR)
|
|
for i in range(3):
|
|
try:
|
|
os.dup2(null, i)
|
|
except OSError as e:
|
|
if e.errno != errno.EBADF:
|
|
raise
|
|
os.close(null)
|