[X2Go-Commits] x2gobroker.git - master (branch) updated: 0.0.2.3-125-g848af71

X2Go dev team git-admin at x2go.org
Fri Dec 20 10:18:56 CET 2013


The branch, master has been updated
       via  848af7187009aa6af1411584fdcbb9b1b8d4c101 (commit)
      from  4c738f9ac94a649c5ce51968c3d708a4b6830af0 (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 848af7187009aa6af1411584fdcbb9b1b8d4c101
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date:   Fri Dec 20 10:18:46 2013 +0100

    switch to python-daemon for daemonizing...

-----------------------------------------------------------------------

Summary of changes:
 bin/x2gobroker                    |   26 +++++++++++++++++++++++---
 debian/control                    |    2 ++
 man/man1/x2gobroker.1             |    3 +++
 man/man8/x2gobroker-authservice.8 |    3 +++
 sbin/x2gobroker-authservice       |   30 +++++++++++++++++++++++++++---
 x2gobroker.spec                   |    2 ++
 6 files changed, 60 insertions(+), 6 deletions(-)

The diff of changes is:
diff --git a/bin/x2gobroker b/bin/x2gobroker
index 8e4c5bf..0cc7365 100755
--- a/bin/x2gobroker
+++ b/bin/x2gobroker
@@ -29,13 +29,15 @@ import logging
 import thread
 
 try:
-    import daemonize
+    import daemon
+    import lockfile
     CAN_DAEMONIZE = True
     if os.path.isdir('/run'):
         RUNDIR = '/run'
     else:
         RUNDIR = '/var/run'
     pidfile = '{run}/x2gobroker/x2gobroker-daemon.pid'.format(run=RUNDIR)
+    daemon_logdir = '/var/log/x2gobroker/'
 except ImportError:
     CAN_DAEMONIZE = False
 
@@ -109,6 +111,7 @@ if __name__ == "__main__":
         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', },
+            {'args':['-L', '--logdir'], 'default': daemon_logdir, 'help': 'Directory where log files for the process\'s stdout and stderr can be created', },
         ])
     sshbroker_options = [
         {'args':['--task'], 'default': None, 'metavar': 'BROKER_TASK', 'help': 'broker task (listsessions, selectsession, setpass, testcon', },
@@ -194,6 +197,21 @@ if __name__ == "__main__":
                 print("Insufficent privileges. Cannot create PID file {pidfile} path".format(pidfile=pidfile))
                 print("")
                 sys.exit(-3)
+            daemon_logdir = os.path.expanduser(cmdline_args.logdir)
+            if not os.path.isdir(daemon_logdir):
+                try:
+                    os.makedirs(daemon_logdir)
+                except:
+                    pass
+            if not os.access(daemon_logdir, os.W_OK):
+                print("")
+                p.print_usage()
+                print("Insufficent privileges. Cannot create directory for stdout/stderr log files: {logdir}".format(logdir=daemon_logdir))
+                print("")
+                sys.exit(-3)
+            else:
+                if not daemon_logdir.endswith('/'):
+                    daemon_logdir += '/'
 
         # 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('*')
@@ -252,8 +270,10 @@ if __name__ == "__main__":
 
             if CAN_DAEMONIZE and 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()
+                daemon_stdout = file(daemon_logdir+'x2gobroker-daemon.stdout', 'w+')
+                daemon_stderr = file(daemon_logdir+'x2gobroker-daemon.stderr', 'w+')
+                with daemon.DaemonContext(stdout=daemon_stdout, stderr=daemon_stderr, files_preserve=keep_fds, umask=0o027, pidfile=lockfile.FileLock(pidfile)):
+                    launch_ioloop()
             else:
                 launch_ioloop()
 
diff --git a/debian/control b/debian/control
index f90379b..b1a9fa8 100644
--- a/debian/control
+++ b/debian/control
@@ -23,6 +23,8 @@ Depends:
  ${python:Depends},
  ${misc:Depends},
  python,
+ python-daemon,
+ python-lockfile,
  python-pampy,
  python-netaddr,
  python-tornado,
diff --git a/man/man1/x2gobroker.1 b/man/man1/x2gobroker.1
index 43958c0..fea10ac 100644
--- a/man/man1/x2gobroker.1
+++ b/man/man1/x2gobroker.1
@@ -77,6 +77,9 @@ Fork this application to background and detach from the running terminal.
 .TP
 \*(T<\fB\-P, \-\-pidfile\fR\*(T>
 Custom PID file location when daemonizing (default: <RUNDIR>/x2gobroker/x2gobroker-daemon.pid).
+.TP
+\*(T<\fB\-L, \-\-logdir\fR\*(T>
+Directory where stdout/stderr will be redirected after having daemonized (default: /var/log/x2gobroker/).
 .SH "FILES"
 /etc/x2go/x2gobroker.conf, /etc/x2go/broker/* (configuration files)
 .PP
diff --git a/man/man8/x2gobroker-authservice.8 b/man/man8/x2gobroker-authservice.8
index af9faa0..592426f 100644
--- a/man/man8/x2gobroker-authservice.8
+++ b/man/man8/x2gobroker-authservice.8
@@ -44,6 +44,9 @@ Fork this application to background and detach from the running terminal.
 \*(T<\fB\-P, \-\-pidfile\fR\*(T>
 Custom PID file location when daemonizing (default: <RUNDIR>/x2gobroker/x2gobroker-authservice.pid).
 .TP
+\*(T<\fB\-L, \-\-logdir\fR\*(T>
+Directory where stdout/stderr will be redirected after having daemonized (default: /var/log/x2gobroker/).
+.TP
 \*(T<\fB\-s <AUTHSOCKET>, \-\-socket <AUTHSOCKET>\fR\*(T>
 File name of the unix domain socket file used for communication between broker and authentication service.
 .TP
diff --git a/sbin/x2gobroker-authservice b/sbin/x2gobroker-authservice
index b5d93cf..aedf233 100755
--- a/sbin/x2gobroker-authservice
+++ b/sbin/x2gobroker-authservice
@@ -33,13 +33,15 @@ import logging.config
 import pam
 
 try:
-    import daemonize
+    import daemon
+    import lockfile
     CAN_DAEMONIZE = True
     if os.path.isdir('/run'):
         RUNDIR = '/run'
     else:
         RUNDIR = '/var/run'
     pidfile = '{run}/x2gobroker/x2gobroker-authservice.pid'.format(run=RUNDIR)
+    daemon_logdir = '/var/log/x2gobroker/'
 except ImportError:
     CAN_DAEMONIZE = False
 
@@ -173,6 +175,7 @@ if __name__ == '__main__':
         common_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', },
+            {'args':['-L', '--logdir'], 'default': daemon_logdir, 'help': 'Directory where log files for the process\'s stdout and stderr can be created', },
         ])
     p = argparse.ArgumentParser(description='X2Go Session Broker (PAM Authentication Service)',\
                                 formatter_class=argparse.RawDescriptionHelpFormatter, \
@@ -188,6 +191,8 @@ if __name__ == '__main__':
     cmdline_args = p.parse_args()
 
     if CAN_DAEMONIZE and cmdline_args.daemonize:
+
+        # create directory for the PID file
         pidfile = os.path.expanduser(cmdline_args.pidfile)
         if not os.path.isdir(os.path.dirname(pidfile)):
             try:
@@ -201,13 +206,32 @@ if __name__ == '__main__':
             print("")
             sys.exit(-3)
 
+        # create directory for logging
+        daemon_logdir = os.path.expanduser(cmdline_args.logdir)
+        if not os.path.isdir(daemon_logdir):
+            try:
+                os.makedirs(daemon_logdir)
+            except:
+                pass
+        if not os.access(daemon_logdir, os.W_OK):
+            print("")
+            p.print_usage()
+            print("Insufficent privileges. Cannot create directory for stdout/stderr log files: {logdir}".format(logdir=daemon_logdir))
+            print("")
+            sys.exit(-3)
+        else:
+            if not daemon_logdir.endswith('/'):
+                daemon_logdir += '/'
+
     socket_file = cmdline_args.socket_file
     AuthService(socket_file, owner=cmdline_args.owner, group_owner=cmdline_args.group, permissions=cmdline_args.permissions)
     try:
         if CAN_DAEMONIZE and 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=loop, keep_fds=keep_fds)
-            daemon.start()
+            daemon_stdout = file(daemon_logdir+'x2gobroker-daemon.stdout', 'w+')
+            daemon_stderr = file(daemon_logdir+'x2gobroker-daemon.stderr', 'w+')
+            with daemon.DaemonContext(stdout=daemon_stdout, stderr=daemon_stderr, files_preserve=keep_fds, umask=0o027, pidfile=lockfile.FileLock(pidfile)):
+                loop()
         else:
             loop()
     except KeyboardInterrupt:
diff --git a/x2gobroker.spec b/x2gobroker.spec
index 04763eb..d053050 100644
--- a/x2gobroker.spec
+++ b/x2gobroker.spec
@@ -55,6 +55,8 @@ Requires:       python-pampy
 Requires:       python-netaddr
 Requires:       python-tornado
 Requires:       paramiko
+Requires:       python-daemon
+Requires:       python-lockfile
 
 %description -n python-x2gobroker
 X2Go is a server based computing environment with


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).




More information about the x2go-commits mailing list