Page MenuHomeFreeBSD

Allow rc.d script to provide "status" method without having a procname/PID file
ClosedPublic

Authored by sobomax on Aug 19 2021, 6:00 PM.
Tags
Referenced Files
Unknown Object (File)
Thu, Dec 26, 8:19 PM
Unknown Object (File)
Sat, Dec 7, 7:20 PM
Unknown Object (File)
Thu, Dec 5, 6:11 PM
Unknown Object (File)
Nov 27 2024, 9:30 PM
Unknown Object (File)
Nov 27 2024, 6:21 PM
Unknown Object (File)
Nov 27 2024, 3:19 AM
Unknown Object (File)
Nov 25 2024, 4:23 AM
Unknown Object (File)
Nov 24 2024, 4:43 PM
Subscribers

Details

Summary

Allow rc.d script to provide "status" method, even if it does not have a procname/pid file. This might be useful for other cases, such as mounting local FS, configuring loopback etc, when there is no running daemon still some other persistent state in the system whose status can be checked.

Test Plan

Consider this script in the /usr/local/etc/rc.d/foo:

#!/bin/sh

# PROVIDE: foo
# REQUIRE: tmp

. /etc/rc.subr

name="foo"
rcvar="${name}_enable"
desc="Configure foo"
start_cmd="enable_foo"
status_cmd="foo_status"

stop_cmd=':'

enable_foo()
{
        touch /tmp/foo
}

foo_status()
{
        if [ -f /tmp/foo ]
        then
                return 0
        fi
        return 1
}

load_rc_config $name
run_rc_command "$1"

Without this patch attempt to do "service foo onestatus" gives me:

$ service foo onestatus
/usr/local/etc/rc.d/foo: unknown directive 'status'.
Usage: /usr/local/etc/rc.d/foo [fast|force|one|quiet](start|stop|restart|rcvar|enabled|describe|extracommands)

After applying this patch:

$ service foo onestatus || echo 'foo is down!'
foo is down!

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sobomax created this revision.
sobomax retitled this revision from Allow rc.d script to provide "status" method without having a PID file to Allow rc.d script to provide "status" method without having a procname/PID file.Aug 19 2021, 6:05 PM
sobomax edited the summary of this revision. (Show Details)
sobomax added a reviewer: Src Committers.

Good idea.

When committing we should include relnotes.

This revision is now accepted and ready to land.Aug 19 2021, 6:30 PM
sobomax added a project: rc.

I like the overall intention, however the example provided can be accomplished without any patch with:

#!/bin/sh

# PROVIDE: foo
# REQUIRE: tmp

. /etc/rc.subr

name="foo"
rcvar="${name}_enable"
desc="Configure foo"
load_rc_config $name

start_cmd="${name}_start"
stop_cmd=':'

extra_commands="status"
status_cmd="${name}_status"

foo_start()
{
	touch /tmp/foo
}

foo_status()
{
	if [ -f /tmp/foo ]; then
		echo "foo is running."
		return 0
	fi
	echo "foo is down!"
	return 1
}

run_rc_command "$1"

Reading the usage message, I wonder if status, poll, and reload should also be added to the list?

Usage: /usr/local/etc/rc.d/foo [fast|force|one|quiet](start|stop|reload|restart|status|poll|rcvar|enabled|describe|extracommands)

Maybe, I should ask the doc team. Thank you!