unable to start a service using 'run'

26 views
Skip to first unread message

kevin....@praxeon.com

unread,
Mar 23, 2007, 7:40:17 AM3/23/07
to Capistrano
I am using the 'run' command to try and start a service (jboss) on a
remote machine. The init script is installed and works when executed
on the remote machine via

/sbin/service start jboss

or

/etc/rc.d/init.d/jboss start

When I run either of these commands through capistrano, the server
startup is begun and then terminated when capistrano closes the
connection. It's as if I was issuing a ctrl-c command to the script.
How can I get capistrano to let the service keep running when the
connection is closed?

Jamis Buck

unread,
Mar 23, 2007, 10:18:01 AM3/23/07
to capis...@googlegroups.com
Kevin,

You'll need to invoke the command via nohup, to ensure the process
will outlive the parent that spawned it. Something like:

run "nohup /sbin/service start jboss"

The drawback of this is that nohup swallows all output of the
command, so you'll not get any feedback of whether the command
actually started or not. :( I've not found a better solution, though.

- Jamis

Drew Raines

unread,
Mar 23, 2007, 12:37:18 PM3/23/07
to capis...@googlegroups.com
Jamis Buck wrote:

> You'll need to invoke the command via nohup, to ensure the process
> will outlive the parent that spawned it. Something like:
>
> run "nohup /sbin/service start jboss"
>
> The drawback of this is that nohup swallows all output of the
> command, so you'll not get any feedback of whether the command
> actually started or not. :( I've not found a better solution,
> though.

How about:

run "sh -c \"/sbin/service start jboss &\""

I'm not sure what capistrano magic might prohibit this from working
remotely, but sh(1) should get exec()'d with "/sbin/service..." as an
argument. The ampersand should do its work then and the jboss
process's parent will be init/launchd/etc. You should also see
stdout & stderr.

I do this all the time with sudo, e.g.:

sudo -u mysql sh -c "mysqld_safe &"

-Drew

kgilpin

unread,
Mar 23, 2007, 12:57:52 PM3/23/07
to Capistrano
This sounds totally reasonable and it appears to solve my problem.

But why is it that I don't need nohup to start this service (jboss)
when I am running from a logged-in shell? And I don't need to use
nohup in order to start services like mysql using 'run'. They start
just fine as

run "/sbin/service mysql start"

When I try Drew's suggestion below (with or without the &)

sh -c \"/sbin/service jboss start &\"

I see the same problem as before. Only nohup seems to help. I also at
one point had nohup in the script itself on the server and that didn't
seem to work either.

At this point I am happy that things are working and I'm just trying
to figure out where the gaps in my knowledge are. These particular
ones... Perhaps this is too entangled to comprehend.

On Mar 23, 10:18 am, Jamis Buck <j...@37signals.com> wrote:
> Kevin,
>
> You'll need to invoke the command via nohup, to ensure the process
> will outlive the parent that spawned it. Something like:
>
> run "nohup /sbin/service start jboss"
>
> The drawback of this is that nohup swallows all output of the
> command, so you'll not get any feedback of whether the command
> actually started or not. :( I've not found a better solution, though.
>
> - Jamis
>

> On Mar 23, 2007, at 5:40 AM, kevin.gil...@praxeon.com wrote:
>
>
>
>
>
> > I am using the 'run' command to try and start a service (jboss) on a
> > remote machine. The init script is installed and works when executed
> > on the remote machine via
>
> > /sbin/service start jboss
>
> > or
>
> > /etc/rc.d/init.d/jboss start
>
> > When I run either of these commands through capistrano, the server
> > startup is begun and then terminated when capistrano closes the
> > connection. It's as if I was issuing a ctrl-c command to the script.
> > How can I get capistrano to let the service keep running when the

> > connection is closed?- Hide quoted text -
>
> - Show quoted text -

Reply all
Reply to author
Forward
0 new messages