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

Add systemd's unicorn service #23

Merged
merged 3 commits into from May 2, 2018

Conversation

Projects
None yet
3 participants
@jstoja
Contributor

jstoja commented Apr 27, 2018

This adds a systemd unit file and uses it to start/reload the app.
It's enabled at startup with the enabled=yes.
I didn't specify the restart always because it's not handled to my knowledge now (and that it's usually a bad idea to force restarting blindly a process).

If you have any remark, please do.

Should close #7

@pushcx

This comment has been minimized.

Show comment
Hide comment
@pushcx

pushcx Apr 29, 2018

Member

This looks like it'll handle #7, thank you. Before I merge, could you elaborate on what you mean by "restart always"?

Member

pushcx commented Apr 29, 2018

This looks like it'll handle #7, thank you. Before I merge, could you elaborate on what you mean by "restart always"?

@jstoja

This comment has been minimized.

Show comment
Hide comment
@jstoja

jstoja Apr 29, 2018

Contributor
Contributor

jstoja commented Apr 29, 2018

@PeterFaiman

Restarting services is a pretty good practice, but yes restarting forever rapidly isn’t the best idea. You can use RestartSec, RestartLimitInterval, and RestartLimitBurst to control the behavior. For example:

Restart=always
RestartSec=60
RestartLimitBurst=5
RestartLimitInterval=3600

That config will attempt to restart the process 60 seconds after it exits, but a maximum of 5 times per hour. This doesn’t affect manually stopping the process.

Those are fairly conservative settings. I use RestartSec=5 with no rate limit. But I also know what will happen if my services restart that quickly.

Show outdated Hide outdated roles/unicorn/files/lobsters-unicorn.service
PIDFile=/srv/lobste.rs/run/unicorn.pid
ExecStart=/usr/bin/bundle exec "unicorn_rails -c config/unicorn.conf.rb -E production -D config.ru"
ExecStop=/usr/bin/pkill -QUIT -f 'unicorn_rails master'

This comment has been minimized.

@PeterFaiman

PeterFaiman May 1, 2018

You should use $MAINPID here, which systemd automatically sets from the pidfile. It should be more reliable than finding the process by name.

@PeterFaiman

PeterFaiman May 1, 2018

You should use $MAINPID here, which systemd automatically sets from the pidfile. It should be more reliable than finding the process by name.

This comment has been minimized.

@jstoja

jstoja May 1, 2018

Contributor

How about using /srv/lobste.rs/run/unicorn.pid as the PID file, since it's created by unicorn itself? I have no idea which one is the more reliable and reagarded as the best practice.

@jstoja

jstoja May 1, 2018

Contributor

How about using /srv/lobste.rs/run/unicorn.pid as the PID file, since it's created by unicorn itself? I have no idea which one is the more reliable and reagarded as the best practice.

@jstoja

This comment has been minimized.

Show comment
Hide comment
@jstoja

jstoja May 1, 2018

Contributor

That's a great idea and a very nice feedback! Thank you very much for this!
I'm changing that ASAP :)

Contributor

jstoja commented May 1, 2018

That's a great idea and a very nice feedback! Thank you very much for this!
I'm changing that ASAP :)

@jstoja

This comment has been minimized.

Show comment
Hide comment
@jstoja

jstoja May 1, 2018

Contributor

I tested the automatic restart after a fail and it worked well with the burst limit 👍

Contributor

jstoja commented May 1, 2018

I tested the automatic restart after a fail and it worked well with the burst limit 👍

@pushcx pushcx merged commit 88e939a into lobsters:master May 2, 2018

@pushcx

This comment has been minimized.

Show comment
Hide comment
@pushcx

pushcx May 2, 2018

Member

This is great to have, especially with the upcoming downtime. Thanks for tackling it, @jstoja, and thank you, @PeterFaiman for collaborating to make it more robust.

Member

pushcx commented May 2, 2018

This is great to have, especially with the upcoming downtime. Thanks for tackling it, @jstoja, and thank you, @PeterFaiman for collaborating to make it more robust.

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