]>
Commit | Line | Data |
---|---|---|
e0edde6f | 1 | # Copyright (c) 2010, 2011 Nicira, Inc. |
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 | ||
b153e667 | 15 | import argparse |
aacea8ba | 16 | import logging |
6793129d | 17 | import signal |
99155935 BP |
18 | import sys |
19 | import time | |
20 | ||
21 | import ovs.daemon | |
22 | import ovs.util | |
23 | ||
50e97486 EJ |
24 | |
25 | def handler(signum, _): | |
6793129d EJ |
26 | raise Exception("Signal handler called with %d" % signum) |
27 | ||
50e97486 | 28 | |
b153e667 | 29 | def main(): |
6793129d EJ |
30 | |
31 | signal.signal(signal.SIGHUP, handler) | |
32 | ||
b153e667 EJ |
33 | parser = argparse.ArgumentParser( |
34 | description="Open vSwitch daemonization test program for Python.") | |
35 | parser.add_argument("-b", "--bail", action="store_true", | |
36 | help="Exit with an error after daemonize_start().") | |
99155935 | 37 | |
b153e667 EJ |
38 | ovs.daemon.add_args(parser) |
39 | args = parser.parse_args() | |
40 | ovs.daemon.handle_args(args) | |
99155935 | 41 | |
99155935 | 42 | ovs.daemon.daemonize_start() |
b153e667 | 43 | if args.bail: |
99155935 BP |
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 | ||
50e97486 | 52 | |
99155935 | 53 | if __name__ == '__main__': |
6793129d | 54 | try: |
b153e667 | 55 | main() |
6793129d EJ |
56 | except SystemExit: |
57 | # Let system.exit() calls complete normally | |
58 | raise | |
59 | except: | |
60 | sys.exit(ovs.daemon.RESTART_EXIT_CODE) |