嗨,每12小時,我想用這個重啓apache服務,每12小時和 我把文件apache_rest
在/etc/init.d/apache_rest
我跑,但得到一些錯誤:重啓Apache使用Linux的服務和python文件
[[email protected] 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)
感謝^ _^
你在根目錄下運行它嗎? – 2013-04-28 08:34:54
問題似乎是文件'/ sbin/start-stop-daemon'不存在。可以? – Aya 2013-04-28 08:48:00
是的,你可以看到它是由root運行的:[root @ localhost init.d]# – user2328647 2013-04-28 09:18:54