Permalink
Browse files

Fix pidfile in captivity (Issue #29)

  • Loading branch information...
1 parent 7e35550 commit 8ba948e432527e893df52f92edbb530bc36e98fe @micolous committed May 11, 2012
Showing with 9 additions and 4 deletions.
  1. +3 −3 platform/debian/init.d/tollgate-captivity
  2. +6 −1 tollgate/captive_landing/tproxy.py
@@ -48,7 +48,7 @@ do_start()
# 2 if daemon could not be started
#start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
# || return 1
- start-stop-daemon --start --quiet --exec $DAEMON -- -D \
+ start-stop-daemon --start --quiet --exec $DAEMON -- -D -P $PIDFILE \
$DAEMON_ARGS \
|| return 2
# Add code here, if necessary, that waits for the process to be ready
@@ -66,7 +66,7 @@ do_stop()
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
- start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --exec $DAEMON
+ start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
@@ -75,7 +75,7 @@ do_stop()
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
- start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
+ start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --pidfile $PIDFILE
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
@@ -68,6 +68,7 @@ def __init__(self, tollgate_uri, server_port, mark):
self.server_address = ('', server_port)
self.mark = mark
self.tollgate_uri = tollgate_uri
+
def run(self):
self.httpd = HTTPServer(self.server_address, TProxyRequestHandler)
@@ -83,6 +84,7 @@ def main_optparse():
parser = OptionParser(usage="%prog [-D] -l 'https://tollgate.example.com'")
parser.add_option('-D', '--daemon', action='store_true', dest='daemon', help='start as a daemon')
parser.add_option('-l', '--tollgate-uri', dest='tollgate_uri', metavar='URI', help='root URI of tollgate frontend HTTPS server')
+ parser.add_option('-P', '--pid', dest='pid_file', default='/var/run/tollgate-captivity.pid', help='Location to write the PID file. Only has effect in daemon mode. [default: %default]')
parser.add_option('-p', '--port', dest='port', type='int', metavar='PORT', help='port of the tproxy service [default: %default]', default=50080)
parser.add_option('-m', '--mark', dest='mark', type='int', metavar='MARK', help='TPROXY mark tag for this service [default: %default]', default=1)
options, args = parser.parse_args()
@@ -102,11 +104,14 @@ def main_optparse():
if options.mark <= 0 or options.mark > 255:
parser.error('Mark value is invalid.')
+ if not options.pid_file and options.daemon:
+ parser.error('No PID file specified and running in daemon mode!')
+
server = TProxyServer(options.tollgate_uri, options.port, options.mark)
if options.daemon:
from daemon import basic_daemonize
- basic_daemonize()
+ daemonize(options.pid_file)
server.run()

0 comments on commit 8ba948e

Please sign in to comment.