服务未通过 SH 脚本启动 jar

服务未通过 SH 脚本启动 jar

我正在尝试通过服务运行 shell 脚本。这似乎工作正常,并且服务能够调用 shell 脚本。问题是当通过服务调用wiremock_process.sh 时,它认为该进程已经在运行。但是,如果我运行“ps -ef | grepwiremock | grep -v grep”,则事实并非如此。我还可以运行我的 shell 脚本并在没有服务的情况下正常启动它

任何帮助,将不胜感激!

杂志


-- Logs begin at Thu 2020-10-08 14:43:49 EDT, end at Thu 2020-10-08 14:44:59 EDT. --
Oct 08 14:44:57 vc2coma1313056n systemd[1]: Started Service to start wiremock.
Oct 08 14:44:57 vc2coma1313056n bash[2836]: Wiremock is already running. Please stop the process and try
Oct 08 14:44:57 vc2coma1313056n systemd[1]: wiremock.service: main process exited, code=exited, status=1
Oct 08 14:44:57 vc2coma1313056n systemd[1]: Unit wiremock.service entered failed state.
Oct 08 14:44:57 vc2coma1313056n systemd[1]: wiremock.service failed.

wiremock.service

[Unit]
Description=Service to start wiremock

[Service]
Type=simple
ExecStart=/bin/bash -c "source /apps/wiremock/wiremock_process.sh && wiremock_start"

[Install]
WantedBy=multi-user.target

wiremock_process.sh

#!/bin/sh
#Script to start/stop wiremock process
#Date 08-OCT-2020
wiremock_start()
{
        ## Don't start if wiremock is already running
        if [[ `ps -ef | grep wiremock | grep -v grep | wc -l` -ne 0 ]]; then
                echo "Wiremock is already running. Please stop the process and try again"
                exit 1;
        fi

    echo 'Starting...' 
        ##Start the process
        
        java -jar /apps/wiremock/wiremock-standalone-2.27.0.jar --port 9999 --global-response-templating &

}

wiremock_stop()
{
        ## Check if the  wiremock is stopped
        if [[ `ps -ef | grep wiremock | grep -v grep | wc -l` -eq 0 ]]; then
                echo "wiremock is not running. Please start the process and try again"
                exit 1;
        fi

        PID=$(ps -ef | grep wiremock | grep java | awk '{print $2}')

        kill $PID

        echo "Done"

}


答案1

尝试更改 if [[ps -ef | grep 线模拟 | grep -v grep | grep -v厕所-l-ne 0 ]]; then

if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 )) then

相关内容