Writing Init Scripts: Difference between revisions
(Change runscript to openrc-run, add start_stop_daemon_args to example) |
Clandmeter (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
{{Draft}} | {{Draft}} | ||
== Introduction == | |||
Alpine Linux uses the [https://github.com/OpenRC/openrc OpenRC] init system to start services. Don't confuse OpenRC init with out system init (the first process that is executed aka pid 1). Many of the current init.d script found in Alpine Linux are takes from Gentoo. If you want to save time you could search [https://packages.gentoo.org/categories Gentoo's repository] for an existing initscript for your service. You can also check [https://wiki.gentoo.org/wiki/Handbook:X86/Working/Initscripts#Writing_initscripts Gentoo's wiki] for some additional OpenRC information. | |||
If you cannot find an init.d script from Gentoo, or you just want to start to write your own init.d scripts, we provide you with some basic information on how to write simple OpenRC init scripts. | |||
Primary information about the OpenRC format can be found in the [http://manpages.org/openrc-run/8 OpenRC man page openrc-run]. | |||
<code>apk add openrc-doc man</code> | |||
<code>man openrc-run</code> | |||
== Basics == | |||
Every init.d script you write needs to start with a [https://en.wikipedia.org/wiki/Shebang_(Unix) shebang] like: | |||
<code>#!/sbin/openrc-run</code> | |||
== Basic example == | |||
<pre> | <pre> | ||
#!/sbin/openrc-run | |||
command="/usr/ | |||
command_args="-- | name=$RC_SVCNAME | ||
command="/usr/bin/my_daemon" | |||
command_args="--my-daemon-args" | |||
pidfile="/run/$RC_SVCNAME/$RC_SVCNAME.pid" | |||
command_user="my_system_user" | |||
start_stop_daemon_args="--args-for-start-stop-daemon" | start_stop_daemon_args="--args-for-start-stop-daemon" | ||
command_background="yes" | |||
depend() { | |||
need net | |||
} | |||
start_pre() { | |||
checkpath --directory --owner $command_user:$command_user --mode 0775 \ | |||
/run/$RC_SVCNAME /var/log/$RC_SVCNAME | |||
} | |||
</pre> | </pre> | ||
Line 30: | Line 56: | ||
} | } | ||
</pre> | </pre> | ||
[[Category:Booting]] | [[Category:Booting]] |
Revision as of 09:05, 20 May 2017
This material is work-in-progress ... Do not follow instructions here until this notice is removed. |
Introduction
Alpine Linux uses the OpenRC init system to start services. Don't confuse OpenRC init with out system init (the first process that is executed aka pid 1). Many of the current init.d script found in Alpine Linux are takes from Gentoo. If you want to save time you could search Gentoo's repository for an existing initscript for your service. You can also check Gentoo's wiki for some additional OpenRC information.
If you cannot find an init.d script from Gentoo, or you just want to start to write your own init.d scripts, we provide you with some basic information on how to write simple OpenRC init scripts.
Primary information about the OpenRC format can be found in the OpenRC man page openrc-run.
apk add openrc-doc man
man openrc-run
Basics
Every init.d script you write needs to start with a shebang like:
#!/sbin/openrc-run
Basic example
#!/sbin/openrc-run name=$RC_SVCNAME command="/usr/bin/my_daemon" command_args="--my-daemon-args" pidfile="/run/$RC_SVCNAME/$RC_SVCNAME.pid" command_user="my_system_user" start_stop_daemon_args="--args-for-start-stop-daemon" command_background="yes" depend() { need net } start_pre() { checkpath --directory --owner $command_user:$command_user --mode 0775 \ /run/$RC_SVCNAME /var/log/$RC_SVCNAME }
Using start-stop-daemon
To be written
start() { ebegin "Starting mydaemon" start-stop-daemon --start \ --exec /usr/sbin/mydaemon \ --pidfile /var/run/mydaemon.pid \ -- \ --args-for-mydaemon eend $? }