Background

I am writing a simple script to be running in Raspbain on Raspberry Pi 2, simple turn a LED on to indicate I am ready to connect with SSH from my desktop computer.

The script is not important here, only to mention that as I use frequence control so the script is running an infinite loop, to turn the LED on and off frequently. So this is an example of simple service. However, at least the accepted answer of this question advise me to set the type to idle. So my service file looks like

[Unit]
Description=Turn on LED after SSH is ready

[Service]
Type=idle
ExecStart=/usr/bin/sshready.py

[Install]
Wants=network-online.target
After=network-online.target

Effect

The service runs as expected. However, I noticed when I start putty in my desktop computer right after the LED turns on the login prompt not appear immidiately. So I checked with

$ systemd-analyze plot > output.svg

The result shows

enter image description here

Question

It looks like my services starts not after network-online.target, what is wrong here and how can I fix it?

up vote 8 down vote accepted

When there is a question about a systemd directive, you can use man systemd.directives to find where it's documented. In this case it shows that After= is documented in man systemd.unit.

In that file, it shows that After= directive is listed in the "[UNIT] SECTION OPTIONS", indicating that it belongs in the [Unit] section of the file.

The same documentation also documents the [INSTALL] section options, and After= is not listed there.

In short, your After= directive was in the wrong location the unit file so it had no effect until you moved it to the correct location.

  • To be clear, in this case "[Unit]" is "[Service]", since it's a service file. – faho Nov 18 '16 at 13:08

Have it fixed by modifying the service as

[Unit]
Description=Turn on LED after SSH is ready
After=network-online.target

[Service]
Type=idle
ExecStart=/usr/bin/sshready.py

[Install]
WantedBy=network-online.target

Still didn't fully understand what I was doing, but it works now. Can anyone please explain?

Update

This answer was created by myself before the accepted answer comes.

  • That the After=directive must be in the [Unit] section. It's just that. – Bigon Dec 21 '16 at 22:41

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.