[DRE-maint] unicorn: native systemd service

Christos Trochalakis christos at skroutz.gr
Thu Jun 25 08:50:57 UTC 2015


Hello all,

I have recently migrated our main ruby application to systemd implementing zero
downtime upgrades.

systemd doesn't like replacing the binary on the fly. There is one exception to
this, services with PIDFile. When PIDFile is set, systemd reads it when the
main process exits and replaces the main process.  nginx also had this issue a
few months ago [0].

So, in order to support zero-downtime upgrades we have to use a pid file.

[0] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=728015#15

We also have to use `KillMode=mixed`. That way SIGTERM will only be send
to the main process (unicorn master) and not the workers and let unicorn
master deal with stopping its children. If the stop timeout passes
SIGKILL will be sent to all processes.

>It is not that usual to add custom actions. I've seen many init.d s scripts
>and only few had such things. I think systemd was designed using different
>philosophy. I don't know the history but it could be that limited systemd
>interface to services is quite intentional. Frankly it is annoying when init.d
>script does too much but we can avoid this by offering an additional utility
>to do soft restart and you can call it from init.d script as well if you wish.
>
>
>> > Perhaps it will be best to introduce a new binary that user could run on
>> > upgrade to do "zero downtime restart" (we can run this utility from
>> > postinst).
>> > What do you think?

I also agree with that, we could introduce a `unicornctl` helper script
supporting that kind of things, like `unicornctl upgrade` or `unicornctl
rotate`. That helper shouldn't care if this it runs on a systemd or sysvinit
system.

On more minor note regarding the proposed patch: You can safely use
`update-rc.d` in maintainer scripts, no need to use $(which update-rc.d).

Quoting https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html

> Before installation is started, the package management system checks to
> see if the programs ldconfig, start-stop-daemon, and update-rc.d can
> be found via the PATH environment variable.




More information about the Pkg-ruby-extras-maintainers mailing list