[DRE-maint] unicorn: native systemd service
Christos Trochalakis
yatiohi at ideopolis.gr
Wed Jul 8 13:08:21 UTC 2015
>Christos Trochalakis <yatiohi at ideopolis.gr> wrote:
>> On Sat, Jun 27, 2015 at 03:05:01AM +0000, Eric Wong wrote:
>> >Is it possible to make systemd fire up two unicorn masters?
>> >That would be a nice feature to have with socket activation.
>>
>> That would be great! I am a bit surprised that specifying multiple
>> services ('Service=' option) is not supported.
Apparently I was wrong. I missed the 'Sockets=' option for Service units.
You can specify a list of socket units to be inherited (if active) when
the service is started. Note that this is not the reverse of Sockets'
'Service=' option: the service is not auto-started when there is an
incoming connnection on the relevant socket, you have to use 'Service='
for socket activation.
Here is a test config for 2 preforked unicorn masters using service
templates (I am using the latest unicorn with the systemd patch):
==> /srv/uni/config.ru <==
puts "initializing for 5sec"
sleep 5
app = proc do |env|
[
200,
{ 'Content-Type' => 'text/plain' },
["ppid:#{Process.ppid}\n"]
]
end
run app
==> /srv/uni/unicorn.conf.rb <==
worker_processes 2
working_directory "/srv/uni"
# Keep in sync with uni.socket file
listen 9000
listen 9001
==> /etc/systemd/system/uni at .service <==
[Unit]
Description=Unicorn Server %i
Wants=uni.socket
After=uni.socket
[Service]
ExecStart=/usr/local/bin/unicorn -c /srv/uni/unicorn.conf.rb -d
Sockets=uni.socket
KillSignal=SIGQUIT
[Install]
WantedBy=multi-user.target
==> /etc/systemd/system/uni.socket <==
[Unit]
Description=Unicorn Sockets
[Socket]
ListenStream=0.0.0.0:9000
ListenStream=0.0.0.0:9001
Service=uni at 1.service
[Install]
WantedBy=sockets.target
==> end <==
systemctl daemon-reload
systemctl enable uni.socket
systemctl start uni.socket
systemctl enable uni at 1 uni at 2 # Make them start at boot
systemctl start uni at 1 uni at 2
Now you can start and stop uni at 1 and uni at 2 with zero latency and without losing
a connection. So we have a happy ending after all :)
While searching systemd's mailing list, I found a thread discussing about a
'Distribute=' option to sockets a few years back[0]. There is also a relevant
item in systemd's TODO list.
[0] http://thread.gmane.org/gmane.comp.sysutils.systemd.devel/14242/focus=14255
More information about the Pkg-ruby-extras-maintainers
mailing list