0

嗨,我想每 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)

谢谢^_^

4

1 回答 1

4

只需将此行添加到 root 的 crontab 中:

0 1,13 * * * /etc/init.d/httpd restart

您不需要如此复杂的解决方案。

于 2013-04-28T08:47:47.390 回答