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 <fe@dev.tdt.de>
This commit is contained in:
Florian Eckert 2021-11-30 16:01:14 +01:00 committed by Hauke Mehrtens
parent b04d38a2ea
commit b9017384ca
3 changed files with 31 additions and 21 deletions

View File

@ -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/arp -o -x /sbin/arp ] || arp() { cat /proc/net/arp; }
[ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; } [ -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 <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" [ -n "$KSH_VERSION" -o \! -s "$HOME/.shinit" ] || . "$HOME/.shinit"
[ -z "$KSH_VERSION" -o \! -s "$HOME/.mkshrc" ] || . "$HOME/.mkshrc" [ -z "$KSH_VERSION" -o \! -s "$HOME/.mkshrc" ] || . "$HOME/.mkshrc"

View File

@ -121,6 +121,7 @@ define Package/procd/install
$(INSTALL_BIN) ./files/reload_config $(1)/sbin/ $(INSTALL_BIN) ./files/reload_config $(1)/sbin/
$(INSTALL_CONF) ./files/hotplug*.json $(1)/etc/ $(INSTALL_CONF) ./files/hotplug*.json $(1)/etc/
$(INSTALL_DATA) ./files/procd.sh $(1)/lib/functions/ $(INSTALL_DATA) ./files/procd.sh $(1)/lib/functions/
$(INSTALL_BIN) ./files/service $(1)/sbin/service
endef endef
Package/procd-selinux/install = $(Package/procd/install) Package/procd-selinux/install = $(Package/procd/install)

View File

@ -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") <service> [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 "$@"