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