OPNsense Forum

Archive => 15.1 Legacy Series => Topic started by: ortylp on March 30, 2015, 06:30:47 pm

Title: [SOLVED] How to start a custom script at boot.
Post by: ortylp on March 30, 2015, 06:30:47 pm
I need to run a script that catches external event and triggers /sbin/poweroff.

How can I bind it in and start at boot?  All methods known to me were wiped off after reboot.
Title: Re: How to start a custom script at boot.
Post by: franco on March 31, 2015, 07:57:48 am
The easiest way is to hook into /usr/local/etc/rc or /usr/local/etc/rc.bootup depending on whether you like shell scripting or PHP, respectively. A good spot would be around https://github.com/opnsense/core/blob/master/src/etc/rc#L263-270 depending how early it should be executed (if it needs network connectivity it should be after rc.bootup).

Currently, these customisations are lost when the system is upgraded to a new version to keep the files consistent. We are working on a more permanent solution as part of the package system and would like to avoid introducing hacks that work but we can't get rid of afterwards because others depend on it.

However, we can work something intermediate out if we keep talking. What do you think? :)
Title: Re: How to start a custom script at boot.
Post by: AdSchellevis on March 31, 2015, 10:15:18 am
This was on the todo list, so here it is  :)

Commit https://github.com/opnsense/core/commit/f290b78c5b240df2e1a2d504a7b433ea83243d3b implements the new feature.

To use this feature, just create a standard rc.d script and place it in /usr/local/etc/rc.d/ then enable the script using the standard variables in /etc/rc.conf.d/.

One example to start squid using this system (after installation of the package):

file : /etc/rc.conf.d/squid
content : squid_enable=YES


The feature doesn't contain all the nice options the standard FreeBSD system has, but it's a step in the right direction.

For reference see discussion over here https://github.com/opnsense/core/issues/94
Title: Re: How to start a custom script at boot.
Post by: franco on March 31, 2015, 11:38:06 am
I would rather use /usr/local/etc/rc.conf.d/ for this purpose as our scripts are also in /usr/local/ ?
Title: Re: How to start a custom script at boot.
Post by: AdSchellevis on March 31, 2015, 12:10:47 pm
The problem with that are the standard rc scripts from ports, they look at /etc/rc.conf (.d/)
We may also include the local variant for custom stuff, but we currently cannot ignore the standard path without extra maintenance on our ports tree...

Or am I missing something? 
Title: Re: How to start a custom script at boot.
Post by: franco on March 31, 2015, 04:28:26 pm
Well, if that is indeed the proper directory for FreeBSD then keep /etc/rc.conf.d :)
Title: Re: [SOLVED] How to start a custom script at boot.
Post by: ortylp on April 03, 2015, 09:06:55 am
I do confirm, that commands issued in /usr/local/etc/rc get executed and the modification survives reboot.

I'll try the proper hook solution as soon as the next update with the commit referenced above comes out.