使用linux服务和python文件每隔12小时重新启动apache

使用linux服务和python文件每隔12小时重新启动apache,python,linux,apache,bash,Python,Linux,Apache,Bash,嗨,我想用它每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文件: #!

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

谢谢^ ^

只需将这一行添加到root的crontab:

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

您不需要这样复杂的解决方案。

只需将这一行添加到root的crontab:

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

您不需要这样复杂的解决方案。

您是在root下运行的吗?问题似乎是文件
/sbin/start-stop-daemon
不存在。是吗?是的,您可以看到它是由root运行的:[root@localhostinit.d]#我不知道那是什么文件。。。您能帮助我吗?@user2328647您正在使用哪个Linux发行版(例如Debian、Redhat等)?您是否在root下运行它?问题似乎是文件
/sbin/start-stop-daemon
不存在。是吗?是的,您可以看到它是由root运行的:[root@localhostinit.d]#我不知道那是什么文件。。。你能帮我吗?@user2328647你在使用哪个Linux发行版(例如Debian、Redhat等)?你能解释更多吗?请Khalid先生,我是新来的,谢谢
我不想使用corn
为什么人们总是说
我不想使用这个专为我所尝试的而设计的解决方案,我宁愿重新发明轮子
。请你再解释一下好吗?哈立德先生,我是新来的,谢谢
我不想用玉米
为什么人们总是说
我不想使用这个专为我想做的事而设计的解决方案,我宁愿重新发明轮子