unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Christos Trochalakis <yatiohi@ideopolis.gr>
To: Eric Wong <e@80x24.org>
Cc: Dmitry Smirnov <onlyjob@debian.org>,
	Hleb Valoshka <375gnu@gmail.com>,
	unicorn@packages.debian.org, unicorn-public@bogomips.org
Subject: Re: [DRE-maint] unicorn: native systemd service
Date: Wed, 8 Jul 2015 16:08:21 +0300	[thread overview]
Message-ID: <20150708130821.GA1361@luke.ws.skroutz.gr> (raw)
In-Reply-To: <20150630173001.GA22252@dcvr.yhbt.net>

>Christos Trochalakis <yatiohi@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@.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@1.service

[Install]
WantedBy=sockets.target

==> end <==

systemctl daemon-reload
systemctl enable uni.socket
systemctl start uni.socket

systemctl enable uni@1 uni@2 # Make them start at boot
systemctl start uni@1 uni@2

Now you can start and stop uni@1 and uni@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

      reply	other threads:[~2015-07-08 13:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <16714105.fRFKlev1fp@debstor>
     [not found] ` <3137844.nsIDTWmvl4@debstor>
     [not found]   ` <CAAB-Kc=s-uSK83PcfDsybPRiYvTaLVxcu2x4eWDPaTf27AJ_XQ@mail.gmail.com>
     [not found]     ` <1810167.FXDESjsu8Z@debstor>
2015-06-24 23:26       ` unicorn: native systemd service Eric Wong
2015-06-25 23:43         ` Dmitry Smirnov
2015-06-25 23:49           ` Eric Wong
     [not found]   ` <20150625083118.GA22140@luke.ws.skroutz.gr>
2015-06-25 23:26     ` [DRE-maint] " Eric Wong
2015-06-26 11:41       ` Christos Trochalakis
2015-06-27  3:05         ` Eric Wong
2015-06-27  4:01           ` [RFC] emulate sd_listen_fds for systemd support Eric Wong
2015-06-30  8:47             ` Christos Trochalakis
2015-07-05  0:27               ` [PATCH v2] " Eric Wong
2015-06-30  9:20           ` [DRE-maint] unicorn: native systemd service Christos Trochalakis
2015-06-30 17:30             ` Eric Wong
2015-07-08 13:08               ` Christos Trochalakis [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/unicorn/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150708130821.GA1361@luke.ws.skroutz.gr \
    --to=yatiohi@ideopolis.gr \
    --cc=375gnu@gmail.com \
    --cc=e@80x24.org \
    --cc=onlyjob@debian.org \
    --cc=unicorn-public@bogomips.org \
    --cc=unicorn@packages.debian.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/unicorn.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).