[Opensrf-commits] r2067 - in trunk: . src/python (dbs)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Nov 9 11:21:17 EST 2010


Author: dbs
Date: 2010-11-09 11:21:15 -0500 (Tue, 09 Nov 2010)
New Revision: 2067

Added:
   trunk/src/python/opensrf.py.in
Removed:
   trunk/src/python/opensrf.py
Modified:
   trunk/configure.ac
Log:
Give opensrf.py reasonable defaults for options

Rather than:
opensrf.py -l -d -f /openils/conf/opensrf_core.xml -p /openils/var/run/ -a start_all

you can now use:
opensrf.py -l -d -a start_all

Isn't that better? Note that we put the PIDs into PID_DIR/run/opensrf/
so that if/when OpenSRF is installed outside of the /openils/ prefix,
the names of the processes won't conflict with any other application PIDs.
Unlikely, but you never know.


Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2010-11-09 15:58:21 UTC (rev 2066)
+++ trunk/configure.ac	2010-11-09 16:21:15 UTC (rev 2067)
@@ -340,6 +340,7 @@
 			 src/libopensrf/Makefile
 			 src/perl/Makefile
 			 src/ports/strn_compat/Makefile
+			 src/python/opensrf.py
 			 src/router/Makefile
 			 src/srfsh/Makefile
 			 bin/opensrf-perl.pl

Deleted: trunk/src/python/opensrf.py
===================================================================
--- trunk/src/python/opensrf.py	2010-11-09 15:58:21 UTC (rev 2066)
+++ trunk/src/python/opensrf.py	2010-11-09 16:21:15 UTC (rev 2067)
@@ -1,237 +0,0 @@
-#!/usr/bin/python
-# -----------------------------------------------------------------------
-# Copyright (C) 2008  Equinox Software, Inc.
-# Bill Erickson <erickson at esilibrary.com>
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301, USA
-# -----------------------------------------------------------------------
-
-'''
-Provides an environment for managing OpenSRF services written in Python
-'''
-
-import sys, getopt, os, signal
-import osrf.system, osrf.server, osrf.app, osrf.set, osrf.json
-
-def do_help():
-    '''
-    Print help for the OpenSRF Python application process manager
-    '''
-
-    print '''
-    Manage OpenSRF application processes
-
-    Options:
-        -a <action>
-            start   -- Start a service
-            stop    -- stop a service
-            restart -- restart a service
-            start_all -- Start all services
-            stop_all -- Stop all services
-            restart_all -- Restart all services
-
-        -s <service>
-            The service name
-
-        -f <config file>
-            The OpenSRF config file
-
-        -c <config context>
-            The OpenSRF config file context
-
-        -p <PID dir>
-            The location of application PID files.  Default is /tmp
-
-        -d 
-            If set, run in daemon (background) mode.  This creates a PID 
-            file for managing the process.
-
-        -l
-            If set, run in 'localhost' mode
-
-        -h
-            Prints help message
-    '''
-    sys.exit(0)
-
-def get_pid_file(service):
-    '''
-    Return the PID file for the named service
-    '''
-
-    return "%s/%s.pid" % (pid_dir, service)
-
-def do_init():
-    '''
-    Initialize the Python service environment
-    '''
-
-    global domain
-    global settings
-
-    # connect to the OpenSRF network
-    osrf.system.System.net_connect(
-        config_file = config_file, config_context = config_ctx)
-
-    if as_localhost:
-        domain = 'localhost'
-    else:
-        domain = osrf.conf.get('domain')
-
-    osrf.set.load(domain)
-
-    settings = osrf.set.get('apps')
-
-    for key in settings.keys():
-        svc = settings[key]
-        if isinstance(svc, dict) and 'language' in svc and svc['language'] == 'python':
-            services[key] = svc
-
-
-def do_start(service):
-    '''
-    Start the named Python service
-    '''
-
-    pidfile = get_pid_file(service)
-
-    if service not in services:
-        print "* service %s is not a 'python' application" % service
-        return
-
-    if os.path.exists(pidfile):
-        print "* service %s already running" % service
-        return
-
-    print "* starting %s" % service
-
-    if as_daemon:
-
-        if osrf.system.System.daemonize(False):
-            return # parent process returns
-
-        # write PID file
-        pid_fd = open(pidfile, 'w')
-        pid_fd.write(str(os.getpid()))
-        pid_fd.close()
-
-    svc_settings = services[service]
-
-    osrf.app.Application.load(service, svc_settings['implementation'])
-    osrf.app.Application.register_sysmethods()
-    osrf.app.Application.application.global_init()
-
-    controller = osrf.server.Controller(service)
-    controller.max_requests = svc_settings['unix_config']['max_requests']
-    controller.max_children = svc_settings['unix_config']['max_children']
-    controller.min_children = svc_settings['unix_config']['min_children']
-    controller.keepalive = svc_settings['keepalive']
-
-    controller.run()
-    os._exit(0)
-
-def do_start_all():
-    '''
-    Start all Python services listed in the OpenSRF configuration file
-    '''
-
-    print "* starting all services for %s " % domain
-    for service in services.keys():
-        do_start(service)
-
-def do_stop_all():
-    '''
-    Stop all Python services listed in the OpenSRF configuration file
-    '''
-
-    print "* stopping all services for %s " % domain
-    for service in services.keys():
-        do_stop(service)
-
-def do_stop(service):
-    '''
-    Stop the named Python service
-    '''
-
-    pidfile = get_pid_file(service)
-
-    if not os.path.exists(pidfile):
-        print "* %s is not running" % service
-        return
-
-    print "* stopping %s" % service
-
-    pid_fd = open(pidfile)
-    pid = pid_fd.read()
-    pid_fd.close()
-    try:
-        os.kill(int(pid), signal.SIGTERM)
-    except:
-        pass
-    os.remove(pidfile)
-
-# -----------------------------------------------------
-
-# Parse the command line options
-ops, args = None, None
-try:
-    ops, args = getopt.getopt(sys.argv[1:], 'a:s:f:c:p:dhl')
-except getopt.GetoptError, e:
-    print '* %s' % str(e)
-    do_help()
-
-options = dict(ops)
-
-if '-a' not in options or '-f' not in options:
-    do_help()
-
-action = options['-a']
-config_file = options['-f']
-pid_dir = options['-p']
-
-service_name = options.get('-s')
-config_ctx = options.get('-c', 'config.opensrf')
-as_localhost = '-l' in options
-as_daemon = '-d' in options
-
-domain = None
-settings = None
-services = {}
-
-do_init()
-
-if action == 'start':
-    do_start(service_name)
-
-elif action == 'stop':
-    do_stop(service_name)
-
-elif action == 'restart':
-    do_stop(service_name)
-    do_start(service_name)
-
-elif action == 'start_all':
-    do_start_all()
-
-elif action == 'stop_all':
-    do_stop_all()
-
-elif action == 'restart_all':
-    do_stop_all()
-    do_start_all()
-
-elif action == 'help':
-    do_help()

