-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·77 lines (59 loc) · 2.39 KB
/
run.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
76
77
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# RelayBot - Simple Relay Service, run.py
#
# Copyright (C) 2023 Matthew Beeching
#
# This file is part of RelayBot.
#
# RelayBot is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RelayBot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with RelayBot. If not, see <http://www.gnu.org/licenses/>.
import core.logging as _logging
import core.config as _config
import core.daemon as _daemon
import core.signals as _signals
import argparse, asyncio, os, sys
log = _logging.log.getChild('main')
def parse_args():
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('-h', '-?', '--help', help='Show this help message and exit', action='help')
parser.add_argument('-c', '--config', help='Specify the path to config.xml', action='store', default=_config.configpath, dest='config')
parser.add_argument('-d', '--debug', help='Enable debug output to STDOUT', action='store_true', dest='debug')
parser.add_argument('-f', '--foreground', help='Run in the foreground', action='store_true', dest='nofork')
parser.add_argument('-n', '--nofork', help='Run in the foreground', action='store_true', dest='nofork')
parser.add_argument('-p', '--pidfile', help='Path to process id (pid) file', action='store', default='relaybot.pid', dest='pidfile')
args = parser.parse_args()
args.asynciodebug = False
if os.name == 'nt':
args.nofork = True
return args
args = parse_args()
_config.checkoverrides(args)
_logging.init_logging(args)
if os.name == 'nt':
log.debug('Running on Windows, -n/-f implied')
log.debug('Command line options: ' + str(vars(args)))
_daemon.daemonize(args)
# Create event loop
loop = asyncio.get_event_loop()
if args.asynciodebug:
loop.set_debug(True)
_signals.init_signals(loop)
# Begin by loading config when we start the loop
loop.call_soon(_config.load, loop, args)
log.info('Starting event loop')
try:
loop.run_forever()
except KeyboardInterrupt:
log.info('Shutting down: Keyboard interrupt')
loop.close()