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

Stan Grishin stangri at melmac.net
Thu Jun 4 19:49:44 EDT 2020


Daniel, thanks, that's what I ended up doing in the code for the `service list`.

Should I send the patch for `service list` and remove `service
list-enabled` and `service list-disabled`? Do people care about this
minor improvement?

On Thu, Jun 4, 2020 at 4:13 PM Daniel Bailey <danielb at meshplusplus.com> wrote:
>
> Somebody who is better with jsonfilter than me might be able to clean this up, but it does the trick:
>
> #!/bin/sh
>
> . /usr/share/libubox/jshn.sh
>
> json_load "$(ubus call service list)"
> json_get_keys SERVICES
>
> for SERVICE in $SERVICES; do
>     echo "$SERVICE: `ubus call service list | jsonfilter -e "@.$SERVICE.instances[\"*\"].running"`"
> done
>
> On Thu, Jun 4, 2020 at 2:56 AM Stan Grishin <stangri at melmac.net> wrote:
>>
>> On Wed, Jun 3, 2020 at 4:53 PM Michael Jones <mike at meshplusplus.com> wrote:
>> >
>> >
>> >
>> > On Wed, Jun 3, 2020 at 6:21 PM Stan Grishin <stangri at melmac.net> wrote:
>> >>
>> >> 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.
>> >
>> >
>> > Originally I asked that question because I misunderstood what the goal of this change was.
>> >
>> > I thought that you were proposing to add the ability to enable / disable multiple services at the same time, so I was asking about the ability to start / stop multiple services at the same time.
>> >
>> > It's clear not that's not what you were trying to propose.
>> >
>> > So instead, what about listing the services that are running, and also listing the services that are configured, but not running?
>>
>> Is there an easy universal way to determine if the service is running?
>>
>> > I don't know that that provides a lot of value, so it may not be worth doing.
>>
>> If there's a one/two liner to figure out if a service is running or
>> not, it may be better to implement `service list` which would print
>> the table of available init scripts, wherever they are enabled or not
>> and wherever they are running or not.
>>
>> If that is deemed to be a better approach I can resubmit the patch.
>>
>> _______________________________________________
>> openwrt-devel mailing list
>> openwrt-devel at lists.openwrt.org
>> https://lists.openwrt.org/mailman/listinfo/openwrt-devel

_______________________________________________
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