check_service_and_restart_if_failed
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
check_service_and_restart_if_failed [2020/07/27 01:16] – created k2patel | check_service_and_restart_if_failed [2020/08/10 02:35] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 4: | Line 4: | ||
<code bash> | <code bash> | ||
# | # | ||
+ | |||
+ | # Enable System level logging | ||
+ | # Redirect log to logger | ||
+ | exec 1> >(logger -t $(basename $0)) 2>&1 | ||
STATUS=" | STATUS=" | ||
if [ " | if [ " | ||
+ | echo "Not running starting Service : Nginx" | ||
| | ||
fi | fi | ||
+ | </ | ||
+ | |||
+ | for python | ||
+ | |||
+ | <code python> | ||
+ | # | ||
+ | import os | ||
+ | import logging | ||
+ | from systemd import journal | ||
+ | |||
+ | def main(serviceName): | ||
+ | status = os.system(' | ||
+ | finisher(status) | ||
+ | |||
+ | def finisher(status): | ||
+ | if status is not 0: | ||
+ | status = os.system(' | ||
+ | print(status) | ||
+ | if status is not 0: | ||
+ | log.error(' | ||
+ | else: | ||
+ | log.info(' | ||
+ | |||
+ | if __name__ == " | ||
+ | |||
+ | # Initialize and handle options | ||
+ | log = logging.getLogger(__file__) | ||
+ | log.addHandler(journal.JournaldLogHandler()) | ||
+ | log.setLevel(logging.INFO) | ||
+ | |||
+ | # Define service array | ||
+ | serviceName = [" | ||
+ | for service in serviceName: | ||
+ | main(service) | ||
</ | </ |
check_service_and_restart_if_failed.1595812614.txt.gz · Last modified: 2020/08/10 02:30 (external edit)