You are not logged in.

#1 2017-10-10 17:58:03

Perry3D
Member
Registered: 2008-03-20
Posts: 553

[SOLVED] Start systemd service after network is up

Hello everybody,

i wrote a small systemd service that turns on and off a bulb in a zigbee network when my computer starts:

[Unit]
Description=Turn on/off osram plug

[Service]
User=oli
Type=oneshot
RemainAfterExit=yes
ExecStart=/home/oli/scripts/osramTurnOn.sh
ExecStop=/home/oli/scripts/osramTurnOff.sh
Requires=network.target
After=network.target

[Install]
WantedBy=multi-user.target

It works perfectly if i start it with

systemctl start osramPlug.service

.

But it doesn't work during boot time.

# systemctl status osramPlug.service
● osramPlug.service - Turn on/off osram plug
   Loaded: loaded (/etc/systemd/system/osramPlug.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2017-10-10 19:41:19 CEST; 9min ago
  Process: 352 ExecStart=/home/oli/scripts/osramTurnOn.sh (code=exited, status=7)
Main PID: 352 (code=exited, status=7)

Oct 10 19:41:18 perryLinux64 systemd[1]: Starting Turn on/off osram plug...
Oct 10 19:41:19 perryLinux64 osramTurnOn.sh[352]: curl: (7) Couldn't connect to server
Oct 10 19:41:19 perryLinux64 systemd[1]: osramPlug.service: Main process exited, code=exited, status=7/NOTRUNNING
Oct 10 19:41:19 perryLinux64 systemd[1]: osramPlug.service: Failed with result 'exit-code'.
Oct 10 19:41:19 perryLinux64 systemd[1]: Failed to start Turn on/off osram plug.


Apparently it needs a network connection. I also tried the network-online.target instead of the network.target.
I use the systemd-networkd service but also tried the Networkmanager.
Where is my error?

Last edited by Perry3D (2017-10-10 18:19:28)

Offline

#2 2017-10-10 18:05:29

edacval
Member
From: .LT
Registered: 2008-10-23
Posts: 71

Re: [SOLVED] Start systemd service after network is up

At least

Requires=network.targe
After=network.target

must be placed in [Unit]  section

Last edited by edacval (2017-10-10 18:05:46)

Offline

#3 2017-10-10 18:19:04

Perry3D
Member
Registered: 2008-03-20
Posts: 553

Re: [SOLVED] Start systemd service after network is up

Thank you very much. This with the network-online.target seems to work.

[Unit]
Description=Turn on/off osram plug
Requires=network-online.target
After=network-online.target

[Service]
User=oli
Type=oneshot
RemainAfterExit=yes
ExecStart=/home/oli/scripts/osramTurnOn.sh
ExecStop=/home/oli/scripts/osramTurnOff.sh

[Install]
WantedBy=multi-user.target

Offline

Board footer

Powered by FluxBB