Home
Help
Search
Login
Register
OPNsense Forum
»
Archive
»
15.1 Legacy Series
»
[SOLVED] How to start a custom script at boot.
« previous
next »
Print
Pages: [
1
]
Author
Topic: [SOLVED] How to start a custom script at boot. (Read 28866 times)
ortylp
Newbie
Posts: 3
Karma: 1
[SOLVED] How to start a custom script at boot.
«
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.
«
Last Edit: April 01, 2015, 04:13:24 pm by franco
»
Logged
franco
Administrator
Hero Member
Posts: 17656
Karma: 1610
Re: How to start a custom script at boot.
«
Reply #1 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?
Logged
AdSchellevis
Administrator
Hero Member
Posts: 907
Karma: 184
Re: How to start a custom script at boot.
«
Reply #2 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
Logged
franco
Administrator
Hero Member
Posts: 17656
Karma: 1610
Re: How to start a custom script at boot.
«
Reply #3 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/ ?
Logged
AdSchellevis
Administrator
Hero Member
Posts: 907
Karma: 184
Re: How to start a custom script at boot.
«
Reply #4 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?
Logged
franco
Administrator
Hero Member
Posts: 17656
Karma: 1610
Re: How to start a custom script at boot.
«
Reply #5 on:
March 31, 2015, 04:28:26 pm »
Well, if that is indeed the proper directory for FreeBSD then keep /etc/rc.conf.d
Logged
ortylp
Newbie
Posts: 3
Karma: 1
Re: [SOLVED] How to start a custom script at boot.
«
Reply #6 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.
«
Last Edit: April 04, 2015, 05:13:35 pm by ortylp
»
Logged
Print
Pages: [
1
]
« previous
next »
OPNsense Forum
»
Archive
»
15.1 Legacy Series
»
[SOLVED] How to start a custom script at boot.