-
Notifications
You must be signed in to change notification settings - Fork 4
/
pancake.py
executable file
·75 lines (59 loc) · 2.08 KB
/
pancake.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
74
75
#!/usr/bin/env python
__project_name__ = 'Pancake chat bot (HipChat edition)'
__version__ = '2.2.1'
import sys
import os
import logging
import argparse
import src as library
class PancakeDaemon(library.Daemon):
def run(self):
logger = logging.getLogger('pancake')
logger.info(__project_name__ + ', version ' + __version__)
bot = library.Bot(settings.get())
bot.join_rooms(settings.get('general:rooms'))
bot.start()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config',
help='config file to be used')
parser.add_argument('-p', '--pid',
default=os.path.dirname(os.path.realpath(__file__)) + '/pancake.pid',
help='pecify path for pid file')
parser.add_argument('-o', '--out',
help='file to redirect output')
parser.add_argument('operation',
metavar='OPERATION',
type=str,
help='Operation with daemon. Accepts any of these values: start, stop, restart, status',
choices=['start', 'stop', 'restart', 'foreground'])
args = parser.parse_args()
# Logging setup
if args.out:
handler = logging.FileHandler(args.out)
else:
handler = logging.StreamHandler()
logger = logging.getLogger('pancake')
logger.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
# Config to use
conf_name = args.config
settings = library.config.Settings(conf_name)
# Lockfile
lockfile = args.pid
pancakeDaemon = PancakeDaemon(lockfile)
if args.operation == 'foreground':
logger.info("Starting Pancake in foreground")
pancakeDaemon.run()
elif args.operation == 'start':
logger.info("Starting Pancake")
pancakeDaemon.start()
elif args.operation == 'stop':
logger.info("Stoping Pancake")
pancakeDaemon.stop()
elif args.operation == 'restart':
logger.info("Restarting Pancake")
pancakeDaemon.restart()
sys.exit(0)