Skip to content

Commit d7d1286

Browse files
committed
operations.server: list BSD variants explicitly in server.service
Replace the "not Linux" guard with an explicit (FreeBSD, OpenBSD, NetBSD, DragonFly) set so the bsdinit branch only matches known BSDs rather than every non-Linux host that happens to expose /etc/rc.d. NetBSD behaves like FreeBSD (ships service(8)), so add a fixture to cover that path.
1 parent 446387e commit d7d1286

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

src/pyinfra/operations/server.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -572,12 +572,15 @@ def service(
572572
elif host.get_fact(Which, command="sv"):
573573
service_operation = runit.service
574574

575-
# NOTE: important that we are not Linux here because /etc/rc.d will exist but checking it's
576-
# contents may trigger things (like a reboot: https://github.com/Fizzadar/pyinfra/issues/819).
577-
# Must also run before the sysvinit check: BSDs ship `service` in base (distinct from the
578-
# Linux sysvinit wrapper), so matching on Which command="service" first would misroute FreeBSD
575+
# NOTE: must run before the sysvinit check: BSDs ship `service` in base (distinct from the
576+
# Linux sysvinit wrapper), so matching on Which command="service" first would misroute BSD
579577
# hosts to sysvinit. See https://github.com/pyinfra-dev/pyinfra/issues/1496.
580-
elif host.get_fact(Os) != "Linux" and bool(host.get_fact(Directory, path="/etc/rc.d")):
578+
# The OS list is explicit (rather than "not Linux") so other /etc/rc.d-having systems are not
579+
# accidentally routed through bsdinit; see https://github.com/Fizzadar/pyinfra/issues/819 for
580+
# the original motivation to exclude Linux here.
581+
elif host.get_fact(Os) in ("FreeBSD", "OpenBSD", "NetBSD", "DragonFly") and bool(
582+
host.get_fact(Directory, path="/etc/rc.d")
583+
):
581584
service_operation = bsdinit.service
582585

583586
elif (
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"args": ["nginx"],
3+
"facts": {
4+
"server.Os": "NetBSD",
5+
"bsdinit.RcdStatus": {
6+
"nginx": false
7+
},
8+
"server.Which": {
9+
"command=systemctl": false,
10+
"command=initctl": false,
11+
"command=rc-service": false,
12+
"command=sv": false,
13+
"command=service": "/usr/sbin/service"
14+
},
15+
"files.Directory": {
16+
"path=/etc/init.d": false,
17+
"path=/etc/rc.d": true
18+
},
19+
"files.Link": {
20+
"path=/etc/init.d": false
21+
}
22+
},
23+
"commands": [
24+
"test -e /etc/rc.d/nginx && /etc/rc.d/nginx start || /usr/local/etc/rc.d/nginx start"
25+
]
26+
}

0 commit comments

Comments
 (0)