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)
Mon, Apr 1, 1:13 PM
Unknown Object (File)
Mar 16 2024, 9:40 AM
Unknown Object (File)
Mar 7 2024, 11:49 PM
Unknown Object (File)
Feb 10 2024, 10:49 PM
Unknown Object (File)
Jan 27 2024, 2:43 AM
Unknown Object (File)
Jan 12 2024, 4:52 PM
Unknown Object (File)
Dec 25 2023, 2:03 AM
Unknown Object (File)
Dec 21 2023, 7:54 PM

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!