forked from jpalardy1752/crits-adapter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedgy_critsd.py
executable file
·73 lines (55 loc) · 2.08 KB
/
edgy_critsd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python2.7
# Copyright 2015 Soltra Solutions, LLC
# Licensed under the Soltra License, Version 2.0 (the "License"); you
# may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.soltra.com/licenses/license-2.0.txt
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from docopt import docopt
import os.path
from lib import util, log, db
import signal
__version__ = '0.3'
app_path = os.path.split(os.path.abspath(__file__))[0]
default_config = os.path.join(app_path, 'config.yaml')
__doc__ = '''edgy_critsd.py: a daemon to drive edgy_crits
Usage:
edgy_critsd.py start [--config=CONFIG]
edgy_critsd.py stop [--config=CONFIG]
edgy_critsd.py restart [--config=CONFIG]
edgy_critsd.py status [--config=CONFIG]
edgy_critsd.py --help
edgy_critsd.py --version
Options:
-c CONFIG --config=CONFIG Specify config file to use [default: %s].
-h --help Show this screen.
-V --version Show version.
Please report bugs to [email protected]
''' % (default_config)
def main():
args = docopt(__doc__, version=__version__)
config = util.parse_config(args['--config'])
config['config_file'] = args['--config']
config['daemon']['app_path'] = app_path
logger = log.setup_logging(config)
config['logger'] = logger
my_db = db.DB(config)
config['db'] = my_db
daemon = util.Daemon(config)
if args['start']:
logger.info('edgy_critsd starting...')
signal.signal(signal.SIGTERM, util.signal_handler)
daemon.start()
elif args['stop']:
logger.info('edgy_critsd stopping...')
daemon.stop()
elif args['restart']:
logger.info('edgy_critsd restarting...')
daemon.restart()
if __name__ == '__main__':
main()