|
@@ -0,0 +1,43 @@
|
|
1
|
+import os.path
|
|
2
|
+import sys
|
|
3
|
+
|
|
4
|
+systemd_user_dir = os.path.expanduser('~/.config/systemd/user')
|
|
5
|
+
|
|
6
|
+python_interpreter_dir = os.path.dirname(sys.executable)
|
|
7
|
+uwsgi_path = os.path.join(python_interpreter_dir, 'uwsgi')
|
|
8
|
+piket_client_path = os.path.join(python_interpreter_dir, 'piket-client')
|
|
9
|
+
|
|
10
|
+server_template = f"""[Unit]
|
|
11
|
+Description=piket server daemon
|
|
12
|
+
|
|
13
|
+[Service]
|
|
14
|
+ExecStart={uwsgi_path} --http :5000 --master --threads 2 --module piket_server:app
|
|
15
|
+KillSignal=SIGINT
|
|
16
|
+Type=notify
|
|
17
|
+NotifyAccess=all
|
|
18
|
+
|
|
19
|
+[Install]
|
|
20
|
+WantedBy=default.target
|
|
21
|
+"""
|
|
22
|
+
|
|
23
|
+client_template = f"""[Unit]
|
|
24
|
+Description=piket client
|
|
25
|
+Requires=piket-server.service
|
|
26
|
+After=piket-server.service
|
|
27
|
+
|
|
28
|
+[Service]
|
|
29
|
+ExecStart={piket_client_path}
|
|
30
|
+
|
|
31
|
+[Install]
|
|
32
|
+WantedBy=graphical.target
|
|
33
|
+"""
|
|
34
|
+
|
|
35
|
+os.makedirs(systemd_user_dir, exist_ok=True)
|
|
36
|
+
|
|
37
|
+with open(os.path.join(systemd_user_dir, 'piket-server.service'), 'w') as f:
|
|
38
|
+ f.write(server_template)
|
|
39
|
+
|
|
40
|
+with open(os.path.join(systemd_user_dir, 'piket-client.service'), 'w') as f:
|
|
41
|
+ f.write(client_template)
|
|
42
|
+
|
|
43
|
+print("Done! Don't forget to systemctl --user daemon-reload.")
|