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.
Details
Details
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
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
Comment Actions
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"
Comment Actions
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!