1 # Copyright (c) 2010, 2011 Nicira Networks.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
24 def handler(signum, frame):
25 raise Exception("Signal handler called with %d" % signum)
28 logging.basicConfig(level=logging.DEBUG)
30 signal.signal(signal.SIGHUP, handler)
33 options, args = getopt.gnu_getopt(
34 argv[1:], 'b', ["bail", "help"] + ovs.daemon.LONG_OPTIONS)
35 except getopt.GetoptError, geo:
36 sys.stderr.write("%s: %s\n" % (ovs.util.PROGRAM_NAME, geo.msg))
40 for key, value in options:
43 elif key in ['-b', '--bail']:
45 elif not ovs.daemon.parse_opt(key, value):
46 sys.stderr.write("%s: unhandled option %s\n"
47 % (ovs.util.PROGRAM_NAME, key))
50 ovs.daemon.daemonize_start()
52 sys.stderr.write("%s: exiting after daemonize_start() as requested\n"
53 % ovs.util.PROGRAM_NAME)
55 ovs.daemon.daemonize_complete()
62 %s: Open vSwitch daemonization test program for Python
64 """ % ovs.util.PROGRAM_NAME)
68 -h, --help display this help message
69 -b, --bail exit with an error after daemonize_start()
73 if __name__ == '__main__':
77 # Let system.exit() calls complete normally
80 sys.exit(ovs.daemon.RESTART_EXIT_CODE)