Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 处于启动/终止状态的Upstart服务_Bash_Ubuntu_Service_Upstart_Init.d - Fatal编程技术网

Bash 处于启动/终止状态的Upstart服务

Bash 处于启动/终止状态的Upstart服务,bash,ubuntu,service,upstart,init.d,Bash,Ubuntu,Service,Upstart,Init.d,我有一个python应用程序需要在Ubuntu 14.04上作为服务运行。此应用程序需要具有以下功能: 当服务启动时,将在crontab中创建一个cron条目,该条目将定期运行应用程序 当服务停止时,crontab条目将被删除 重新启动系统/服务器时,需要启动服务 我有以下upstart脚本来运行我的服务: start on [2345] stop on [!2345] script LOGDIR=/usr/local/etc/myservice/logs/ CFGFILE=/

我有一个python应用程序需要在Ubuntu 14.04上作为服务运行。此应用程序需要具有以下功能:

  • 当服务启动时,将在crontab中创建一个cron条目,该条目将定期运行应用程序

  • 当服务停止时,crontab条目将被删除

  • 重新启动系统/服务器时,需要启动服务

  • 我有以下upstart脚本来运行我的服务:

    start on [2345]
    stop on [!2345]
    
    script
        LOGDIR=/usr/local/etc/myservice/logs/
        CFGFILE=/usr/local/etc/myservice/myservice.conf
    
        echo $$ > /var/run/myservice.pid
        # If there is no cronjob by the name myservice, then add a cronjob to the crontab
        set -x
        exec bash -c '
        if (( $(crontab -l | grep -c myservice) == 0 )); then
           (crontab -l ; echo "1 * * * * myservice) | crontab -
        fi'
    end script
    
    pre-start script
        set -x
        echo "[`date`] Starting myservice Service" >> /var/log/myservice.log
    
        # Testing to see if myservice has been installed, else exit
        [ -x /usr/local/bin/myservice ] || exit 0
        mkdir -p /usr/local/etc/myservice/logs/
    end script
    
    pre-stop script
        set -x
        echo "[`date`] Stopping myservice Service" >> /var/log/myservice.log
    end script
    
    post-stop script
        set -x
        rm /var/run/myservice.pid
        # If there is at least 1 cronjob by the name myservice, remove all such entries from crontab
        exec bash -c '
        if (( $(crontab -l | grep -c myservice) >= 0 )); then
           (crontab -l | grep -v myservice) | crontab -
        fi'
        pkill -f myservice
    end script
    

    但是,当我尝试运行该服务时,它会挂起,我必须按ctrl+c键才能返回命令行。与停止服务类似。我是不是遗漏了什么?任何帮助都将不胜感激

    别担心,伙计们!我自己设法解决了这个问题……请发布一个答案,总结您的解决方案(即使是简单或明显的)。它将来可能会帮助别人。