Skip to content

Commit be6f881

Browse files
committed
Fix rc.d script to properly load configuration and start on boot
Previous: The rc.d/spkrd service script had rcorder comments at the top of the file but was not functioning correctly during boot. The load_rc_config call appeared after command_args was defined, which meant any spkrd_flags configured in /etc/rc.conf were not available when constructing the command line arguments. The script structure did not follow FreeBSD rc.d best practices for variable initialization order. Changed: Relocated rcorder comments (PROVIDE, REQUIRE, KEYWORD) to appear after the explanatory header section while remaining parseable by rcorder. Moved load_rc_config call to execute immediately after basic variable setup and before command definition, ensuring spkrd_flags from /etc/rc.conf is available. Added explicit default value for spkrd_enable using the ${var:="default"} pattern following FreeBSD conventions. Removed trailing whitespace in device path comment line. See: changelog/20251013-rc-script-boot-issue.md
1 parent 5eae006 commit be6f881

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# RC Script Boot Issue Investigation
2+
3+
## Task Specification
4+
User reported that the spkrd daemon was not starting on boot with the provided rc.d script. They manually added rcorder comments and want verification that the script is now correct.
5+
6+
## Initial Analysis
7+
The rc.d script now includes rcorder comments:
8+
- `PROVIDE: spkrd`
9+
- `REQUIRE: DAEMON`
10+
- `KEYWORD: shutdown`
11+
12+
## Files to Review
13+
- `rc.d/spkrd`: FreeBSD service script
14+
15+
## Current Status
16+
- Examining script for correctness
17+
- Need to verify rcorder comments are appropriate
18+
- Check for other potential boot startup issues
19+
20+
## Issues Found
21+
1. **Variable loading order**: `load_rc_config` called after `command_args` definition, preventing `spkrd_flags` from being properly loaded from `/etc/rc.conf`
22+
2. **rcorder comment placement**: User prefers rcorder comments after the explanatory header comment
23+
24+
## Implementation Plan
25+
26+
### Fix 1: Correct Variable Loading Order
27+
Move `load_rc_config $name` to execute before `command_args` is set. Standard pattern:
28+
```sh
29+
. /etc/rc.subr
30+
name=spkrd
31+
rcvar=spkrd_enable
32+
load_rc_config $name # Load user config first
33+
# Then set defaults and use variables
34+
```
35+
36+
### Fix 2: Move rcorder Comments
37+
Place `PROVIDE`/`REQUIRE`/`KEYWORD` comments after the explanatory header block. This is supported by FreeBSD - rcorder scans the entire file for these special comments, they don't need to be at the top.
38+
39+
## Changes Applied
40+
- Moved rcorder comments (lines 3-5) to after explanatory header (after line 34)
41+
- Moved `load_rc_config $name` to before `command` and `command_args` definitions
42+
- Added `: ${spkrd_enable:="NO"}` default for cleaner rc.conf integration

rc.d/spkrd

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#
1010
# Available flags:
1111
# --port <port> Server port (default: 1111)
12-
# --device <path> Speaker device path (default: /dev/speaker)
12+
# --device <path> Speaker device path (default: /dev/speaker)
1313
# --retry-timeout <secs> Device retry timeout (default: 30)
1414
# --daemon Run as daemon (automatically added by rc.d)
1515
# --pidfile <path> PID file path (default: /var/run/spkrd.pid)
@@ -29,15 +29,22 @@
2929
# - View logs: tail -f /var/log/daemon.log | grep spkrd
3030
# - Non-root users: Use custom --pidfile (e.g., /tmp/spkrd.pid)
3131

32+
# PROVIDE: spkrd
33+
# REQUIRE: DAEMON
34+
# KEYWORD: shutdown
35+
3236
. /etc/rc.subr
3337

3438
name=spkrd
3539
rcvar=spkrd_enable
3640

41+
load_rc_config $name
42+
43+
: ${spkrd_enable:="NO"}
44+
3745
command="/usr/local/bin/${name}"
3846
pidfile="/var/run/${name}.pid"
3947
command_args="--daemon --pidfile ${pidfile} ${spkrd_flags}"
4048
required_files="/usr/local/bin/${name}"
4149

42-
load_rc_config $name
4350
run_rc_command "$1"

0 commit comments

Comments
 (0)