[systemd-devel] Restarting a socket starts the associated service

Tim Cuthbertson tim at gfxmonk.net
Mon Mar 24 21:05:11 PDT 2014


Hi all,

I've got a socket-activated service, called `myapp-main.service` and
`myapp-main.socket`. These are part of myapp.target:

$ cat myapp.target
[Install]
WantedBy=multi-user.target

$ cat myapp-main.service
[Unit]
After=local-fs.target
After=network.target
Requires=myapp-main.socket

[Service]
ExecStart=< .. uninteresting .. >

$ cat user/myapp-main.socket
[Socket]
ListenStream=9776

[Unit]
PartOf=myapp.target

[Install]
WantedBy=myapp.target

--------------------------

When I install the units, I run:

$ systemctl reenable myapp-main.service myapp-main.socket myapp.target
$ systemctl daemon-reload
$ systemctl reload-or-try-restart myapp-main.service myapp-main.socket
myapp.target
$ systemctl start myapp.target

This ensures that required units are started, while also ensuring that
if the service did happen to be running already, it is restarted.

On the first install, myapp-main.socket is made active, but
myapp-main.service is not (since it's socket activated, and nothing
uses it). However on the second install it is now running.

It seems to be that if you run `systemctl restart` on a socket that is
currently listening, it starts the associated service even if it was
not previously running. Is this intentional? Is there some different
approach I should use to ensure that:

a) all running units in my list of units that I've installed are
reloaded / restarted
b) no services are unnecessarily started

Cheers,
 - Tim.


More information about the systemd-devel mailing list