OPNsense Forum

English Forums => General Discussion => Topic started by: pelle on October 28, 2020, 09:37:44 am

Title: How to best execute shell command once, after OPNsense have reboot?
Post by: pelle on October 28, 2020, 09:37:44 am
I want to execute a FreeBSD shell command every time OPNsense has started. I have tried to add a @reboot crontab job, but the crontab seems to be 'cleaned' after each reboot. My @reboot is no longer in the crontab -l after a reboot.

Maybe I can use RC in some way. If so, is there any good tutorial or easy example RC-file how to create an RC job in an OPNsense FreeBSD machine (I'm have not much experience using FreeBSD or Linux)? I did read that a bad RC job might halt the startup sequence. That made me a bit cautious playing around in the RC directories.

Maybe there is a plugin I can use from within OPNsense doing a startup script/shell command?

Best Regards
- Per HÃ¥kansson
Title: Re: How to best execute shell command once, after OPNsense have reboot?
Post by: Patrick M. Hausen on October 28, 2020, 09:44:13 am
Sorry, I have no solution for you. The fact that the "Cron" setting in the UI does not let you create arbitrary cron jobs is driving me nuts as well.

Does someone know the reasoning behind this?

Kind regards,
Patrick
Title: Re: How to best execute shell command once, after OPNsense have reboot?
Post by: mimugmail on October 28, 2020, 02:01:09 pm
Add a file here:
/usr/local/etc/rc.syshook.d/start

For crontab add a file here:
/usr/local/opnsense/service/conf/actions.d/
(and give it a description)
Title: Re: How to best execute shell command once, after OPNsense have reboot?
Post by: pelle on October 28, 2020, 09:10:06 pm
Yes, yes, yes . . .  it seems to work great!! Thanks, mimugmail!

In the /usr/local/etc/rc.syshook.d/start directory, I copy the 90-cron.. job to 93-all-service-restart and edit the file to:

   #!/bin/sh

   echo -n "Restart all services: "
   configctl service reload all

This result in a startup output as follows:

   >>> Invoking start script 'all-service-restart'
   Restart all services: OK

. . . and guess what, as soon as the "Restart all services" start to execute, even before the "OK", my VXLAN starts to work :) This will fix my VXLAN remote bridge 'bug' for now.

Will this file survive an OPNsense update? . . or will the update/upgrade process wipe my new start file (93-all-service-restart)? Should I be worried to lose this fix after I update/upgrade OPNsense to next release? Does anyone know?

Once again, thanks a lot. This is great. I now can go on to test encrypting my site to site VXLAN traffic.

Best regards
- Per HÃ¥kansson
Title: Re: How to best execute shell command once, after OPNsense have reboot?
Post by: mimugmail on October 28, 2020, 10:32:18 pm
It will surive :)
But a Bug report would be nice too
Title: Re: How to best execute shell command once, after OPNsense have reboot?
Post by: Gromhelm on May 07, 2023, 07:36:58 am
Was the bug report ever posted? I had the same problem today, where my Cloudflare DynDNS script with @reboot was removed from crontab with the OPNsense upgrade.
Title: Re: How to best execute shell command once, after OPNsense have reboot?
Post by: franco on May 08, 2023, 12:13:18 pm
There isn't much of a bug report for VPN and remote tunnels not coming up upon start there is some edge case in required connectivity often with dynamic WAN use such as DHCP or PPPoE which comes up too late. Not everything can be fixed.


Cheers,
Franco