This repository has been archived by the owner on Jan 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
115 lines (98 loc) · 2.93 KB
/
setup.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import subprocess
import platform
import argparse
from misc.functions import functions
from decouple import config
if platform.system() != "Linux":
exit("error: This can only run on Linux.")
functions.systemctl_log()
try:
parser = argparse.ArgumentParser()
parser.add_argument(
"-n", "--service_name", help="Name of the service you want to create."
)
args = parser.parse_args()
if functions.is_connected():
while True:
subprocess.call(
[
"sudo",
"python",
"-m",
"pip",
"install",
"--upgrade",
"-r",
"requirements.txt",
],
shell=False,
)
break
else:
print(
"Internet is not connected. Skipping dependency installations. This may cause problems."
)
while True:
subprocess.call(
["sudo", "addgroup", "--system", f"{args.service_name}"], shell=False
)
break
while True:
subprocess.call(
[
"sudo",
"adduser",
"--system",
"--no-create-home",
"--disabled-login",
"--disabled-password",
"--ingroup",
f"{args.service_name}",
f"{args.service_name}",
],
shell=False,
)
break
while True:
subprocess.call(
["sudo", "usermod", "-a", "-G", "sudo", f"{args.service_name}"], shell=False
)
break
while True:
subprocess.call(
["sudo", "usermod", "-a", "-G", "video", f"{args.service_name}"],
shell=False,
)
break
while True:
subprocess.call(
["sudo", "touch", f"/lib/systemd/system/{args.service_name}.service"],
shell=False,
)
break
service = f"""[Unit]
Requires=network-online.target
After=network-online.target
Description="{args.service_name} Service"
[Service]
WorkingDirectory={config("WORKING_DIR")}
ExecStart=/usr/bin/python {config("WORKING_DIR")}vision.py
StandardOutput=append:{config("WORKING_DIR")}/log/stdout.log
StandardError=append:{config("WORKING_DIR")}/log/stderr.log
User={args.service_name}
[Install]
WantedBy=multi-user.target"""
with open(f"/lib/systemd/system/{args.service_name}.service", "w") as f:
f.write(service)
while True:
subprocess.call(["sudo", "systemctl", "daemon-reload"], shell=False)
break
while True:
subprocess.call(
["sudo", "systemctl", "enable", f"{args.service_name}"], shell=False
)
break
print("vision-2021 is installed and enabled. It will start automatically on boot.")
except Exception as e:
print("error: Please run as root. (sudo python setup.py)")
print(e)