[projects/git-slug: 88/170] Daemonize slug_watch

glen glen at pld-linux.org
Mon Sep 21 21:46:12 CEST 2015


commit b37e915c854fe306bba8d2731bf73817bfd3d8a5
Author: Kacper Kornet <draenog at pld-linux.org>
Date:   Tue Mar 13 08:15:56 2012 +0000

    Daemonize slug_watch

 setup.py   |  2 +-
 slug_watch | 22 ++++++++++++++++++++--
 2 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/setup.py b/setup.py
index 7f51e6a..5b3bf9a 100644
--- a/setup.py
+++ b/setup.py
@@ -9,7 +9,7 @@ setup(name='git-core-slug',
       author_email='draenog at pld-linux.org',
       url='https://github.com/draenog/slug',
       classifiers=['Programming Language :: Python :: 3'],
-      packages=['git_slug'],
+      packages=['git_slug', 'Daemon'],
       data_files=[('/home/services/gitolite/adc/bin', ['trash'])],
       scripts=['slug.py', 'slug_watch']
      )
diff --git a/slug_watch b/slug_watch
index 2b39e2a..bff899e 100755
--- a/slug_watch
+++ b/slug_watch
@@ -9,6 +9,7 @@ import pyinotify
 
 from contextlib import contextmanager
 
+import Daemon.daemon
 from git_slug.gitconst import EMPTYSHA1, REFREPO, REFFILE
 from git_slug.serverconst import WATCHDIR
 from git_slug.refsdata import RemoteRefsData
@@ -75,7 +76,13 @@ class EventHandler(pyinotify.ProcessEvent):
     def process_IN_CLOSE_WRITE(self, event):
         process_file(event.pathname)
 
-def runwatch():
+def runwatch(user=None):
+    if options.user is not None:
+        uid = pwd.getpwnam(options.user).pw_uid
+        gid = pwd.getpwnam(options.user).pw_gid
+        os.setgid(gid)
+        os.setuid(uid)
+
     os.chdir(pwd.getpwuid(os.getuid()).pw_dir)
     for directory in (WATCHDIR, REFREPO_WDIR):
         if not os.path.isdir(directory):
@@ -97,4 +104,15 @@ parser.add_argument('-d', '--daemon', nargs='?', choices=['start', 'stop'], defa
 parser.add_argument('-u', '--user')
 options = parser.parse_args()
 
-runwatch()
+class SlugWatch(Daemon.daemon.daemon):
+    def __init__(self, user, pidfile):
+        super().__init__(pidfile)
+        self.user = user
+    def run(self):
+        runwatch(self.user)
+
+if options.daemon is not None:
+    daemon = SlugWatch(options.user, "/var/run/slug_watch.pid")
+    getattr(daemon, options.daemon)()
+else:
+    runwatch(options.user)
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/git-slug.git/commitdiff/4ed64f73960519a2f4fd04c42950b2c96ae795c5



More information about the pld-cvs-commit mailing list