OpenRC runscript is an actively used application created in 2007. OpenRC is basically an interpreter for shell scripts which provides an easy interface to the often complex system commands and daemons. When a service runs a command it first loads its multiplexed configuration file, then its master configuration file, then /etc/rc.conf and finally the script itself. At this point then runs the command given.

13Years Old ?Users ?Jobs
  • OpenRC runscript first appeared in 2007
  • Have a question about OpenRC runscript not answered here? Email me and let me know how I can help.

Example code from the web:

command_args="${foo_args} --bar"
name="FooBar Daemon"

description="FooBar is a daemon that eats and drinks"
extra_started_commands="drink eat"
description_drink="Opens mouth and reflexively swallows"
description_eat="Chews food in mouth"
description_show="Shows what's in the tummy"

    grep -q dbus /etc/foo/plugins

    # We write a pidfile and to /var/cache, so we need localmount.
    need localmount
    # We can optionally use the network, but it's not essential.
    use net
    # We should be after bootmisc so that /var/run is cleaned before
    # we put our pidfile there.
    after bootmisc

    # Foo may use a dbus plugin.
    # However, if we add the dbus plugin whilst foo is running and
    # stop dbus, we don't need to stop foo as foo didn't use dbus.
    config /etc/foo/plugins
    local _need=
    if service_started; then
        _need=`service_get_value need`
        if _need_dbus; then
           _need="${_need} dbus"
    need ${_need}

# This function does any pre-start setup. If it fails, the service will
# not be started.
# If you need this function to behave differently for a restart command,
# you should check the value of RC_CMD for "restart".
# This also applies to start_post, stop_pre and stop_post.
        if [ "$RC_CMD" = restart ]; then
                # This block will only execute for a restart command. Use a
                # structure like this if you need special processing for a
                # restart which you do not need for a normal start.
                # The function can also fail from here, which will mean that a
                # restart can fail.
                # This logic can also be used in start_post, stop_pre and
                # stop_post.
    # Ensure that our dirs are correct
    checkpath --directory --owner foo:foo --mode 0775 \
        /var/run/foo /var/cache/foo

    # Save our need
    if _need_dbus; then
        service_set_value need dbus

stop_post() {
    # Clean any spills
    rm -rf /var/cache/foo/*

    ebegin "Starting to drink"
    ${command} --drink beer
    eend $? "Failed to drink any beer :("

    local result=0 retval= ate= food=
    ebegin "Starting to eat"

    if yesno "${foo_diet}"; then
        eend 1 "We are on a diet!"
        return 1

    for food in /usr/share/food/*; do
        veinfo "Eating `basename ${food}`"
        ${command} --eat ${food}
        : $(( result += retval ))
        [ ${retval} = 0 ] && ate="${ate} `basename ${food}`"

    if eend ${result} "Failed to eat all the food"; then
        service_set_value ate "${ate}"

    einfo "Foo has eaten: `service_get_value ate`"

Example code from Linguist:


description="Daemon for Advanced Configuration and Power Interface"


depend() {
	need localmount
	use logger

reload() {
	ebegin "Reloading acpid configuration"
	start-stop-daemon --exec $command --signal HUP
	eend $?

Trending Repos

repo stars description

Last updated January 18th, 2020

Edit OpenRC runscript on GitHub