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

SystemV init script is not idempotent #451

Closed
OlegIlyenko opened this issue Jan 5, 2015 · 4 comments
Closed

SystemV init script is not idempotent #451

OlegIlyenko opened this issue Jan 5, 2015 · 4 comments
Labels
bug universal Zip, tar.gz, tgz and bash issues

Comments

@OlegIlyenko
Copy link
Contributor

I'm creating a debian package with SystemV (init.d) init script in it. The problem is that I able to sudo service my-app start several times in a row and it will start several processes. I expect it to start my service the first time and fail all consequent starts because service is already started and running.

The actual issue is in the way services are started. It uses --exec here:

start-stop-daemon --background --chdir ${{chdir}} --chuid "$DAEMON_USER" --make-pidfile --pidfile "$PIDFILE" --exec "$RUN_CMD" --start -- $RUN_OPTS

The problem is that in order to check whether the service is running, --exec not only checks the PID file, but also the /proc/[PID]/exe file (see this article for more detail). This is a problem, because the actual process is a java process, but what I give to the start-stop-daemon command is an application name like my-service.

I looked at this issue and found 2 possible solutions. One would be to use --startas instead of --exec like described in article I linked above. Another solution would be to use exec -a <actual-service-name> "$@" in the application script:

https://github.com/sbt/sbt-native-packager/blob/master/src/main/resources/com/typesafe/sbt/packager/archetypes/bash-template#L136

in order to change the process name.

@muuki88 muuki88 added bug universal Zip, tar.gz, tgz and bash issues labels Jan 5, 2015
@muuki88
Copy link
Contributor

muuki88 commented Jan 5, 2015

Thanks for the detailed bug report! What are the difference between your solutions?

Using the start-stop-daemon solution would mean that only the debian/SystemV packages
would benefit, right? The new script would look something like

start-stop-daemon --background \
--chdir ${{chdir}} --chuid "$DAEMON_USER"  \
--make-pidfile --pidfile "$PIDFILE" \
--startas "$RUN_CMD" --start -- $RUN_OPTS

The second solution, using exec -a means that the bashscript itself starts a named
process, which should make the start-stop-daemon behave as expected.

exec -a ${{app_name}} "$@" 

What would you suggest? PRs welcome :)

@OlegIlyenko
Copy link
Contributor Author

Hi, thanks for the fast feedback! Yes, you described it correctly. I generally would prefer the second solution (exec -a), because --startas has some downsides (and exec -a makes nice process names).

I was not sure which solution would be more idiomatic for the SBT plugin, so I decided to just create an issue. Also I was not sure whether i understand the problem correctly (or missing some obvious solution) - judging by the scope of this issue, I would assume that many people should potentially face it. But if we agree on some particular solution, I can make a PR.

@muuki88
Copy link
Contributor

muuki88 commented Jan 5, 2015

Using exec -a sounds more reasonable to me as well, as this is the more general
solution. This issue may have not occurred for most of the users as the system-loader
takes care of starting and stopping or most use service restart.

Happy to merge your PR. Nice avatar btw ;)

@OlegIlyenko
Copy link
Contributor Author

Thanks :) Ok, I will try to test the change with our setup tomorrow, and if everything works fine, i will make a PR.

OlegIlyenko added a commit to OlegIlyenko/sbt-native-packager that referenced this issue Jan 7, 2015
…pt idempotent. This will only use PID file to check whether application is started or not. `--exec` in contrast is also checks the `/proc/[PID]/exe` file which links to the java executable and not original start script (see [this article](https://chris-lamb.co.uk/posts/start-stop-daemon-exec-vs-startas)). For more detail please see the discussion on sbt#451
@muuki88 muuki88 closed this as completed Jan 8, 2015
muuki88 pushed a commit that referenced this issue Jan 8, 2015
…pt idempotent. This will only use PID file to check whether application is started or not. `--exec` in contrast is also checks the `/proc/[PID]/exe` file which links to the java executable and not original start script (see [this article](https://chris-lamb.co.uk/posts/start-stop-daemon-exec-vs-startas)). For more detail please see the discussion on #451
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug universal Zip, tar.gz, tgz and bash issues
Projects
None yet
Development

No branches or pull requests

2 participants