Skript angepasst für Windows
This commit is contained in:
+13
-9
@@ -14,8 +14,10 @@ import logging
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from systemd import journal
|
||||
if sys.platform == "linux":
|
||||
from systemd import journal
|
||||
|
||||
|
||||
def __setup_logging(loglevel, frm, startmethode, unitname):
|
||||
@@ -27,7 +29,6 @@ def __setup_logging(loglevel, frm, startmethode, unitname):
|
||||
logger.handlers = []
|
||||
if startmethode == "auto":
|
||||
log_handler = journal.JournalHandler(SYSLOG_IDENTIFIER=unitname)
|
||||
|
||||
else:
|
||||
log_handler = logging.StreamHandler()
|
||||
log_handler.setLevel(loglevel)
|
||||
@@ -37,7 +38,7 @@ def __setup_logging(loglevel, frm, startmethode, unitname):
|
||||
|
||||
|
||||
def __get_service_unit_pid(unitname):
|
||||
"""Ermittelt ob das ausführende Skript mit einer Service Unit gestartet worden ist, wenn ja so ist das
|
||||
"""Ermittelt, ob das ausführende Skript mit einer Service-Unit gestartet worden ist, wenn ja so ist das
|
||||
Ergebnis (pid_service_unit) != 0"""
|
||||
cmd = "systemctl show -p MainPID {}".format(unitname)
|
||||
cmd = shlex.split(cmd)
|
||||
@@ -49,12 +50,15 @@ def __get_service_unit_pid(unitname):
|
||||
|
||||
|
||||
def __get_startmethode(unitname):
|
||||
"""Verglicht die PID vom skript mit der pid Service Unit Prüfung
|
||||
wenn die Nummern gleich sind wird auf auto gestellt, wenn nicht auf manuell"""
|
||||
pid_service_unit = __get_service_unit_pid(unitname)
|
||||
pid_skript = os.getpid()
|
||||
if pid_service_unit == pid_skript:
|
||||
startmethode = "auto"
|
||||
"""Vergleicht die PID vom Skript mit der PID von der Service-Unit.
|
||||
Wenn die Nummern gleich sind und die platform linux ist, wird auf auto gestellt, ansonsten auf manuell"""
|
||||
if sys.platform == "linux":
|
||||
pid_service_unit = __get_service_unit_pid(unitname)
|
||||
pid_skript = os.getpid()
|
||||
if pid_service_unit == pid_skript:
|
||||
startmethode = "auto"
|
||||
else:
|
||||
startmethode = "manuell"
|
||||
else:
|
||||
startmethode = "manuell"
|
||||
return startmethode
|
||||
|
||||
Reference in New Issue
Block a user