I'm trying to run a shell script via a service. This seems to be working fine and the service is able to call the shell script. The issue is when the wiremock_process.sh is called via the service, it believes that the process is already running. However if I run "ps -ef | grep wiremock | grep -v grep" this is not true. I'm also able to run my shell script and start it just fine without the service
Any help would be appreciated!
journal
-- 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"
}