Actually you can set variables like you did in
/etc/rc.conf.local, but then you have to use them in the
/etc/rc.local.
The
/etc/rc script uses the following to decide whether to start
sshd and with which options:
Code:
echo -n starting network daemons:
if [ X"${sshd_flags}" != X"NO" ]; then
echo -n ' sshd'; /usr/sbin/sshd ${sshd_flags};
fi
If you use something similar in
/etc/rc.local you can use your
proftpd and
proftpd_flags variables in
/etc/rc.conf.local to start or not to start
proftpd in the
/etc/rc.local script.
For a test I created a stripped down version of the
rc script, which does not start up any daemons, but does only the following:
- Reads or includes the variable assignments from /etc/rc.conf.
Note that this file will include the variable assignments from /etc/rc.conf.local
Code:
$ tail -3 /etc/rc.conf
local_rcconf="/etc/rc.conf.local"
[ -f ${local_rcconf} ] && . ${local_rcconf} # Do not edit this line
- Includes the /etc/rc.local script
The stripped down version
Code:
# example rc file
echo
echo "$0: Source/include the variable assignments from \"/etc/rc.conf\""
echo " and \"/etc/rc.conf.local\" with the shell \".\" dot operator"
# grep -n rc.conf /etc/rc
# 248:. /etc/rc.conf
. /etc/rc.conf
echo
echo $0: Source/include the \"/etc/rc.local\" script with the shell \".\" dot operator
echo
# grep -n rc.local /etc/rc
# 789:[ -f /etc/rc.local ] && . /etc/rc.local
[ -f /etc/rc.local ] && . /etc/rc.local
For simplicity sake I did not "include" the
/etc/rc.securelevel which allows you to start things before the securelevel changes.
I placed this simplified
rc file in a subdirectory
temp in my home directory together with a simple test script called
myprogram
Code:
$ pwd ; ls -l
/home/j65nko/temp
-rwxr-xr-x 1 j65nko j65nko 61 Feb 27 23:07 myprogram
-rwxr-xr-x 1 j65nko j65nko 459 Feb 28 00:09 rc
$ cat myprogram
#!/bin/sh
cat <<END
This is my program
My options: $@
END
As you can see this
myprogram script just prints a message and the displays the options passed to it. An example
Code:
$ myprogram clinton obama
This is my program
My options: clinton obama
To control
myprogram I added the following to the real
/etc/rc.conf.local:
Code:
myprogram="YES"
myprogram_flags="-s -p -x"
The real
/etc/rc.local script uses these variables as follows
Code:
# $OpenBSD: rc.local,v 1.39 2006/07/28 20:19:46 sturm Exp $
# Site-specific startup actions, daemons, and other things which
# can be done AFTER your system goes into securemode. For actions
# which should be done BEFORE your system has gone into securemode
# please see /etc/rc.securelevel.
echo -n 'starting local daemons:'
# Add your local startup actions here.
cat <<END
Displaying 'myprogram' variables :
===================================
$(set | grep myprogram)
==================================
END
if [ X"${myprogram}" != X"NO" ] ; then
echo -n " myprogram" ; /home/j65nko/temp/myprogram ${myprogram_flags}
fi
echo '.'
First task is just for diagnostics.The shell
set command prints all variables. Because this list is quite long, I used grep to filter out the ones having
myprogram in it.
The actual work is done in a similar way like the real "rc" starts up sshd.
- if myprogram is not set to "NO", then display the name of the program
- Invoke /home/j65nko/temp/myprogram and pass it the flags or options as set by the myprogram_flags variable.
Running the stripped version of
rc in this temp directory:
Code:
$ ./rc
./rc: Source/include the variable assignments from "/etc/rc.conf"
and "/etc/rc.conf.local" with the shell "." dot operator
./rc: Source/include the "/etc/rc.local" script with the shell "." dot operator
starting local daemons:
Displaying 'myprogram' variables :
===================================
myprogram=
myprogram_flags='-s -p -x'
==================================
myprogram
This is my program
My options: -s -p -x
.
Conclusion:
You can use your own daemon controlling variables in
/etc/rc.conf.local which are not supported in the standard
/etc/rc script.
To use these custom variables you have to write some some simple code in
/etc/rc.local which uses them. Read the real
/etc/rc script. to find inspiration.