|
|
@ -14,8 +14,10 @@ import logging
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import shlex
|
|
|
|
import shlex
|
|
|
|
import subprocess
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
from systemd import journal
|
|
|
|
if sys.platform == "linux":
|
|
|
|
|
|
|
|
from systemd import journal
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __setup_logging(loglevel, frm, startmethode, unitname):
|
|
|
|
def __setup_logging(loglevel, frm, startmethode, unitname):
|
|
|
@ -27,7 +29,6 @@ def __setup_logging(loglevel, frm, startmethode, unitname):
|
|
|
|
logger.handlers = []
|
|
|
|
logger.handlers = []
|
|
|
|
if startmethode == "auto":
|
|
|
|
if startmethode == "auto":
|
|
|
|
log_handler = journal.JournalHandler(SYSLOG_IDENTIFIER=unitname)
|
|
|
|
log_handler = journal.JournalHandler(SYSLOG_IDENTIFIER=unitname)
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
log_handler = logging.StreamHandler()
|
|
|
|
log_handler = logging.StreamHandler()
|
|
|
|
log_handler.setLevel(loglevel)
|
|
|
|
log_handler.setLevel(loglevel)
|
|
|
@ -37,7 +38,7 @@ def __setup_logging(loglevel, frm, startmethode, unitname):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __get_service_unit_pid(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"""
|
|
|
|
Ergebnis (pid_service_unit) != 0"""
|
|
|
|
cmd = "systemctl show -p MainPID {}".format(unitname)
|
|
|
|
cmd = "systemctl show -p MainPID {}".format(unitname)
|
|
|
|
cmd = shlex.split(cmd)
|
|
|
|
cmd = shlex.split(cmd)
|
|
|
@ -49,14 +50,17 @@ def __get_service_unit_pid(unitname):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __get_startmethode(unitname):
|
|
|
|
def __get_startmethode(unitname):
|
|
|
|
"""Verglicht die PID vom skript mit der pid Service Unit Prüfung
|
|
|
|
"""Vergleicht die PID vom Skript mit der PID von der Service-Unit.
|
|
|
|
wenn die Nummern gleich sind wird auf auto gestellt, wenn nicht auf manuell"""
|
|
|
|
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_service_unit = __get_service_unit_pid(unitname)
|
|
|
|
pid_skript = os.getpid()
|
|
|
|
pid_skript = os.getpid()
|
|
|
|
if pid_service_unit == pid_skript:
|
|
|
|
if pid_service_unit == pid_skript:
|
|
|
|
startmethode = "auto"
|
|
|
|
startmethode = "auto"
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
startmethode = "manuell"
|
|
|
|
startmethode = "manuell"
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
startmethode = "manuell"
|
|
|
|
return startmethode
|
|
|
|
return startmethode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|