小编cod*_*mer的帖子

如何为 shell 脚本创建服务,以便我可以像守护进程一样启动和停止它?

我正在使用 CentOS 7,我的目标是每五秒创建一个 cron,但正如我研究的那样,我们只能使用 cron 一分钟,所以我现在正在做的是我创建了一个 shell 文件。
命中.sh

while sleep 5; do curl http://localhost/test.php; done
Run Code Online (Sandbox Code Playgroud)

但我通过右键单击它手动点击了它。

我想要的是为该文件创建一个服务,以便我可以自动启动和停止它。

我找到了创建服务脚本

#!/bin/bash
# chkconfig: 2345 20 80
# description: Description comes here....

# Source function library.
. /etc/init.d/functions

start() {
    # code to start app comes here 
    # example: daemon program_name &
}

stop() {
    # code to stop app comes here 
    # example: killproc program_name
}

case "$1" in 
    start)
       start
       ;;
    stop)
       stop
       ;;
    restart)
       stop
       start …
Run Code Online (Sandbox Code Playgroud)

cron centos shell-script services sysvinit

38
推荐指数
3
解决办法
25万
查看次数

标签 统计

centos ×1

cron ×1

services ×1

shell-script ×1

sysvinit ×1