+apache_restarter
This commit is contained in:
parent
bba64ac49c
commit
49bf010b87
39
apache_restarter/apache_restarter.py
Normal file
39
apache_restarter/apache_restarter.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
delay = 2
|
||||||
|
|
||||||
|
|
||||||
|
def restart_apache():
|
||||||
|
os.system("systemctl reload-or-restart apache2")
|
||||||
|
|
||||||
|
|
||||||
|
def run_monitor(filename):
|
||||||
|
while True:
|
||||||
|
if os.path.exists(filename):
|
||||||
|
logging.info("restarting apache")
|
||||||
|
restart_apache()
|
||||||
|
time.sleep(delay)
|
||||||
|
os.remove(filename)
|
||||||
|
time.sleep(delay)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s: %(message)s')
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
raise Exception('No monitor filename')
|
||||||
|
monitor_filename = sys.argv[1]
|
||||||
|
monitor_dir = os.path.dirname(monitor_filename)
|
||||||
|
if not os.path.isdir(monitor_dir):
|
||||||
|
raise Exception(f'directory not exist: {monitor_dir}')
|
||||||
|
if not os.access(monitor_dir, os.W_OK):
|
||||||
|
raise Exception(f'directory not writable: {monitor_dir}')
|
||||||
|
run_monitor(monitor_filename)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
13
apache_restarter/apache_restarter.service
Normal file
13
apache_restarter/apache_restarter.service
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Apache restart monitor
|
||||||
|
After=apache2.service
|
||||||
|
Wants=apache2.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/usr/bin/env python3 /path/apache_restarter.py /run/apache_restart/apache_restart
|
||||||
|
ExecReload=/bin/kill -HUP $MAINPID
|
||||||
|
Restart=always
|
||||||
|
RestartSec=2s
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
Loading…
Reference in New Issue
Block a user