I have a script that uses the route command to add or remove a network route. It works fine if I run it from the terminal as a regular script.
However I tried to automate its execution so it runs on boot using a systemd one-shot service.
I've created the service and everything appears to run fine, no complains anywhere, no error codes or messages that I can observe anywhere, however the route is neither added nor deleted.
I suspect systemd is imposing some kind of restriction when running "route add/del" but can't figure out what it is.
I'm running CentOS 7 so adding "+" to the ExecStart, ExecStop is not possible.
I've tried to set KillMode=None (to allow forking from within the script, I know this is not advised) it does not help.
I made a version of the script that only adds/removes the route, this is, for testing purposes I've reduced the script to practically a single line doing "route add"/"route del" to troubleshoot this and I can say 100% that the problem lies on running "route add/del" and not something else in the script borking systemd.
I'm not sure how to proceed, if anyone could offer some insight or ways to debug this it would be great.
This is my service definition, nothing out of the ordinary:
[Unit]
Description=Add/remove network X
After=network-online.target
[Service]
Type=oneshot
KillMode=none
ExecStart=/usr/local/bin/script.sh --start
ExecStop=/usr/local/bin/script.sh --stop
[Install]
WantedBy=multi-user.target
Notes: I'm aware 'systemd-networkd' can create network routes, but this is not what I'm after as the script does many more things besides adding or removing the network route.
route addwhen your script is started with systemd? Did you addset -xvto your script and looked at the output with journalctl?