2017-07-21 3 views
0

Ich bin ziemlich neu zu schreiben systemd Service-Skripte. Ich folgte diesem useful page, um mein eigenes zu schreiben. Es versagt wie unten.Ausführen eines Python-Skripts über Systemd

Die prodKPI.service Inhalte in /etc/systemd/system/ in einer Centos 7 Maschine sind wie

[Unit] 
Description=prodKPI: Aggregation logic to compute device availability 

[Service] 
Type=simple 
PermissionsStartOnly=true 
User=deployuser 
ExecStart = /usr/bin/python /tmp/app1/folder1/file1.py; /usr/bin/python /tmp/folder2/file2.py 
Restart=always 

[Install] 
WantedBy=default.target 

Die Schritte I nach der Erstellung der Datei werden anschließend

systemctl daemon-reload 
systemctl enable prodKPI.service 

eine

# systemctl status prodKPI.service 
● prodKPI.service - prodKPI: Aggregation logic to compute device availability 
    Loaded: loaded (/etc/systemd/system/prodKPI.service; enabled; vendor preset: disabled) 
    Active: failed (Result: start-limit) since Fri 2017-07-21 19:20:41 UTC; 15min ago 
    Process: 1190 ExecStart=/usr/bin/python /tmp/app1/folder1/file1.py; /usr/bin/python /tmp/folder2/file2.py (code=exited, status=2) 
Main PID: 1190 (code=exited, status=2) 

Jul 21 19:20:41 device-1 systemd[1]: prodKPI.service: main process exited, code=exited, status=2/INVALIDARGUMENT 
Jul 21 19:20:41 device-1 systemd[1]: Unit prodKPI.service entered failed state. 
Jul 21 19:20:41 device-1 systemd[1]: prodKPI.service failed. 
Jul 21 19:20:41 device-1 systemd[1]: prodKPI.service holdoff time over, scheduling restart. 
Jul 21 19:20:41 device-1 systemd[1]: start request repeated too quickly for prodKPI.service 
Jul 21 19:20:41 device-1 systemd[1]: Failed to start prodKPI.service: Aggregation logic to compute device availability. 
Jul 21 19:20:41 device-1 systemd[1]: Unit prodKPI.service entered failed state. 
Jul 21 19:20:41 device-1 systemd[1]: prodKPI.service failed. 

reboot und

tat, was hat nicht viel geholfen, aus

journalctl -xe 

-- Unit prodKPI.service has finished starting up. 
-- 
-- The start-up result is done. 
Jul 21 19:20:41 device-1 systemd[1]: Starting prodKPI.service: Aggregation logic to compute device availability... 
-- Subject: Unit prodKPI.service has begun start-up 
-- Defined-By: systemd 
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel 
-- 
-- Unit prodKPI.service has begun starting up. 
Jul 21 19:20:41 device-1 python[1190]: /usr/bin/python: can't open file '/tmp/app1/folder1/file1.py;': [Errno 2] No such file or directory 
Jul 21 19:20:41 device-1 systemd[1]: prodKPI.service: main process exited, code=exited, status=2/INVALIDARGUMENT 
Jul 21 19:20:41 device-1 systemd[1]: Unit prodKPI.service entered failed state. 
Jul 21 19:20:41 device-1 systemd[1]: prodKPI.service failed. 
Jul 21 19:20:41 device-1 systemd[1]: prodKPI.service holdoff time over, scheduling restart. 
Jul 21 19:20:41 device-1: start request repeated too quickly for prodKPI.service 
Jul 21 19:20:41 device-1: Failed to start prodKPI.service: Aggregation logic to compute device availability. 

Die folgende Fehlerzeile weist auf eine Art von Berechtigungsproblemen hin? Soll die Serviceeinheit mit einem anderen Benutzer (oder) Zugriffsebenen ausgeführt werden? Ich habe die sowohl die Python-Dateien auch ausführbar sein

Jul 21 19:20:41 device-1 python[1190]: /usr/bin/python: can't open file '/tmp/app1/folder1/file1.py;': [Errno 2] No such file or directory 

Antwort

1

Wenn Typ nicht oneshot ist, können Sie nur ein Befehl geben.

Auch Sie verwenden Bash Syntax in Ihrem Befehl. Sie müssen es in einen Zwischen-Shell-Prozess einbinden, wenn Sie bash Syntax verwenden möchten. Ie .:

ExecStart=/usr/bin/bash -c "python /tmp/app1/folder1/file1.py; /usr/bin/python /tmp/folder2/file2.py" 
+0

Danke für die Antwort. Ich kann den Dienst jetzt ausführen. Ich habe ein paar Klarstellungen. 1) meintest du '/ usr/bin/python' für das erste Python-Skript? 2) Mit dieser 'bash -c'-Option kann ich nur das erste Skript sehen, das im Hintergrund von' ps -ef | läuft grep [p] ython' und kann das zweite Skript nicht ausführen? Irgendeine Idee, wie man es auch laufen lässt? Würde freudig die Antwort dann akzeptieren – Inian

+0

Schließlich gefunden die Lösung für das Problem! – Inian

Verwandte Themen