Created
October 9, 2016 16:36
-
-
Save quasoft/2b7a1b11be70540dfe396019f2bdd758 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import signal | |
import daemon | |
import lockfile | |
import time | |
def start(): | |
print("Initial setup") | |
def stop(): | |
print("Cleanup") | |
def reload(): | |
print("Reload config") | |
def run(): | |
while True: | |
print("Main program") | |
time.sleep(10) | |
context = daemon.DaemonContext( | |
working_directory='/', | |
umask=2, | |
pidfile=lockfile.FileLock('/tmp/mylockfile') | |
) | |
context.signal_map = { | |
signal.SIGTERM: stop, | |
signal.SIGHUP: 'terminate', | |
signal.SIGUSR1: reload, | |
} | |
# No need to change gid, as we want our service to run without root | |
#context.gid = grp.getgrnam('nogroup').gr_gid | |
# No files to preserve | |
#context.files_preserve = [important_file, interesting_file] | |
start() | |
with context: | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment