The branch, master has been updated via 9cc96c24034b67ce69434d66b392f1ff1b59eaab (commit) from 292c63786872749fd4c10ca0106d4cd1142bb327 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 9cc96c24034b67ce69434d66b392f1ff1b59eaab Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Thu Dec 19 22:11:11 2013 +0100 Support daemonizing of the http broker. ----------------------------------------------------------------------- Summary of changes: bin/x2gobroker | 47 ++++++++++++++++++++++++++++++++++++++++++++++- debian/changelog | 1 + 2 files changed, 47 insertions(+), 1 deletion(-) The diff of changes is: diff --git a/bin/x2gobroker b/bin/x2gobroker index 0b4c881..35ed455 100755 --- a/bin/x2gobroker +++ b/bin/x2gobroker @@ -28,6 +28,18 @@ import socket import logging import thread +try: + import daemonize + CAN_DAEMONIZE = True + if os.path.isdir('/run'): + RUNDIR = '/run' + else: + RUNDIR = '/var/run' + pidfile = '{run}/x2gobroker/x2gobroker-daemon.pid'.format(run=RUNDIR) +except ImportError: + CAN_DAEMONIZE = False + + def prep_http_mode(): global urls @@ -93,6 +105,11 @@ if __name__ == "__main__": daemon_options = [ {'args':['-b', '--bind'], 'default': None, 'metavar': 'BIND_ADDRESS', 'help': 'The [address:]port that the web.py http-engine shall bind to (default: 127.0.0.1:8080)', }, ] + if CAN_DAEMONIZE: + daemon_options.extend([ + {'args':['-D', '--daemonize'], 'default': False, 'action': 'store_true', 'help': 'Detach the X2Go Broker process from the current terminal and fork to background', }, + {'args':['-P', '--pidfile'], 'default': pidfile, 'help': 'Alternative file path for the daemon\'s PID file', }, + ]) sshbroker_options = [ {'args':['--task'], 'default': None, 'metavar': 'BROKER_TASK', 'help': 'broker task (listsessions, selectsession, setpass, testcon', }, {'args':['--user'], 'default': None, 'metavar': 'USER_NAME', 'help': 'Operate on behalf of this user name', }, @@ -136,6 +153,7 @@ if __name__ == "__main__": sys.exit(-1) elif cmdline_args.mode.upper() == 'SSH': if cmdline_args.bind: logger_broker.warn('ignoring non-valid option --bind for broker mode SSH...') + if cmdline_args.daemonize: logger_broker.warn('ignoring non-valid option --daemonize for broker mode SSH...') if cmdline_args.profile_id and cmdline_args.task != 'selectsession': #logger_broker.warn('ignoring option --sid as it only has a meaning with ,,--task selectsession\'\'') pass @@ -163,6 +181,20 @@ if __name__ == "__main__": if cmdline_args.task: logger_broker.warn('ignoring non-valid option --task for broker mode HTTP...') if cmdline_args.profile_id: logger_broker.warn('ignoring non-valid option --profile-id for broker mode HTTP...') + if cmdline_args.daemonize: + pidfile = os.path.expanduser(cmdline_args.pidfile) + if not os.path.isdir(os.path.dirname(pidfile)): + try: + os.makedirs(os.path.dirname(pidfile)) + except: + pass + if not os.access(os.path.dirname(pidfile), os.W_OK) or (os.path.exists(pidfile) and not os.access(pidfile, os.W_OK)): + print("") + p.print_usage() + print("Insufficent privileges. Cannot create PID file {pidfile} path".format(pidfile=pidfile)) + print("") + sys.exit(-3) + # some people just give the port but prepend a colon, webpy does not like this, so we strip if off cmdline_args.bind = cmdline_args.bind.lstrip('*') cmdline_args.bind = cmdline_args.bind.lstrip(':') @@ -183,6 +215,7 @@ if x2gobroker.defaults.X2GOBROKER_DEBUG and not x2gobroker.defaults.X2GOBROKER_T logger_access.setLevel(logging.DEBUG) logger_error.setLevel(logging.DEBUG) + # run the Python Tornado standalone daemon or handle interactive command line execution (via SSH) if __name__ == "__main__": @@ -197,6 +230,11 @@ if __name__ == "__main__": import tornado.web import tornado.httpserver import tornado.ioloop + + def launch_ioloop(): + logger_broker.info('Forking daemon to background, PID file is: {pidfile}'.format(pidfile=pidfile)) + tornado.ioloop.IOLoop.instance().start() + application = tornado.web.Application(urls, **settings) try: if x2gobroker.defaults.X2GOBROKER_SSL_CERTFILE and x2gobroker.defaults.X2GOBROKER_SSL_KEYFILE: @@ -211,7 +249,14 @@ if __name__ == "__main__": # run without https http_server = tornado.httpserver.HTTPServer(application) http_server.listen(bind_port, address=bind_address) - tornado.ioloop.IOLoop.instance().start() + + if cmdline_args.daemonize: + keep_fds = [int(fd) for fd in os.listdir('/proc/self/fd') if fd not in (0,1,2) ] + daemon = daemonize.Daemonize(app="x2gobroker", pid=pidfile, action=launch_ioloop, keep_fds=keep_fds) + daemon.start() + else: + launch_ioloop() + except socket.error as e: print (e) diff --git a/debian/changelog b/debian/changelog index 9dd0ee7..1fe4749 100644 --- a/debian/changelog +++ b/debian/changelog @@ -67,6 +67,7 @@ x2gobroker (0.0.3.0-0x2go1) UNRELEASED; urgency=low - Adapt man page installation to moval of x2gobroker(-testauth) from an sbin to a bin directory (executable for any user). - Make the inifile broker backend the default backend. + - Support daemonizing of the http broker. * debian/control: + Replace LDAP support with session brokerage support in LONG_DESCRIPTION. + Fix SYNOPSIS texts. hooks/post-receive -- x2gobroker.git (HTTP(S) Session broker for X2Go) This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "x2gobroker.git" (HTTP(S) Session broker for X2Go).