The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.
Difference between revisions of "Openrc"
Line 1: | Line 1: | ||
== Service script == | == Service script == | ||
=== Mini howto === | |||
Let's start to write our openrc service script(<code>/etc/init.d/mydaemon</code>). The first line is: | |||
<pre> | |||
#!/sbin/openrc-run | |||
</pre> | |||
If we use another interpreter, then we may have troubles. | |||
Next we add <code>command</code> variable with our binary full path and the file is as follows: | |||
<pre> | |||
#!/sbin/openrc-run | |||
command="/usr/sbin/mydaemon" | |||
</pre> | |||
That's all. Now our binary specified in <code>command</code> variable can be started with help of start-stop-daemon. | |||
Next add <code>description</code> variable to supply a user some info about the service: | |||
<pre> | |||
description="super essential service" | |||
</pre> | |||
And <code>/etc/init.d/mydaemon describe</code> now shows us: | |||
<pre> | |||
* super essential service | |||
* healthcheck: no description | |||
* unhealthy: no description | |||
* cgroup_cleanup: Kill all processes in the cgroup | |||
</pre> | |||
Great. If our service create a pid file, then we should specify it full path with <code>pidfile</code> variable: | |||
<pre> | |||
pidfile="/var/run/mydaemon.pid" | |||
</pre> | |||
This helps start-stop-daemon to detect an already running instance of mydaemon. | |||
Next add additional arguments for our daemon with help of <code>command_args</code> variable: | |||
<pre> | |||
command_args="-c /etc/mydaemon.conf" | |||
</pre> | |||
=== Extra commands === | === Extra commands === | ||
To add additional commands we must tell openrc about it and define a function with such name: | To add additional commands we must tell openrc about it and define a function with such name: | ||
Line 13: | Line 49: | ||
=== Variables reference === | === Variables reference === | ||
==== We set for openrc ==== | ==== We set for openrc ==== | ||
* <code>command="PATH_TO_BIN"</code> - a full path to binary we want to start/stop. | |||
* <code>command_args="COMMAND LINE ARGUMENTS"</code> - command line arguments for our daemon. | |||
* <code>command_background=true</code> - tell start-stop-daemon to create a pid file and force a daemon into the background by itself. | |||
* <code>description="DESC TEXT"</code> - a text which is outputed on <code>/etc/init.d/SCRIPT describe</code> command. | * <code>description="DESC TEXT"</code> - a text which is outputed on <code>/etc/init.d/SCRIPT describe</code> command. | ||
* <code>description_CMD="CMD DESC TEXT"</code> - a text which is outputed on <code>/etc/init.d/SCRIPT describe</code> command as CMD extra command description. | * <code>description_CMD="CMD DESC TEXT"</code> - a text which is outputed on <code>/etc/init.d/SCRIPT describe</code> command as CMD extra command description. | ||
* <code>extra_commands="cmd1 cmd2 ..."</code> - add specified additional functions to a service script. | * <code>extra_commands="cmd1 cmd2 ..."</code> - add specified additional functions to a service script. | ||
* <code>pidfile="PATH_TO_PID"</code> - a full path to a pid file created by our daemon or start-stop-daemon(see command_background). | |||
==== Openrc set for us ==== | ==== Openrc set for us ==== | ||
* <code>RC_CMD</code> - a command/action name(e.g. start/stop/status/etc). | * <code>RC_CMD</code> - a command/action name(e.g. start/stop/status/etc). | ||
* <code>RC_SVCNAME</code> - a service script name(e.g. mydaemon.local). |
Revision as of 13:38, May 13, 2020
Service script
Mini howto
Let's start to write our openrc service script(/etc/init.d/mydaemon
). The first line is:
#!/sbin/openrc-run
If we use another interpreter, then we may have troubles.
Next we add command
variable with our binary full path and the file is as follows:
#!/sbin/openrc-run command="/usr/sbin/mydaemon"
That's all. Now our binary specified in command
variable can be started with help of start-stop-daemon.
Next add description
variable to supply a user some info about the service:
description="super essential service"
And /etc/init.d/mydaemon describe
now shows us:
* super essential service * healthcheck: no description * unhealthy: no description * cgroup_cleanup: Kill all processes in the cgroup
Great. If our service create a pid file, then we should specify it full path with pidfile
variable:
pidfile="/var/run/mydaemon.pid"
This helps start-stop-daemon to detect an already running instance of mydaemon.
Next add additional arguments for our daemon with help of command_args
variable:
command_args="-c /etc/mydaemon.conf"
Extra commands
To add additional commands we must tell openrc about it and define a function with such name:
extra_commands="cmd1" description_cmd1="do some additional action" cmd1() { ... }
Variables reference
We set for openrc
command="PATH_TO_BIN"
- a full path to binary we want to start/stop.command_args="COMMAND LINE ARGUMENTS"
- command line arguments for our daemon.command_background=true
- tell start-stop-daemon to create a pid file and force a daemon into the background by itself.description="DESC TEXT"
- a text which is outputed on/etc/init.d/SCRIPT describe
command.description_CMD="CMD DESC TEXT"
- a text which is outputed on/etc/init.d/SCRIPT describe
command as CMD extra command description.extra_commands="cmd1 cmd2 ..."
- add specified additional functions to a service script.pidfile="PATH_TO_PID"
- a full path to a pid file created by our daemon or start-stop-daemon(see command_background).
Openrc set for us
RC_CMD
- a command/action name(e.g. start/stop/status/etc).RC_SVCNAME
- a service script name(e.g. mydaemon.local).