From c12872881176d97b43926b01e8593a46bc6d04a0 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Tue, 30 Nov 2021 16:01:14 +0100 Subject: [PATCH] procd: move service command to procd The service command belongs to the procd and does not belong in the shinit. In the course of the move, the script was also checked with shellcheck and cleaned up. Signed-off-by: Florian Eckert (cherry picked from commit b9017384cae7bbc47186fdf35a80207844876a0d) --- package/base-files/files/etc/profile | 11 +--------- package/base-files/files/etc/shinit | 21 ------------------- package/system/procd/Makefile | 1 + package/system/procd/files/service | 30 ++++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 31 deletions(-) create mode 100644 package/system/procd/files/service diff --git a/package/base-files/files/etc/profile b/package/base-files/files/etc/profile index 222fdace9b..283a62dc74 100644 --- a/package/base-files/files/etc/profile +++ b/package/base-files/files/etc/profile @@ -3,7 +3,7 @@ [ -f /etc/banner ] && cat /etc/banner [ -n "$FAILSAFE" ] && cat /etc/banner.failsafe -fgrep -sq '/ overlay ro,' /proc/mounts && { +grep -Fsq '/ overlay ro,' /proc/mounts && { echo 'Your JFFS2-partition seems full and overlayfs is mounted read-only.' echo 'Please try to remove files from /overlay/upper/... and reboot!' } @@ -51,12 +51,3 @@ in order to prevent unauthorized SSH logins. -------------------------------------------------- EOF fi - -service() { - [ -f "/etc/init.d/$1" ] || { - echo "service "'"'"$1"'"'" not found, the following services are available:" - ls "/etc/init.d" - return 1 - } - /etc/init.d/$@ -} diff --git a/package/base-files/files/etc/shinit b/package/base-files/files/etc/shinit index 6b682d8769..8df9771e65 100644 --- a/package/base-files/files/etc/shinit +++ b/package/base-files/files/etc/shinit @@ -8,26 +8,5 @@ alias ll='ls -alF --color=auto' [ -x /usr/bin/arp -o -x /sbin/arp ] || arp() { cat /proc/net/arp; } [ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; } -service() { - if [ -f "/etc/init.d/$1" ]; then - /etc/init.d/$@ - else - echo "Usage: service [command]" - if [ -n "$1" ]; then - echo "Service "'"'"$1"'"'" not found, the following services are available:" - else - echo "The following services are available:" - fi - for F in /etc/init.d/* ; do - printf "%-30s\t%10s\t%10s\n" "$F" \ - $( $($F enabled) && echo "enabled" || echo "disabled" ) \ - $( [ "$(ubus call service list "{ 'verbose': true, 'name': '$(basename $F)' }" \ - | jsonfilter -q -e "@['$(basename $F)'].instances[*].running" | uniq)" = "true" ] \ - && echo "running" || echo "stopped" ) - done; - return 1 - fi -} - [ -n "$KSH_VERSION" -o \! -s "$HOME/.shinit" ] || . "$HOME/.shinit" [ -z "$KSH_VERSION" -o \! -s "$HOME/.mkshrc" ] || . "$HOME/.mkshrc" diff --git a/package/system/procd/Makefile b/package/system/procd/Makefile index 861dd0da57..641b2fc1f1 100644 --- a/package/system/procd/Makefile +++ b/package/system/procd/Makefile @@ -138,6 +138,7 @@ define Package/procd/install $(INSTALL_BIN) ./files/reload_config $(1)/sbin/ $(INSTALL_CONF) ./files/hotplug*.json $(1)/etc/ $(INSTALL_DATA) ./files/procd.sh $(1)/lib/functions/ + $(INSTALL_BIN) ./files/service $(1)/sbin/service endef Package/procd-selinux/install = $(Package/procd/install) diff --git a/package/system/procd/files/service b/package/system/procd/files/service new file mode 100644 index 0000000000..1ceacfe5ad --- /dev/null +++ b/package/system/procd/files/service @@ -0,0 +1,30 @@ +#!/bin/sh + +main() { + local service="$1" + local cmd="$2" + + local boot status + + if [ -f "/etc/init.d/${service}" ]; then + /etc/init.d/"${service}" "${cmd}" + exit "$?" + fi + + if [ -n "$service" ]; then + echo "Service \"$1\" not found:" + exit 1 + fi + + echo "Usage: $(basename "$0") [command]" + for service in /etc/init.d/* ; do + boot="$($service enabled && echo "enabled" || echo "disabled" )" + status="$( [ "$(ubus call service list "{ 'verbose': true, 'name': '$(basename "$service")' }" \ + | jsonfilter -q -e "@['$(basename "$service")'].instances[*].running" | uniq)" = "true" ] \ + && echo "running" || echo "stopped" )" + + printf "%-30s\\t%10s\\t%10s\\n" "$service" "$boot" "$status" + done +} + +main "$@"