서비스를 통해 쉘 스크립트를 실행하려고 합니다. 이는 제대로 작동하는 것으로 보이며 서비스가 쉘 스크립트를 호출할 수 있습니다. 문제는 서비스를 통해 wiremock_process.sh가 호출될 때 프로세스가 이미 실행 중이라고 생각한다는 것입니다. 그러나 "ps -ef | grepwiremock | grep -v grep"을 실행하면 그렇지 않습니다. 쉘 스크립트를 실행하고 서비스 없이 정상적으로 시작할 수도 있습니다.
어떤 도움이라도 대단히 감사하겠습니다!
잡지
-- 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
ps -ef | grep 라인 에뮬레이션 if [[
| grep -v grep |-ne 0 ]]; then
도착하다if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 )) then