Ich möchte ein Python Script per Systemd Starten.
Code: Alles auswählen
#!/usr/bin/python3
import os
path_to_file = os.environ['HOME'] + '/Pyapps/wire-py/wg_py.xml'
path_to_file = str(path_to_file)
a_connect = {}
file = open(path_to_file, 'r')
for line in file.readlines():
line_splitted = line.split()
a_connect[line_splitted[0]] = line_splitted[1]
if 'true' in a_connect:
auto_con = a_connect['true']
else:
pass
os.system('nmcli connection up ' + str(auto_con))
so steht es in einem python file was gemacht werden soll.
Dies ist die erste Meldung die kommt beim manuellen start des Unit.
Code: Alles auswählen
× wg_start.service - Automatic Tunnel Start
Loaded: loaded (/usr/lib/systemd/system/wg_start.service; disabled; preset: enabled)
Active: failed (Result: exit-code) since Sat 2024-09-07 16:04:58 CEST; 5s ago
Process: 8078 ExecStartPre=/bin/sleep 3 (code=exited, status=0/SUCCESS)
Process: 8082 ExecStart=/bin/start_wg.py (code=exited, status=1/FAILURE)
Main PID: 8082 (code=exited, status=1/FAILURE)
CPU: 431ms
Sep 07 16:04:54 asus systemd[1]: Starting wg_start.service - Automatic Tunnel Start...
Sep 07 16:04:57 asus start_wg.py[8082]: Traceback (most recent call last):
Sep 07 16:04:57 asus start_wg.py[8082]: File "/bin/start_wg.py", line 4, in <module>
Sep 07 16:04:57 asus start_wg.py[8082]: path_to_file = os.environ['HOME'] + '/Pyapps/wire-py/wg_py.xml'
Sep 07 16:04:57 asus start_wg.py[8082]: ~~~~~~~~~~^^^^^^^^
Sep 07 16:04:57 asus start_wg.py[8082]: File "<frozen os>", line 685, in __getitem__
Sep 07 16:04:57 asus start_wg.py[8082]: KeyError: 'HOME'
Sep 07 16:04:58 asus systemd[1]: wg_start.service: Main process exited, code=exited, status=1/FAILURE
Sep 07 16:04:58 asus systemd[1]: wg_start.service: Failed with result 'exit-code'.
Sep 07 16:04:58 asus systemd[1]: Failed to start wg_start.service - Automatic Tunnel Start.
funktioniert es. Ich brauch das aber so des der User ausgelesen wird.
Vielleicht hat einer ja ne Idde wie ich das lösen könnte.