Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

re-implement daemonize #8011

Merged
merged 3 commits into from
Aug 4, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions synapse/util/daemonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ def daemonize_process(pid_file: str, logger: logging.Logger, chdir: str = "/") -
os.dup2(devnull_fd, 2)
os.close(devnull_fd)

# now that we have redirected stderr to /dev/null, any uncaught exceptions will
# get sent to /dev/null, so make sure we log them.
#
# (we don't normally except reactor.run to raise any exceptions, but this will
richvdh marked this conversation as resolved.
Show resolved Hide resolved
# also catch any other uncaught exceptions before we get that far.)

def excepthook(type_, value, traceback):
logger.critical("Unhanded exception", exc_info=(type_, value, traceback))

sys.excepthook = excepthook

# Set umask to default to safe file permissions when running as a root daemon. 027
# is an octal number which we are typing as 0o27 for Python3 compatibility.
os.umask(0o27)
Expand Down