From 3b6becd54b001fec82f082f88a69ccfbcc9f75da Mon Sep 17 00:00:00 2001 From: Paul Egan Date: Tue, 21 Oct 2014 16:58:16 +0100 Subject: [PATCH 1/2] Run as nobody on redhat-based systems --- init/pystatsd.init | 3 ++- pystatsd/daemon.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/init/pystatsd.init b/init/pystatsd.init index 19fd4af..1f7397c 100755 --- a/init/pystatsd.init +++ b/init/pystatsd.init @@ -50,7 +50,8 @@ start() { # Start daemons. ret=0 echo -n $"Starting $prog: " - daemon /usr/bin/pystatsd-server --port $LOCAL_PYSTATD_PORT --pct $PCT --flush-interval $FLUSH_INTERVAL --counters-prefix $COUNTERS_PREFIX --timers-prefix $TIMERS_PREFIX --graphite-host $GRAPHITE_HOST --graphite-port $GRAPHITE_PORT --daemon --pidfile $PIDFILE + install -o $USER /dev/null $PIDFILE + daemon --user $USER /usr/bin/pystatsd-server --port $LOCAL_PYSTATD_PORT --pct $PCT --flush-interval $FLUSH_INTERVAL --counters-prefix $COUNTERS_PREFIX --timers-prefix $TIMERS_PREFIX --graphite-host $GRAPHITE_HOST --graphite-port $GRAPHITE_PORT --daemon --pidfile $PIDFILE RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/pystatsd diff --git a/pystatsd/daemon.py b/pystatsd/daemon.py index 0b5156e..64bd34f 100644 --- a/pystatsd/daemon.py +++ b/pystatsd/daemon.py @@ -70,7 +70,10 @@ def start(self, *args, **kw): pid = None if os.path.exists(self.pidfile): with open(self.pidfile, 'r') as fp: - pid = int(fp.read().strip()) + try: + pid = int(fp.read().strip()) + except ValueError: + pass if pid: msg = 'pidfile (%s) exists. Daemon already running?\n' From 1c8cb13fbccc21ca8de053ac358d0da0c2a93289 Mon Sep 17 00:00:00 2001 From: Paul Egan Date: Tue, 21 Oct 2014 16:58:52 +0100 Subject: [PATCH 2/2] Don't set default runlevels in redhat init script. From Redhat/Fedora guidelines: "Only services which are really required for a vital system should define runlevels". http://fedoraproject.org/wiki/Packaging:SysVInitScript#Chkconfig_Header --- init/pystatsd.init | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/init/pystatsd.init b/init/pystatsd.init index 1f7397c..bb9d4a5 100755 --- a/init/pystatsd.init +++ b/init/pystatsd.init @@ -2,7 +2,7 @@ # # pystatsd This shell script takes care of starting and stopping pystatsd. # -# chkconfig: 2345 80 30 +# chkconfig: - 80 30 # description: Pystatsd is a front end/proxy for the Graphite stats collection and graphing server. # # processname: pystatsd @@ -13,8 +13,6 @@ # Provides: pystatsd # Required-Start: $local_fs $network # Required-Stop: $local_fs $network -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 # Short-Description: start and stop pystatsd # Description: Pystatsd is a front end/proxy for the Graphite stats collection and graphing server. ### END INIT INFO