aboutsummaryrefslogtreecommitdiff
path: root/bot/_bs/systemd.py
diff options
context:
space:
mode:
Diffstat (limited to 'bot/_bs/systemd.py')
-rw-r--r--bot/_bs/systemd.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/bot/_bs/systemd.py b/bot/_bs/systemd.py
new file mode 100644
index 0000000..ce19cb6
--- /dev/null
+++ b/bot/_bs/systemd.py
@@ -0,0 +1,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")