-
Notifications
You must be signed in to change notification settings - Fork 0
/
navi.py
47 lines (39 loc) · 1.11 KB
/
navi.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
#!/usr/bin/python3
# Launcher versão daemon
import logging
import os
import sys
from daemons.prefab import run
from navibot.client import Bot
NAVI_TMP = '/var/tmp'
NAVI_PATH = os.path.dirname(os.path.abspath(__file__))
NAVI_PIDFILE = os.path.join(NAVI_TMP, 'navibot.pid')
NAVI_LOGFILE = os.path.join(NAVI_PATH, 'navibot.log')
NAVI_ENABLE_LOGGING = False
class NaviDaemon(run.RunDaemon):
def run(self):
bot = Bot(
path=NAVI_PATH,
logenable=NAVI_ENABLE_LOGGING,
logfile=NAVI_LOGFILE if NAVI_ENABLE_LOGGING else None,
loglevel=logging.INFO
)
bot.start()
def show_usage():
print(f"Uso:\n\n{sys.argv[0]} <start|stop|restart>")
if __name__ == "__main__":
if len(sys.argv) > 1:
action = sys.argv[1]
d = NaviDaemon(
pidfile=NAVI_PIDFILE
)
if action == "start":
d.start()
elif action == "stop":
d.stop()
elif action == "restart":
d.restart()
else:
show_usage()
else:
show_usage()