blob: ce19cb63a44c8a39d16d2a51b1e30dc83c2cb050 (
plain)
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
|
import sys
from .load import base_path, load
# language=ini
TEMPLATE = """
[Unit]
Description = {description}
[Service]
Type=simple
ExecStart={python_executable} -m bot run
WorkingDirectory={working_directory}
Restart=always
[Install]
WantedBy=multi-user.target
"""
def generate_template():
bot = load('bot')
return TEMPLATE.format(
python_executable=sys.executable,
working_directory=str(base_path),
description=bot.description,
)
def install_systemd():
bot = load('bot')
with open(f'/etc/systemd/system/{bot.name}.service', 'w') as fp:
fp.write(generate_template())
print(f"Service created. Use systemd enable/start {bot.name} to start/enable the bot")
|