summaryrefslogtreecommitdiff
path: root/etc/rc.d/rc.subr
diff options
context:
space:
mode:
authorAntoine Jacoutot <ajacoutot@cvs.openbsd.org>2021-02-27 09:28:06 +0000
committerAntoine Jacoutot <ajacoutot@cvs.openbsd.org>2021-02-27 09:28:06 +0000
commite87888bbc6d880bd9e8488740f852479d12f79a1 (patch)
tree934f9de5d275631b1ca750daee8df42856af3af4 /etc/rc.d/rc.subr
parent3dec16227ba0ce2c6e4474d16e8e12a633515148 (diff)
Add logger(1) support for daemons that are logging to stdout/stderr (mostly from
the go ecosystem). Properly handle failing daemon startup now that we have pipefail. To take advantage of this new feature, just add foo_logger=facility to the daemon rc.d(8) script or in rc.conf.local(8) or use rcctl: rcctl set foo logger daemon.info tweak for checking flags in rcctl(8) from martijn@ "this looks pretty good" deraadt@ ok sthen@
Diffstat (limited to 'etc/rc.d/rc.subr')
-rw-r--r--etc/rc.d/rc.subr14
1 files changed, 9 insertions, 5 deletions
diff --git a/etc/rc.d/rc.subr b/etc/rc.d/rc.subr
index 0268e0a9722..5bd7ba3f2c0 100644
--- a/etc/rc.d/rc.subr
+++ b/etc/rc.d/rc.subr
@@ -1,6 +1,6 @@
-# $OpenBSD: rc.subr,v 1.135 2020/07/12 14:35:38 jca Exp $
+# $OpenBSD: rc.subr,v 1.136 2021/02/27 09:28:04 ajacoutot Exp $
#
-# Copyright (c) 2010, 2011, 2014-2017 Antoine Jacoutot <ajacoutot@openbsd.org>
+# Copyright (c) 2010, 2011, 2014-2021 Antoine Jacoutot <ajacoutot@openbsd.org>
# Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
# Copyright (c) 2010, 2011, 2014 Robert Nagy <robert@openbsd.org>
#
@@ -49,6 +49,7 @@ _rc_write_runfile() {
cat >${_RC_RUNFILE} <<EOF
daemon_class=${daemon_class}
daemon_flags=${daemon_flags}
+daemon_logger=${daemon_logger}
daemon_rtable=${daemon_rtable}
daemon_timeout=${daemon_timeout}
daemon_user=${daemon_user}
@@ -149,7 +150,7 @@ _rc_parse_conf() {
while IFS=' ' read -r _l; do
[[ $_l == [!#=]*=* ]] || continue
_key=${_l%%*([[:blank:]])=*}
- [[ $_key == *_@(flags|rtable|timeout|user) ]] ||
+ [[ $_key == *_@(flags|logger|rtable|timeout|user) ]] ||
[[ " ${_allowed_keys[*]} " == *" $_key "* ]] ||
continue
[[ $_key == "" ]] && continue
@@ -170,7 +171,8 @@ _rc_parse_conf() {
[ -n "${FUNCS_ONLY}" ] && return
rc_start() {
- ${rcexec} "${daemon} ${daemon_flags}"
+ ${rcexec} "${daemon_logger:+set -o pipefail; }${daemon} ${daemon_flags}${daemon_logger:+ 2>&1 |
+ logger -ip ${daemon_logger} -t ${_name}}"
}
rc_check() {
@@ -288,6 +290,7 @@ _RC_RUNFILE=${_RC_RUNDIR}/${_name}
_rc_do _rc_parse_conf
eval _rcflags=\${${_name}_flags}
+eval _rclogger=\${${_name}_logger}
eval _rcrtable=\${${_name}_rtable}
eval _rctimeout=\${${_name}_timeout}
eval _rcuser=\${${_name}_user}
@@ -304,6 +307,7 @@ getcap -f /etc/login.conf ${_name} 1>/dev/null 2>&1 && daemon_class=${_name} ||
unset _rcflags
[ -n "${_rcflags}" ] && daemon_flags=${_rcflags}
+[ -n "${_rclogger}" ] && daemon_logger=${_rclogger}
[ -n "${_rcrtable}" ] && daemon_rtable=${_rcrtable}
[ -n "${_rctimeout}" ] && daemon_timeout=${_rctimeout}
[ -n "${_rcuser}" ] && daemon_user=${_rcuser}
@@ -315,7 +319,7 @@ if [ -n "${_RC_DEBUG}" ]; then
fi
readonly daemon_class
-unset _rcflags _rcrtable _rctimeout _rcuser
+unset _rcflags _rclogger _rcrtable _rctimeout _rcuser
# the shell will strip the quotes from daemon_flags when starting a daemon;
# make sure pexp matches the process (i.e. doesn't include the quotes)
pexp="$(eval echo ${daemon}${daemon_flags:+ ${daemon_flags}})"