MESSAGE
DATE | 2015-11-04 |
FROM | ruben safir
|
SUBJECT | Subject: [Hangout-NYLXS] openrc tips
|
http://www.libregeek.org/2014/02/11/creating-startup-init-script-openrc/
Creating a Startup init Script For OpenRC
Even though OpenRC init scripts use the “init.d” type implementation, I still wanted to break this how to into a separate article. The guide will detail the bare basics of init implementation with OpenRC. Specification and Comparison
The OpenRC system does not support script-specific restart functionality. Instead, the script needs to check the contents of the RC_CMD variable to see if a function (be it start() or stop()) is called as part of a restart or not.
It is very important to start your script with the proper environment. The OpenRC script needs to start with “#!/sbin/runscript”, as seen below Overview of Run Levels
OpenRC uses run levels just like sysV, and in similar practice to how systemd uses single user and multi user “targets.” Below is a table and explanation of each level (click image to enlarge): Screenshot from 2014-02-11 13:10:48 Creating your OpenRC init script
OpenRC uses simple scripts to enable an uncomplicated method of implementation. Below is a code template that outlines a basic OpenRC init script. FOO is a common “general” place holder for whichever program you are trying to implement.
[code language=”bash” collapse=”true”]#!/sbin/runscript # # Start ddclient that provides support for updating dynamic DNS services. #
depend() { need net use dns logger }
start() { DDCLIENT="/usr/sbin/ddclient" CONF="/etc/ddclient/ddclient.conf" PIDFILE="/var/run/ddclient.pid"
test -x $DDCLIENT || exit 0 test -f $CONF || exit 0 ebegin "Starting ddclient…"
start-stop-daemon –start –quiet –pidfile $PIDFILE –exec $DDCLIENT –chdir /etc/ddclient — -file $CONF
eend $? }
stop() { ebegin "Stopping ddclient…"
start-stop-daemon –stop –quiet –pidfile $PIDFILE –retry SIGTERM/10
eend $?
}
[/code] Implementing the script
What I do like about OpenRC’s init scripts, is how easy it is to implement them. All of the OpenRC init scripts are stored in either the “/etc/rc.d/init.d/” directory, or the “/etc/init.d” directory. These scripts are used to control system startup and shutdown, in contrast to “startup applications” that are in user space, and not part of the system startup at boot time.
An example of this is the CUPS system daemon: /etc/init.d/httpd start 1 /etc/init.d/httpd start
The first line will start the service, but will not persist on boot up until you update your init scripts (see below).
Update your init scripts
When you are finished implementing the script into the system, be sure to update the init scripts that load on boot up: update-rc.d 1 update-rc.d
Summary
That should be all that is needed to get you on the road to making your own init scripts for OpenRC init systems.
Enjoy,
-mikeyd
Sources: http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&chap=4&style=printable http://wiki.alpinelinux.org/wiki/Writing_Init_Scripts
_______________________________________________ hangout mailing list hangout-at-nylxs.com http://www.nylxs.com/ |
|