[OpenWrt-Devel] [PATCH] base-files: add list-enabled/disabled to service function in /etc/profile

Stan Grishin stangri at melmac.net
Wed Jun 3 19:21:42 EDT 2020


To obtain the list of enabled (for autostart) services, you'd type
service list-enabled. For disabled services service list-disabled. It
is useful when you need to quickly check which services are
enabled/disabled or when helping other users troubleshoot.

An alternative to list-enabled/list-disabled that I have considered
was to output the enabled status of available services below the usage
output, ie replace:
                if [ -n "$1" ]; then
                        echo "service "'"'"$1"'"'" not found, the
following services are available:"
                    ls "/etc/init.d"
                fi

with

                if [ -n "$1" ]; then
                        echo "service "'"'"$1"'"'" not found, the
following services are available:"
                    for F in /etc/init.d/* ; do
                        $F enabled && echo "$F (autostart enabled)" ||
echo "$F (autostart **disabled**)"
                    done;
                fi


Please elaborate on the list-start and list-stop question, I'm not
sure I understand the purpose of those.


On Wed, Jun 3, 2020 at 11:34 AM Michael Jones <mike at meshplusplus.com> wrote:
>
>
>
> On Wed, Jun 3, 2020 at 6:42 AM Stan Grishin <stangri at melmac.net> wrote:
>>
>> Implement service list-enabled and service list-disabled to provide an easy way
>> for users to list enabled/disabled services from CLI.
>>
>> Signed-off-by: Stan Grishin <stangri at melmac.net>
>> ---
>>  package/base-files/files/etc/profile | 21 +++++++++++++++++++++
>>  1 file changed, 21 insertions(+)
>>
>> 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
>> +}
>> --
>> 2.25.1
>>
>
> Could you provide examples of how this would be used?
>
> What about "list-start" and "list-stop" as well?

_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list