From patchwork Mon Apr 13 11:16:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stan Grishin X-Patchwork-Id: 1269777 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=melmac.net Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=PTi6dyBk; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=melmac.net header.i=@melmac.net header.a=rsa-sha256 header.s=google header.b=UejwtGul; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4915fp5RMmz9sSb for ; Mon, 13 Apr 2020 21:16:50 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:To:Message-ID:Date:From:MIME-Version:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=lh1W4S3dp3Rbni3QbO6Wk1OsBfLANHY6mA3o7Ld1HeQ=; b=PTi 6dyBkWR3aUm24NJ1teAdjHp6SIygOn+2swvJo6VHpw7F9ZTth80mPL1h4AM57SBdMzOvOw0vZvVb9 1KEhdPn0gi758jIpWFXel+LlOlCmx/KwLQI24CLhxg/Cdw5X6jOiqOqcoFUSObpWI3tPD9UJkDSuI +9gSBxvWL2YZUdayczDJWoTGuyoeSv3bSk7nnGwcA6sbC0N6IDREUEgOV3rJPFbjTwb27QbHNHlPq iGMsbZ8vOhOGgHJu7Y8IUUTfh3UjCb8/fXrZKbYmKPFeDMkGg4p9J8bnQ6V26dpZtj/ODOb1mKj3I M3/2JRKPh/iHT2W1UekbXhXJWDGgJyw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jNx4z-00084h-Tl; Mon, 13 Apr 2020 11:16:41 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jNx4x-000848-Hg for openwrt-devel@lists.openwrt.org; Mon, 13 Apr 2020 11:16:41 +0000 Received: by mail-wr1-x42e.google.com with SMTP id a25so9775147wrd.0 for ; Mon, 13 Apr 2020 04:16:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=melmac.net; s=google; h=mime-version:from:date:message-id:subject:to; bh=bbbC1wfdodVsUufVEvRB0eZfNfU9+0M+mINBVeWC5as=; b=UejwtGuli2I3JeddLTvBmhSC0jBzwlaNQCrfNFCdiuuDenrJENr6k+jYnH1qBrkEVa 7v6kiry7Vv+CYenGln3WxWe2t9PxnPUl53mmBhbLvSKaXPxvaPGiAQXaavy1jgvOOGnl bUe95xBKuUFBm9CSWV1XFXMFBYgMaBKU+Ukz0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=bbbC1wfdodVsUufVEvRB0eZfNfU9+0M+mINBVeWC5as=; b=W0vzMy+8F+TK5Q5NsHvW0zaCdj1VHEdXq1tU4hjwtDf5ZamFuCK1QvWdhSLpZBink+ kYEKNGgyEh86B7ZbB6gTnvqFqnP2OleQJqXJEUODPhmM9HIuyPz+lw60pfcTQ5anaTZu t9aluq+7l77l//hnZcBuLbBVgM+C7KYsunK/+TlkEg1AZOU38UuyT2RRl4u2nng9zVMT XO9RhTFwdk7kK/53AMBEMLI+mXk1G112u9G1sBL6IJLCV2tOvEnpModsiaCYWn/+SulC NRPGCVGuymlkKF7wnBPejBbEOc3WiMNmAtSUAMtmKxmqUtFFNNom/OEPtp/7zLMl9gJh CBBQ== X-Gm-Message-State: AGi0PubnPI+gWi5ShsO/f58s039uaxPNZ0pObv9hhwr/ZqDcxbqukwuS I4OzR+8X6UVEf4wxlFSX+rYAECL6fdnmJvuMANnoaQqpUexFJg== X-Google-Smtp-Source: APiQypK9lFSNjWkYrnmNPjr0hlj+Z8lfcHc6ZYivm0ONSdNC2rOuZGHoLnLUeH8g8zz5zBIMUd/XX06lmE8jGfYyn7U= X-Received: by 2002:a5d:498b:: with SMTP id r11mr18230931wrq.368.1586776596861; Mon, 13 Apr 2020 04:16:36 -0700 (PDT) MIME-Version: 1.0 From: Stan Grishin Date: Mon, 13 Apr 2020 04:16:25 -0700 Message-ID: To: openwrt-devel@lists.openwrt.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200413_041639_592786_110D04D2 X-CRM114-Status: UNSURE ( 8.39 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:42e listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 HTML_MESSAGE BODY: HTML included in message -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid Subject: [OpenWrt-Devel] new functionality for service shell function X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org I've been using something similar on my system and propose the following patch (first submission to the list, be gentle ;)): EOF } @@ -165,6 +166,13 @@ ${EXTRA_HELP}" } } -ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}" -list_contains ALL_COMMANDS "$action" || action=help +status_ubus() { + name="$(basename "${initscript}")" + /bin/ubus call service list "{'name': '$name'}" + return 0 +} + +ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends status-ubus ${EXTRA_COMMANDS}" +list_contains ALL_COMMANDS "$action" && action="${action/-/_}" || action=help $action "$@" + diff --git a/package/base-files/files/etc/profile b/package/base-files/files/etc/profile index 0beff1608f..e8350cfd6a 100644 --- a/package/base-files/files/etc/profile +++ b/package/base-files/files/etc/profile @@ -38,3 +38,24 @@ in order to prevent unauthorized SSH logins. -------------------------------------------------- EOF fi + +service() { + if [ "$1" = "list-enabled" ]; then + for F in /etc/init.d/* ; do + $F enabled && echo "$F enabled" + done; + elif [ "$1" = "list-disabled" ]; then + for F in /etc/init.d/* ; do + $F enabled || echo "$F disabled" + done; + elif [ -f "/etc/init.d/$1" ]; then + /etc/init.d/$@ + else + echo "Usage: service list-disabled|list-enabled| [command]" + if [ -n "$1" ]; then + echo "service "'"'"$1"'"'" not found, the following services are available:" + ls "/etc/init.d" + fi + return 1 + fi +} diff --git a/package/base-files/files/etc/rc.common b/package/base-files/files/etc/rc.common index 7c11544405..c44614d757 100755 --- a/package/base-files/files/etc/rc.common +++ b/package/base-files/files/etc/rc.common @@ -67,13 +67,14 @@ help() { Syntax: $initscript [command] Available commands: - start Start the service - stop Stop the service - restart Restart the service - reload Reload configuration files (or restart if service does not implement reload) - enable Enable service autostart - disable Disable service autostart - enabled Check if service is started on boot + start Start the service + stop Stop the service + restart Restart the service + reload Reload configuration files (or restart if service does not implement reload) + enable Enable service autostart + disable Disable service autostart + enabled Check if service is started on boot + status-ubus Show ubus info for the service $EXTRA_HELP