2 # -----------------------------------------------------------------------
3 # Copyright (C) 2008 Equinox Software, Inc.
4 # Bill Erickson <erickson@esilibrary.com>
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 # -----------------------------------------------------------------------
22 import sys, getopt, os, signal
23 import osrf.system, osrf.server, osrf.app
27 Manage one or more an OpenSRF applications
31 start -- Start a service
32 stop -- stop a service
33 restart -- restart a service
39 The OpenSRF config file
42 The OpenSRF config file context
45 The location of application PID files. Default is /tmp
48 If set, run in daemon (background) mode
53 # Parse the command line options
54 ops, args = getopt.getopt(sys.argv[1:], 'a:s:f:c:p:d')
57 if '-a' not in options or '-s' not in options or '-f' not in options:
60 action = options['-a']
61 service = options['-s']
62 config_file = options['-f']
63 config_ctx = options.get('-c', 'opensrf')
64 pid_dir = options.get('-p', '/tmp')
65 as_daemon = '-d' in options
66 pidfile = "%s/osrf_py_%s.pid" % (pid_dir, service)
71 # connect to the OpenSRF network
72 osrf.system.System.net_connect(
73 config_file = config_file, config_context = config_ctx)
75 # XXX load the settings configs...
76 osrf.app.Application.load(service, 'osrf.apps.example') # XXX example only for now
77 osrf.app.Application.register_sysmethods()
78 osrf.app.Application.application.global_init()
80 controller = osrf.server.Controller(service)
81 controller.max_requests = 10
82 controller.max_children = 6
83 controller.min_children = 3
86 osrf.system.System.daemonize()
87 file = open(pidfile, 'w')
88 file.write(str(os.getpid()))
93 elif action == 'stop':
97 os.kill(int(pid), signal.SIGTERM)