Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rc-status lists service as crashed while rc-service <service> status lists the service as started? #215

Open
walterjwhite opened this issue Mar 10, 2018 · 6 comments

Comments

@walterjwhite
Copy link

walterjwhite commented Mar 10, 2018

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:

#!/sbin/openrc-run
# Copyright 1999-2018 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'
		mark_service_started "${SVCNAME}"
		return 0
	else
		einfo 'status: stopped'	
		mark_service_stopped "${SVCNAME}"
		return 3
	fi
}

@williamh
Copy link
Contributor

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 mark_service_* at all. The purpose of the status function is to report status, not change it.

@walterjwhite
Copy link
Author

Thanks for the feedback, I will give that a try.

@walterjwhite
Copy link
Author

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.

@williamh
Copy link
Contributor

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.

@dwfreed
Copy link
Contributor

dwfreed commented Mar 21, 2018

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.

@walterjwhite
Copy link
Author

  1. Yes, broctl start / stop return 0 if it was successful, otherwise, 1 (at least from the little testing I've performed).

  2. 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants