How do I restart a service a minute or 2 after reboot?
-
Long ago I used it to restart unbound 1 minute after each reboot:
-n pfSsh.php playback svc restart unbound | at now + 1minute
That problem was fixed but now I need to restart an openvpn client 1 minute after reboot and it's not working. Testing from the CLI it appears "at" doesn't have any effect.
I understand it's best to address the root of the issue rather than restarting a service after boot, but this will fix it until i can spend more time on it.
Thanks,
-
You can do a @reboot in cron however I do not know what time they run during reboot
-
@py said in How do I restart a service a minute or 2 after reboot?:
Testing from the CLI it appears "at" doesn't have any effect.
Like it runs immediately or not at all?
That command is probably just piping to result of the restart to at. You probably want something more like:
echo 'pfSsh.php playback svc restart unbound' | at now + 5 minutes
-
@stephenw10
I'm trying to get this working in the CLI before I bother with Cron.
From the CLI, the following result in immediate restart of the correct openvpn client:pfSsh.php playback svc restart openvpn client 3
pfSsh.php playback svc restart openvpn client 3 | at now + 1minute
pfSsh.php playback svc restart openvpn client 3 | at now + 1 minuteThis is why I wondered if "at" is even part of the OS.
The following had no result, except for the Shell Output "Job ?? will be executed using /bin/sh:"
echo 'pfSsh.php playback svc restart openvpn client 3' | at now + 1minute
echo 'pfSsh.php playback svc restart openvpn client 3'Specifying the full paths also results in no restart:
/usr/local/sbin/pfSsh.php playback svc restart /usr/local/sbin/openvpn client 3 | at now + 1minute
Another thing i noticed is that when the openvpn service is restarted from the CLI, the restart appears in the OpenVPN log but not always in the Status page, (Status > OpenVPN). I haven't tracked that enough yet to see which specific command keeps it from appearing on the Status page.
-
What pfSense version are you doing this in?
Since atrun only runs at 5min intervals now+1m might not get run. Hence I tested at +5m.
However it still fail here logging:
Jan 6 14:40:00 atrun 17651 cannot chdir to /var/at/spool: No such file or directory
Do you also see that?
-
@py said in How do I restart a service a minute or 2 after reboot?:
result in immediate restart
Well I'd read what you wrote as you're piping the result of pfSsh.php to at. Did you try the "echo" as above? Is the "-n" from "echo -n" maybe?
Maybe, "sleep 60 && pfSsh.php playback svc restart openvpn client 3" ?
-
Yup using sleep is probably easier. Though if you run that as a shellcmd it may just sleep the boot process entirely!
-
"sleep 60 && pfSsh.php playback svc restart openvpn client 3 &" to spawn it?
run a .sh script with sleep, via @reboot in cron (which has a pfSense package, for lurkers)?
-
@SteveITS @stephenw10
This is pfSense + 24.11.I haven't tried "atrun" but I was aware of the 5 minute granularity. However, years ago "at now + 1minute" worked after 1 minute, or close enough I didn't notice. This is acting so different that I still wonder if "at" is even part of the OS anymore, and based on your result, maybe "atrun" is also gone?
I know where the FreeBSD manual is and I've been using that, but I could use a command reference that shows the specifics on how to use "at" or "sleep" in this context. I'm using the pipe symbol, but I found that on another forum somewhere long ago and could use a reference on how to use all these together instead of hunting and pecking to see if it works. And I realize there may still be some hunt and peck but at least it might be reduced.
Thanks,
-
@SteveITS
"sleep 60...." did it, thanks!
Tested with a reboot and it did not sleep the reboot process either.Status > OpenVPN also shows the time (re)started correctly.
Much appreciated and thanks to everyone for their help!