]>
Commit | Line | Data |
---|---|---|
99155935 | 1 | # Copyright (c) 2010 Nicira Networks. |
9c64f238 | 2 | # |
99155935 BP |
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: | |
9c64f238 | 6 | # |
99155935 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
9c64f238 | 8 | # |
99155935 BP |
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. | |
14 | ||
15 | import getopt | |
6793129d | 16 | import signal |
99155935 BP |
17 | import sys |
18 | import time | |
19 | ||
20 | import ovs.daemon | |
21 | import ovs.util | |
22 | ||
6793129d EJ |
23 | def handler(signum, frame): |
24 | raise Exception("Signal handler called with %d" % signum) | |
25 | ||
99155935 | 26 | def main(argv): |
6793129d EJ |
27 | |
28 | signal.signal(signal.SIGHUP, handler) | |
29 | ||
99155935 BP |
30 | try: |
31 | options, args = getopt.gnu_getopt( | |
32 | argv[1:], 'b', ["bail", "help"] + ovs.daemon.LONG_OPTIONS) | |
33 | except getopt.GetoptError, geo: | |
34 | sys.stderr.write("%s: %s\n" % (ovs.util.PROGRAM_NAME, geo.msg)) | |
35 | sys.exit(1) | |
36 | ||
37 | bail = False | |
38 | for key, value in options: | |
39 | if key == '--help': | |
40 | usage() | |
41 | elif key in ['-b', '--bail']: | |
42 | bail = True | |
43 | elif not ovs.daemon.parse_opt(key, value): | |
44 | sys.stderr.write("%s: unhandled option %s\n" | |
45 | % (ovs.util.PROGRAM_NAME, key)) | |
46 | sys.exit(1) | |
47 | ||
48 | ovs.daemon.die_if_already_running() | |
49 | ovs.daemon.daemonize_start() | |
50 | if bail: | |
51 | sys.stderr.write("%s: exiting after daemonize_start() as requested\n" | |
52 | % ovs.util.PROGRAM_NAME) | |
53 | sys.exit(1) | |
54 | ovs.daemon.daemonize_complete() | |
55 | ||
56 | while True: | |
57 | time.sleep(1) | |
58 | ||
59 | def usage(): | |
60 | sys.stdout.write("""\ | |
61 | %s: Open vSwitch daemonization test program for Python | |
62 | usage: %s [OPTIONS] | |
63 | """ % ovs.util.PROGRAM_NAME) | |
64 | ovs.daemon.usage() | |
65 | sys.stdout.write(""" | |
66 | Other options: | |
67 | -h, --help display this help message | |
68 | -b, --bail exit with an error after daemonize_start() | |
69 | """) | |
70 | sys.exit(0) | |
71 | ||
72 | if __name__ == '__main__': | |
6793129d EJ |
73 | try: |
74 | main(sys.argv) | |
75 | except SystemExit: | |
76 | # Let system.exit() calls complete normally | |
77 | raise | |
78 | except: | |
79 | sys.exit(ovs.daemon.RESTART_EXIT_CODE) |