You are not logged in.
Hi, I am trying to write a systemd service that runs and completes before NetworkManager.service starts.
I tried this:
[Unit]
Description=Custom service test
Before=NetworkManager.service
[Service]
Type=oneshot
ExecStart=/usr/bin/echo Custom service test 1
ExecStart=/usr/bin/sleep 5
ExecStart=/usr/bin/echo Custom service test 2
[Install]
WantedBy=network.target
While the custom service does start, I got this rather strange output:
Jan 22 00:12:46 localhost echo[1166]: Custom service test 1
Jan 22 00:12:48 localhost kernel: NVRM: GPU at 0000:02:00: GPU-(snip)
... some unrelated messages (acpid, kdm, etc) ...
Jan 22 00:12:49 localhost systemd-logind[1170]: Linked /tmp/.X11-unix/X0 to /run/user/1000/X11-display.
Jan 22 00:13:13 localhost echo[1254]: Custom service test 2
Jan 22 00:12:50 localhost systemd[1]: Started Custom service test.
Jan 22 00:12:50 localhost systemd[1]: Starting Network Manager...
As you can see, while everything appears in the expected order in the log, the timestamps look very wrong. The "Custom service test 2" says "00:13:13", yet it is in the middle of "00:12:49" and "00:12:50". What gives?
Also, notice that the first echo was at 00:12:46, but NetworkManager started at 00:12:50, which is only 4 seconds later. The "sleep" in the custom services should have made it start at 00:12:51 at the earliest. I don't understand why things are not being respected.
The output I'd expect to see is something like this:
Jan 22 00:12:46 localhost echo[1166]: Custom service test 1
...
Jan 22 00:12:51 localhost echo[1254]: Custom service test 2
Jan 22 00:12:51 localhost systemd[1]: Started Custom service test.
Jan 22 00:12:51 localhost systemd[1]: Starting Network Manager...
I have also made sure that it shows up in NetworkManager.service's After list:
$ systemctl show -p After NetworkManager.service
After=mycustomservice.service syslog.target systemd-journald.socket dbus.socket basic.target
Offline
Sooooo this begs the question: what are you really trying to do?
I'm trying to write a script that changes the interface's MAC address before NetworkManager gets a chance to take over the network interface. I'm aware that there's a page about exactly that on the wiki. I started with the systemd service from the bottom of the page, which says "Before=dhcpcd@%i.service". I changed that line to use "NetworkManager.service", and I changed the ExecStart line to "/usr/bin/macchanger -A myinterface" in order to get a random MAC address, instead of setting a fixed one like the example shows. Then I saw that macchanger's output was being mixed with NetworkManager's output in the journal, so I decided to try and write a custom service just for testing, making it start before NetworkManager, in order to see if it really was systemd's fault or if it was something macchanger-specific. Then I noticed the strange behavior described in the OP, didn't really know what to do about it, so I posted this topic. That's the story so far...
Last edited by WindPower (2013-01-23 00:13:22)
Offline