嗨,我想每 12 小时使用它来重新启动 apache 服务,我将文件apache_rest
放入/etc/init.d/apache_rest
运行但得到一些错误:
[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 文件:
#!/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
和python文件:
#!/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)
谢谢^_^