Script invoked from remote server unable to run service correctly

Viewed 219

I have a unix script that invokes another script on a remote unix server.

amongst other commands i am stopping a service. The stop command essentially translates to

ssh -t -t -q ${AEM_USER}@${SERVERIP}   'bash -l -c "service aem stop"'

The service is getting stopped but when i start back the service it just creates the .pid file and does not perform the start up. When i run the command for start i.e.

ssh -t -t -q ${AEM_USER}@${SERVERIP}   'bash -l -c "service aem start"'

it does not show any error. On going to the server and checking the status

service aemauthor status

Below message is displayed

aem dead but pid file exists

Also when starting the service by logging in to the server, it works as expected along with the message

Removing stale pidfile (pid: 8701)
Starting aem
2 Answers

We don't know the details of the service script of aem.

I guess the problem is related to the SIGHUP signal. When we log off from a shell or disconnect from ssh, the OS will send HUP signal to all processes that started in this terminated shell. If the process didn't handle the HUP signal, it would exit by default.

When we run a command via ssh remotely, the process started by this command will receive HUP signal after ssh session is terminated.

We can use the nohup command to ignore the HUP signal.

You can try

ssh -t -t -q ${AEM_USER}@${SERVERIP} 'bash -l -c "nohup service aem start"'

If it works, you can use nohup command to start aem in the service script.

As mentioned at the stale pidfile syndrome, there are different reasons for pidfiles getting stalled, like for instance some issues with the way your handles its removal when the process exits... but considering your only experiencing when running remotely, I would guess it might be related to what is being loaded or not by your profile... check the most voted solid answer at the post below for some insights:

As described in the comments of the mentioned post, you can try sourcing /etc/profile or ~/.bash_profile before executing your script to test it, or even trying to execute env locally and remotelly to compare variables that are being sourced or not.

Related