From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 50A951396DA for ; Wed, 25 Oct 2017 20:10:51 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 97E132BC03A; Wed, 25 Oct 2017 20:10:50 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 770502BC03A for ; Wed, 25 Oct 2017 20:10:50 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6194C33C4EE for ; Wed, 25 Oct 2017 20:10:49 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id C66818F9D for ; Wed, 25 Oct 2017 20:10:47 +0000 (UTC) From: "William Hubbs" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "William Hubbs" Message-ID: <1508962182.a428c325a902bba55a849a07a59c0c1567404db2.williamh@OpenRC> Subject: [gentoo-commits] proj/openrc:master commit in: sh/ X-VCS-Repository: proj/openrc X-VCS-Files: sh/supervise-daemon.sh X-VCS-Directories: sh/ X-VCS-Committer: williamh X-VCS-Committer-Name: William Hubbs X-VCS-Revision: a428c325a902bba55a849a07a59c0c1567404db2 X-VCS-Branch: master Date: Wed, 25 Oct 2017 20:10:47 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 87060abe-0a62-4601-815a-1f3cd9010dd4 X-Archives-Hash: 14803a348e2d8847231c35389293cd66 commit: a428c325a902bba55a849a07a59c0c1567404db2 Author: William Hubbs gmail com> AuthorDate: Wed Oct 25 20:07:19 2017 +0000 Commit: William Hubbs gentoo org> CommitDate: Wed Oct 25 20:09:42 2017 +0000 URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a428c325 add "unsupervised" status and return code 64 to supervise-daemon status function This is to be used if the service is being supervised and the supervisor is somehow killed. Currently, this is very linux specific, but I will expand to other platforms, patches are welcome. sh/supervise-daemon.sh | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh index 1c1b840d..bccfd06a 100644 --- a/sh/supervise-daemon.sh +++ b/sh/supervise-daemon.sh @@ -56,7 +56,50 @@ supervise_stop() eend $? "Failed to stop ${name:-$RC_SVCNAME}" } +_check_supervised() +{ + [ "$RC_UNAME" != Linux ] && return 0 + local child_pid="$(service_get_value "child_pid")" + local pid="$(cat ${pidfile})" + if [ -n "${child_pid}" ]; then + if ! [ -e "/proc/${pid}" ] && [ -e "/proc/${child_pid}" ]; then + if [ -e "/proc/self/ns/pid" ] && [ -e "/proc/${child_pid}/ns/pid" ]; then + local n1 n2 + n1=$(readlink "/proc/self/ns/pid") + n2=$(readlink "/proc/${child_pid}/ns/pid") + if [ "${n1}" = "${n2}" ]; then + return 1 + fi + fi + fi + fi + return 0 +} + supervise_status() { - _status + if service_stopping; then + ewarn "status: stopping" + return 4 + elif service_starting; then + ewarn "status: starting" + return 8 + elif service_inactive; then + ewarn "status: inactive" + return 16 + elif service_started; then + if service_crashed; then + if ! _check_supervised; then + eerror "status: unsupervised" + return 64 + fi + eerror "status: crashed" + return 32 + fi + einfo "status: started" + return 0 + else + einfo "status: stopped" + return 3 + fi }