Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single start and restart command (start if not running, restart if running) #437

Open
julien-c opened this issue Jun 20, 2013 · 8 comments

Comments

@julien-c
Copy link

I might have overlooked something, but is there a way to restart a script if it's already running, and start it otherwise?

I'm having this need in a deploy script I wrote for Meteor.

Thanks!

@julien-c
Copy link
Author

julien-c commented Jul 1, 2013

Anyone? Thanks in advance for your help!

@flovilmart
Copy link

The restart should not fail if the process is not running in the first instance

@tuomassalo
Copy link

I agree with @vfloz: restart should do start if the process is not running. That would be identical to traditional UNIX daemon behavior. Any chances for this to be fixed?

(I ran into this problem when migrating an old service to use forever. Something is calling it with restart and expects is to start if not running.)

@sheldonh
Copy link

Any maintainer opinion? A way to start if not running and restart if running sounds like a great feature for deployment scripts.

@noazark
Copy link
Contributor

noazark commented Mar 16, 2014

start exits with a non zero code (I think its 1) if the process is already running so a simple forever start || forever restart should do the job right? The production init script my company uses to deploy apps has a restart method that looks something like this:

restart() {
  if [ "$foreverid" != "" ]; then
    forever restart $foreverid
  else
    forever start $script
  fi
}

I much prefer handling the (re)starting myself.

@indexzero
Copy link
Member

👍 will go into forever@1.0.0 since it is breaking.

@indexzero indexzero changed the title Conditional restart/start Single start and restart command (start if not running, restart if running) Dec 15, 2015
@markstos
Copy link

As a forever user, I'm going to be looking at solving this with systemd as a process manager in the future. systemd features three levels of off to help address is. In addition to stopping a service, you can also "disable" it. Further, systemd offers a try-restart command, which is explicitly designed to only restart a service that's already running.

If forever adds this feature, I recommend that's also called try-restart to follow the same pattern.

@julien-c
Copy link
Author

For potential reference, this works fine:

forever restart $SCRIPT || forever start $SCRIPT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants