i have a previous rc.local file which was a startup script on a router machine i have. it is designed to run tcpdump commands for the interfaces and output them to terminals tty9, tty10, and tty11. it worked perfectly...
i have since transitioned to systemd. I followed wiki instructions to make a oneshot service file and have enabled it. here is the file: (/usr/lib/systemd/system/startup.service)
[Unit] Description=Startup Script After=iptables.service [Service] Type=oneshot ExecStart=/etc/scripts/startup [Install] WantedBy=multi-user.target
here is the script /etc/scripts/startup: (email addresses disquised)
#!/bin/bash route add -net 10.11.12.0/24 gw 172.16.16.4 /usr/sbin/tcpdump -pnq -i external >> /dev/tty11 & /usr/sbin/tcpdump -pnq -i internal >> /dev/tty10 & /usr/sbin/tcpdump -pq -i wifi >> /dev/tty9 & echo "$HOSTNAME system startup complete `date '+%r %x'`" | /usr/bin/mailx -c "firstname.lastname@example.org" -s "$HOSTNAME Startup Message" email@example.com
here is the output from the startup command with journalctl:
Nov 18 22:46:10 pLAN9-Gateway systemd: Starting Startup Script... Nov 18 22:46:10 pLAN9-Gateway systemd: Starting OpenSSH Daemon... Nov 18 22:46:10 pLAN9-Gateway systemd: Started OpenSSH Daemon. Nov 18 22:46:13 pLAN9-Gateway startup: . . . message not sent. Nov 18 22:46:13 pLAN9-Gateway systemd: Started Startup Script.
the route add command runs, but nothing else does. as you can see, there is absolutley NOTHING helpful in the log, other than the completely useless "message not sent" output from mailx. running the startup script manually with "systemctl start startup" works fine.
iptables.service is setup to run After=netcfg.service, so I would assume that beucase the startup script runs after iptables, it should run after netcfg as well.
why aren't these commands running?
A oneshot service is killed once the main process returns (that's why it is called a "oneshot"). Your tcpdump processes are killed once startup returns.