Message ID | 20190501052321.11985-1-zajec5@gmail.com |
---|---|
State | Accepted |
Delegated to: | Rafał Miłecki |
Headers | show |
Series | [OpenWrt-Devel] procd: add procd_running() helper for checking running state | expand |
Hi, comment inline below. > From: Rafał Miłecki <rafal@milecki.pl> > > This should be helpful for implementing service_running() in procd init > scripts. > > Signed-off-by: Rafał Miłecki <rafal@milecki.pl> > --- > package/system/procd/files/procd.sh | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/package/system/procd/files/procd.sh b/package/system/procd/files/procd.sh > index 72f25fe0c0..ade55a344f 100644 > --- a/package/system/procd/files/procd.sh > +++ b/package/system/procd/files/procd.sh > @@ -26,6 +26,9 @@ > # procd_close_instance(): > # Complete the instance being prepared > # > +# procd_running(service, [instance]): > +# Checks if service/instance is currently running > +# > # procd_kill(service, [instance]): > # Kill a service instance (or all instances) > # > @@ -398,6 +401,18 @@ _procd_add_instance() { > _procd_close_instance > } > > +procd_running() { > + local service="$1" > + local instance="${2:-instance1}" > + local running > + > + json_init > + json_add_string name "$service" > + running=$(_procd_ubus_call list | jsonfilter -e "@.$service.instances.${instance}.running") Pass '{ "name": "'"$service"'" }' as argument to the list call to reduce the amount of output you need to filter. > + > + [ "$running" = "true" ] > +} > + > _procd_kill() { > local service="$1" > local instance="$2" > ~ Jo
On 01/05/2019 19:08, Jo-Philipp Wich wrote: > Hi, > > comment inline below. > >> From: Rafał Miłecki <rafal@milecki.pl> >> >> This should be helpful for implementing service_running() in procd init >> scripts. >> >> Signed-off-by: Rafał Miłecki <rafal@milecki.pl> >> --- >> package/system/procd/files/procd.sh | 15 +++++++++++++++ >> 1 file changed, 15 insertions(+) >> >> diff --git a/package/system/procd/files/procd.sh b/package/system/procd/files/procd.sh >> index 72f25fe0c0..ade55a344f 100644 >> --- a/package/system/procd/files/procd.sh >> +++ b/package/system/procd/files/procd.sh >> @@ -26,6 +26,9 @@ >> # procd_close_instance(): >> # Complete the instance being prepared >> # >> +# procd_running(service, [instance]): >> +# Checks if service/instance is currently running >> +# >> # procd_kill(service, [instance]): >> # Kill a service instance (or all instances) >> # >> @@ -398,6 +401,18 @@ _procd_add_instance() { >> _procd_close_instance >> } >> >> +procd_running() { >> + local service="$1" >> + local instance="${2:-instance1}" >> + local running >> + >> + json_init >> + json_add_string name "$service" >> + running=$(_procd_ubus_call list | jsonfilter -e "@.$service.instances.${instance}.running") > Pass '{ "name": "'"$service"'" }' as argument to the list call to reduce the amount of output you > need to filter. the line above the invocation already adds the service name if i am not mistaken Acked-by: John Crispin <john@phrozen.org> >> + >> + [ "$running" = "true" ] >> +} >> + >> _procd_kill() { >> local service="$1" >> local instance="$2" >> > > ~ Jo > > > _______________________________________________ > openwrt-devel mailing list > openwrt-devel@lists.openwrt.org > https://lists.openwrt.org/mailman/listinfo/openwrt-devel
On Wed, 1 May 2019 at 19:09, Jo-Philipp Wich <jo@mein.io> wrote: > > From: Rafał Miłecki <rafal@milecki.pl> > > > > This should be helpful for implementing service_running() in procd init > > scripts. > > > > Signed-off-by: Rafał Miłecki <rafal@milecki.pl> > > --- > > package/system/procd/files/procd.sh | 15 +++++++++++++++ > > 1 file changed, 15 insertions(+) > > > > diff --git a/package/system/procd/files/procd.sh b/package/system/procd/files/procd.sh > > index 72f25fe0c0..ade55a344f 100644 > > --- a/package/system/procd/files/procd.sh > > +++ b/package/system/procd/files/procd.sh > > @@ -26,6 +26,9 @@ > > # procd_close_instance(): > > # Complete the instance being prepared > > # > > +# procd_running(service, [instance]): > > +# Checks if service/instance is currently running > > +# > > # procd_kill(service, [instance]): > > # Kill a service instance (or all instances) > > # > > @@ -398,6 +401,18 @@ _procd_add_instance() { > > _procd_close_instance > > } > > > > +procd_running() { > > + local service="$1" > > + local instance="${2:-instance1}" > > + local running > > + > > + json_init > > + json_add_string name "$service" > > + running=$(_procd_ubus_call list | jsonfilter -e "@.$service.instances.${instance}.running") > > Pass '{ "name": "'"$service"'" }' as argument to the list call to reduce the amount of output you > need to filter. It's handed by: json_add_string name "$service" and then _procd_ubus_call using that JSON that was built before calling it.
diff --git a/package/system/procd/files/procd.sh b/package/system/procd/files/procd.sh index 72f25fe0c0..ade55a344f 100644 --- a/package/system/procd/files/procd.sh +++ b/package/system/procd/files/procd.sh @@ -26,6 +26,9 @@ # procd_close_instance(): # Complete the instance being prepared # +# procd_running(service, [instance]): +# Checks if service/instance is currently running +# # procd_kill(service, [instance]): # Kill a service instance (or all instances) # @@ -398,6 +401,18 @@ _procd_add_instance() { _procd_close_instance } +procd_running() { + local service="$1" + local instance="${2:-instance1}" + local running + + json_init + json_add_string name "$service" + running=$(_procd_ubus_call list | jsonfilter -e "@.$service.instances.${instance}.running") + + [ "$running" = "true" ] +} + _procd_kill() { local service="$1" local instance="$2"