Can't start a service (sudo) remotely from script and keep it running

Posted by Greg Bernhardt on Super User See other posts from Super User or by Greg Bernhardt
Published on 2012-05-18T16:22:50Z Indexed on 2012/11/20 17:05 UTC
Read the original article Hit count: 223

Filed under:
|
|

I have a service (tomcat) that needs sudo to be started. I made a simple script on the remote server in /root/bin/test.sh

#!/bin/sh
sudo service tomcat start
read

(The script needs to do other stuff too, just pared down for simplicity). When I run a it directly on the remote server, tomcat starts and continues running on the server after I disconnect.

When I run it remotely, the process starts, (I can see it when paused for the "read"), but once the script ends, it's gone. (while paused for the read, run this command locally)

ps -ef | grep tomcat

I've tried various combinations of nohup, screen, and & on the commands both on the local machine and in the remote machine's test.sh script, but I can't seem to get it working.

ssh -t [email protected] "/root/bin/test.sh"
ssh -t [email protected] "nohup /root/bin/test.sh"
ssh -t [email protected] "nohup /root/bin/test.sh &"
ssh -t [email protected] "screen /root/bin/test.sh &"

© Super User or respective owner

Related posts about bash

Related posts about ssh