diff mbox series

[OpenWrt-Devel] new functionality for service shell function

Message ID CALu2O0SgR3FGgJ6epuQsmeZFxTsd0czNHaX3N0wQRgWYKWwbUQ@mail.gmail.com
State Changes Requested
Delegated to: Petr Štetiar
Headers show
Series [OpenWrt-Devel] new functionality for service shell function | expand

Commit Message

Stan Grishin April 13, 2020, 11:16 a.m. UTC
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 "$@"
+

Comments

Petr Štetiar June 3, 2020, 10:16 a.m. UTC | #1
Stan Grishin <stangri@melmac.net> [2020-04-13 04:16:25]:

Hi,

> I've been using something similar on my system and propose the following
> patch (first submission to the list, be gentle ;)):

no worries, just read https://openwrt.org/submitting-patches and try again :-)

Commit subject should be "base-files: ..." and mail "Subject: [PATCH]
base-files: ...", easily done with `git format-patch -s1 ...`, then `git
send-email` and you're done.

Please add as well some proper commit description.

Thanks.

-- ynezz

> 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|<service>
> [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
>  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 mbox series

Patch

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|<service>
[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