Copied: trunk/src/python/opensrf.py.in (from rev 2066, trunk/src/python/opensrf.py)
===================================================================
--- trunk/src/python/opensrf.py.in	                        (rev 0)
+++ trunk/src/python/opensrf.py.in	2010-11-09 16:21:15 UTC (rev 2067)
@@ -0,0 +1,238 @@
+#!/usr/bin/python
+# -----------------------------------------------------------------------
+# Copyright (C) 2008  Equinox Software, Inc.
+# Bill Erickson <erickson at esilibrary.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA
+# -----------------------------------------------------------------------
+
+'''
+Provides an environment for managing OpenSRF services written in Python
+'''
+
+import sys, getopt, os, signal
+import osrf.system, osrf.server, osrf.app, osrf.set, osrf.json
+
+def do_help():
+    '''
+    Print help for the OpenSRF Python application process manager
+    '''
+
+    print '''
+    Manage OpenSRF application processes
+
+    Options:
+        -a <action>
+            start   -- Start a service
+            stop    -- stop a service
+            restart -- restart a service
+            start_all -- Start all services
+            stop_all -- Stop all services
+            restart_all -- Restart all services
+
+        -s <service>
+            The service name
+
+        -f <config file>
+            The OpenSRF config file
+
+        -c <config context>
+            The OpenSRF config file context
+
+        -p <PID dir>
+            The location of application PID files.  Default is /tmp
+
+        -d 
+            If set, run in daemon (background) mode.  This creates a PID 
+            file for managing the process.
+
+        -l
+            If set, run in 'localhost' mode
+
+        -h
+            Prints help message
+    '''
+    sys.exit(0)
+
+def get_pid_file(service):
+    '''
+    Return the PID file for the named service
+    '''
+
+    return "%s/%s.pid" % (pid_dir, service)
+
+def do_init():
+    '''
+    Initialize the Python service environment
+    '''
+
+    global domain
+    global settings
+
+    # connect to the OpenSRF network
+    osrf.system.System.net_connect(
+        config_file = config_file, config_context = config_ctx)
+
+    if as_localhost:
+        domain = 'localhost'
+    else:
+        domain = osrf.conf.get('domain')
+
+    osrf.set.load(domain)
+
+    settings = osrf.set.get('apps')
+
+    for key in settings.keys():
+        svc = settings[key]
+        if isinstance(svc, dict) and 'language' in svc and svc['language'] == 'python':
+            services[key] = svc
+
+
+def do_start(service):
+    '''
+    Start the named Python service
+    '''
+
+    pidfile = get_pid_file(service)
+
+    if service not in services:
+        print "* service %s is not a 'python' application" % service
+        return
+
+    if os.path.exists(pidfile):
+        print "* service %s already running" % service
+        return
+
+    print "* starting %s" % service
+
+    if as_daemon:
+
+        if osrf.system.System.daemonize(False):
+            return # parent process returns
+
+        # write PID file
+        pid_fd = open(pidfile, 'w')
+        pid_fd.write(str(os.getpid()))
+        pid_fd.close()
+
+    svc_settings = services[service]
+
+    osrf.app.Application.load(service, svc_settings['implementation'])
+    osrf.app.Application.register_sysmethods()
+    osrf.app.Application.application.global_init()
+
+    controller = osrf.server.Controller(service)
+    controller.max_requests = svc_settings['unix_config']['max_requests']
+    controller.max_children = svc_settings['unix_config']['max_children']
+    controller.min_children = svc_settings['unix_config']['min_children']
+    controller.keepalive = svc_settings['keepalive']
+
+    controller.run()
+    os._exit(0)
+
+def do_start_all():
+    '''
+    Start all Python services listed in the OpenSRF configuration file
+    '''
+
+    print "* starting all services for %s " % domain
+    for service in services.keys():
+        do_start(service)
+
+def do_stop_all():
+    '''
+    Stop all Python services listed in the OpenSRF configuration file
+    '''
+
+    print "* stopping all services for %s " % domain
+    for service in services.keys():
+        do_stop(service)
+
+def do_stop(service):
+    '''
+    Stop the named Python service
+    '''
+
+    pidfile = get_pid_file(service)
+
+    if not os.path.exists(pidfile):
+        print "* %s is not running" % service
+        return
+
+    print "* stopping %s" % service
+
+    pid_fd = open(pidfile)
+    pid = pid_fd.read()
+    pid_fd.close()
+    try:
+        os.kill(int(pid), signal.SIGTERM)
+    except:
+        pass
+    os.remove(pidfile)
+
+# -----------------------------------------------------
+
+# Parse the command line options
+ops, args = None, None
+try:
+    ops, args = getopt.getopt(sys.argv[1:], 'a:s:f:c:p:dhl')
+except getopt.GetoptError, e:
+    print '* %s' % str(e)
+    do_help()
+
+options = dict(ops)
+
+if '-a' not in options:
+    do_help()
+
+action = options['-a']
+
+config_file = options.get('-f', '@CONF_DIR@/opensrf_core.xml')
+pid_dir = options.get('-p', '@PID_DIR@/run/opensrf')
+
+service_name = options.get('-s')
+config_ctx = options.get('-c', 'config.opensrf')
+as_localhost = '-l' in options
+as_daemon = '-d' in options
+
+domain = None
+settings = None
+services = {}
+
+do_init()
+
+if action == 'start':
+    do_start(service_name)
+
+elif action == 'stop':
+    do_stop(service_name)
+
+elif action == 'restart':
+    do_stop(service_name)
+    do_start(service_name)
+
+elif action == 'start_all':
+    do_start_all()
+
+elif action == 'stop_all':
+    do_stop_all()
+
+elif action == 'restart_all':
+    do_stop_all()
+    do_start_all()
+
+elif action == 'help':
+    do_help()



More information about the opensrf-commits mailing list