diff options
author | Stef Walter <stef@thewalter.net> | 2008-06-06 22:24:40 +0000 |
---|---|---|
committer | Stef Walter <stef@thewalter.net> | 2008-06-06 22:24:40 +0000 |
commit | 70885122408498e4a11961026b9abd82b88f0bdc (patch) | |
tree | ad8dfdb3c7efc6efff96e5667a5109ca60f1b62c /slapd-pivot.py | |
parent | 390be307a7424a60db0170e4c174332b23e42cbb (diff) |
Fix daemonizing, and add pidfifile
Diffstat (limited to 'slapd-pivot.py')
-rw-r--r-- | slapd-pivot.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/slapd-pivot.py b/slapd-pivot.py index d657b1b..704c16e 100644 --- a/slapd-pivot.py +++ b/slapd-pivot.py @@ -9,6 +9,7 @@ import Backend, Pivot, Config SCRIPT = "slapd-pivot" USER = None GROUP = None +PIDFILE = None class Log: def __init__(self): @@ -16,7 +17,7 @@ class Log: def write(self, string): string = string.encode("utf-8", "replace").strip("\n\r") if string: - syslog.syslog(syslog.LOG_WARNING | syslog.LOG_DAEMON, s) + syslog.syslog(syslog.LOG_WARNING | syslog.LOG_DAEMON, string) def flush(self): pass @@ -29,13 +30,14 @@ def failure(msg, details = None): def usage(): - print >> sys.stderr, "usage: %s -f config [-d level] [-u user] [-g group]" % SCRIPT + print >> sys.stderr, "usage: %s -f config [-d level] [-g group] [-p pidfile] [-u user]" % SCRIPT sys.exit(2) def run_server(): server = Backend.Server("/tmp/pivot-slapd.sock", Pivot.Database) try: + print >> sys.stderr, "%s starting up..." % SCRIPT server.serve_forever() except KeyboardInterrupt: sys.exit(0) @@ -76,8 +78,6 @@ def daemon(): except OSError, e: failure("couldn't fork to daemon", e.strerror) - os.chdir(os.path.dirname(sys.argv[0])) - # decouple from parent environment os.setsid() os.umask(0) @@ -87,8 +87,8 @@ def daemon(): pid = os.fork() if pid > 0: # exit from second parent, print eventual PID before - # print "Daemon PID %d" % pid - open(PIDFILE,'w').write("%d"%pid) + if PIDFILE: + open(PIDFILE,'w').write("%d" % pid) sys.exit(0) except OSError, e: failure("couldn't fork to daemon", e.strerror) @@ -103,7 +103,7 @@ if __name__ == '__main__': config = "/usr/local/etc/slapd-pivot.conf" try: - opts, args = getopt.getopt(sys.argv[1:], 'd:f:g:u:') + opts, args = getopt.getopt(sys.argv[1:], 'd:f:g:p:u:') except getopt.GetoptError: usage() @@ -122,6 +122,9 @@ if __name__ == '__main__': elif opt == '-g': GROUP = oarg + elif opt == '-p': + PIDFILE = oarg + elif opt == '-u': USER = oarg |