Open walterjwhite opened 6 years ago
It looks to me like you don't need to use start-stop-daemon for this. Try dropping those calls. Also, please use the ${RC_SVCNAME} variable, not ${SVCNAME}. Also, in your status() function, do not call markservice* at all. The purpose of the status function is to report status, not change it.
Thanks for the feedback, I will give that a try.
I gave it a try and am having the same problem:
#!/sbin/openrc-run
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$
depend() {
need net
}
start() {
ebegin "Starting bro"
mkdir -p /var/log/bro
#start-stop-daemon --start --quiet -n bro --exec
/usr/bin/broctl start
eend $?
}
stop() {
ebegin "Stopping bro"
#start-stop-daemon --start --quiet -n bro --exec
/usr/bin/broctl stop
eend $?
}
status() {
local _retval
/usr/bin/broctl status>/dev/null
_retval=$?
if [ ${_retval} = '0' ]; then
einfo 'status: started'
return 0
else
einfo 'status: stopped'
return 3
fi
}
Let me know if this is something that should be easily answered by reading the documentation. I am new to openrc scripts, so I any direction is much appreciated.
In your start() and stop() functions, you are trusting that "broctl start" and "broctl stop" return 0 if bro is started or stopped successfully. Please verify that this is true, and if it is not, make the start() and stop() functions return 0 if bro is started or stopped successfully.
rc-status does not call initscripts at all, so your status function is completely ignored. It only shows the state openrc thinks the service should be in, assuming no outside forces (except for crashed, which depends on something like start-stop-daemon to set the appropriate information). rc-service, on the other hand, just calls the initscript, which runs your provided status function. If no status function is provided, the default function matches the behavior of rc-status.
Yes, broctl start / stop return 0 if it was successful, otherwise, 1 (at least from the little testing I've performed).
Ok, understood - so, in the case that rc-service differs from rc-status, will that update rc-service then? Shouldn't it as it is information was readily available?
I am in the process of exploring supervise-daemon, and while troubleshooting a different problem I also noticed this for services I have not yet looked at, namely syslog and chronyd. However, the variance actually is noticeable with rc-status
, and rc-service servicename status
indicating started, while rc-status -c
indicates crashed.
They have the following service definitions:
Chronyd
#!/sbin/openrc-run
command="/usr/sbin/chronyd"
description="NTP daemon"
pidfile="/run/chrony/chronyd.pid"
required_files="$CFGFILE"
command_args="-f $CFGFILE $ARGS"
depend() {
need net
after firewall
provide ntp-client ntp-server
use dns
}
start() {
if [ -c /dev/rtc ]; then
grep -q '^rtcfile' "${CFGFILE}" && command_args="$command_args -s"
fi
grep -q '^dumponexit$' "${CFGFILE}" && command_args="$command_args -r"
if yesno "$FAST_STARTUP"; then
# this option makes it stay in foreground and let openrc do the tracking,
# so we have to set pidfile to a dir that exists earlier.
# the reason this is not the default is because there is no 'readiness',
# self-backgrounding chrony waits for time to sync before continuing,
# and this form does not.
command_args="$command_args -n"
command_background=true
pidfile=/run/chronyd.pid
fi
default_start
}
Syslog:
#!/sbin/openrc-run
description="Message logging system"
name="busybox syslog"
command="/sbin/syslogd"
command_args="${SYSLOGD_OPTS} -n"
pidfile="/run/syslogd.pid"
command_background=true
start_stop_daemon_args="-g wheel -k 027"
depend() {
need clock hostname localmount
provide logger
}
rc-status -c
shows:
syslog
chronyd
rc-status
shows:
Runlevel: default
chronyd [ started ]
Runlevel: boot
syslog [ started ]
rc-service servicename status
for both shows:
* status: started
I noticed there is a discrepancy between rc-status and rc-service for a particular service. rc-service lists the service as crashed whereas invoking rc-service status indicates the service is running.
The implementation of rc-status and rc-service must be different.
The service in question is bro and I provided my own init script: