DIR << back
Restarting updated services on OpenBSD
======================================
On my OpenBSD boxes I regularly use the `sysutils/checkrestart` port after
updating my machines.
For quite some time I have been using scripts which just run a line like the
following for each and every service I am using on that host:
```bash
[...]
checkrestart | grep node_exporter && rcctl restart node_exporter
[...]
```
This has proved to be quite inefficient, and annoying to maintain over time.
So I replaced it with the following simple script:
```bash
#!/bin/sh
cbinaries="$(checkrestart | cut -f 2)"
for sfile in /etc/rc.d/*; do
sname="$(basename $sfile)"
[ "$sname" = "rc.subr" ] && continue
dfile="$(awk -F'=' '/daemon=/{gsub(/"/, "", $2); print $2}' "$sfile")"
dcommand="$(echo $dfile | cut -d " " -f 1)"
dbinary="$(basename $dcommand)"
for binary in "$cbinaries"; do
if echo "$cbinaries" | grep -q "$dbinary" > /dev/null; then
echo "Restarting $sname due to changed binary: $daemon ..."
rcctl restart "$sname"
break
fi
done
done
```
Finally something simple, I can automatically deploy to all my OpenBSD machines,
and regularily run, to automatically restart all updated services, independent
of the enabled services on that host (like needrestart on Linux).
---------------------------------------------------------------=|
powered by openbsd & geomyidae(8) | accessible via tls & tor
(c) 2016-2025 drkhsh. CC BY-NC-SA 4.0