1

I have written some simple daemon and I want my system to automatically start it on boot. My daemon needs bluetooth daemon to be started and UNIX socket for outputting data. What is a bit different from what can be read in most manuals and tutorials about systemd is that from daemon point of view I want systemd to create socket for writing, not listening. When I start service and socket manually everything works, however after executing systemctl enable foo.service my daemon is not started after reboot. Based on man systemd.unit, man systemd.target and some googling I have created 3 unit files.

Due to the fact that there seems to be at least few ways in which dependencies can be described for systemd I don't know what is wrong, why my service is not automatically started after reboot. Should I create foo.target file or is it unnecessary in such simple scenario? I am also not sure if WantedBy in foo.socket should be set to foo.target or more maybe to sockets.target.

Here is code snippet of my 3 unit files below. I would really appreciate if someone could take a look and give me some tips.

############ foo.service file #############################################
[Unit]
Description=Foo Service
Requires=foo.socket

[Service]
Type=simple
ExecStart=/path/to/start

[Install]
WantedBy=foo.target
###########################################################################
############ foo.socket file ##############################################
[Unit]
Description=Foo socket for write, not for listen

[Socket]
ListenDatagram=/run/foo/foo.sk

[Install]
WantedBy=foo.target
###########################################################################
############ foo.target file ##############################################
[Unit]
Description=Foo target
Requires=bluetooth.target
###########################################################################

1 Answer 1

1

You have instructed systemd to start your service and socket when your target starts, but you have not instructed the the target should not be started at boot. It has no [Install] section-- which is why your service doesn't some up at boot.

A target is not necessary for this simple case. Move the Requires= clause from your target to your service.

For the WantedBy= in your service, try using multi-user.target, or if your service needs networking, network-online.target.

3
  • If I have Requires=foo.socket in my foo service unit file, do I also need WantedBy=foo.service in foo.socket file in [Install] section? Is the section [Install] needed in foo.socket if it is defined in foo.service that foo.socket is required? Isn't it like writing the same information twice?
    – Al Bundy
    Commented Jul 24, 2018 at 7:54
  • Little fix to previous comment RequiredBy=foo.service instead of WantedBy=foo.service.
    – Al Bundy
    Commented Jul 24, 2018 at 8:04
  • @AlBundy You are welcome to test removing the [Install] section in your socket file. I think you'll find it's unnecessary as you suspect. If my answer was was helpful, please consider upvoting and accepting it. Thanks. Commented Jul 24, 2018 at 15:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .