Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd systemd's unicorn service #23
Conversation
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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"?
|
This looks like it'll handle #7, thank you. Before I merge, could you elaborate on what you mean by "restart always"? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jstoja
Apr 29, 2018
Contributor
|
I meant using this option in the systemd’s unit file: https://www.freedesktop.org/software/systemd/man/systemd.service.html#Restart=
If we want to enable this, I’d setup some monitoring to at least notify someone that it restarted (for example notify if restarted >= 3 in the last hour).
What do you think about this?
… On 29 Apr 2018, at 04:53, Peter Bhat Harkins ***@***.***> wrote:
This looks like it'll handle #7, thank you. Before I merge, could you elaborate on what you mean by "restart always"?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
PeterFaiman
reviewed
May 1, 2018
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.
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.
Show comment
Hide comment
This comment has been minimized.
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
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.
Show comment
Hide comment
This comment has been minimized.
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
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.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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 :)
|
That's a great idea and a very nice feedback! Thank you very much for this! |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jstoja
May 1, 2018
Contributor
I tested the automatic restart after a fail and it worked well with the burst limit
|
I tested the automatic restart after a fail and it worked well with the burst limit |
pushcx
merged commit 88e939a
into
lobsters:master
May 2, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
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. |
jstoja commentedApr 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