Reputation: 1
Hi i want to use this for restart apache service every 12 hours and
i put the file apache_rest
in /etc/init.d/apache_rest
i run but get some error :
[root@localhost init.d]# service apache_rest start
Starting server
/etc/init.d/apache_rest: line 13: /sbin/start-stop-daemon: No such file or directory
apache_rest file:
#!/bin/bash
WORK_DIR="/var/lib/foo"
DAEMON="/usr/bin/python"
ARGS="/home/lol/apache.py"
PIDFILE="/var/run/foo.pid"
USER="foo"
case "$1" in
start)
echo "Starting server"
mkdir -p "$WORK_DIR"
/sbin/start-stop-daemon --start --pidfile $PIDFILE \
--user $USER --group $USER \
-b --make-pidfile \
--chuid $USER \
--exec $DAEMON $ARGS
;;
stop)
echo "Stopping server"
/sbin/start-stop-daemon --stop --pidfile $PIDFILE --verbose
;;
*)
echo "Usage: /etc/init.d/$USER {start|stop}"
exit 1
;;
esac
exit 0
and the python file :
#!/usr/bin/python
import os,signal,time,multiprocessing
stop_event = multiprocessing.Event()
def stop(signum, frame):
stop_event.set()
signal.signal(signal.SIGTERM, stop)
if __name__ == '__main__':
while not stop_event.is_set():
os.system('service httpd restart')
time.sleep(43200)
thanks ^_^
Upvotes: 0
Views: 1551
Reputation: 174624
Simply add this line to root's crontab:
0 1,13 * * * /etc/init.d/httpd restart
You don't need such a convoluted solution.
Upvotes: 4