diff mbox series

procd: add info json output

Message ID 20201214123627.23555-1-fe@dev.tdt.de
State Superseded
Headers show
Series procd: add info json output | expand

Commit Message

Florian Eckert Dec. 14, 2020, 12:36 p.m. UTC
By adding the extra command `info` it is now possible to retrieve all
relevant data from a procd started service directly via the init script.

Until now, you have to query the ubus with the command:
ubus call service list '{"name":"<xxx>","verbose":true}'

With this change, the init script is now used with the command:
/etc/init.d/<xxx> info

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
---
 package/base-files/files/etc/rc.common |  5 +++++
 package/system/procd/files/procd.sh    | 14 ++++++++++++++
 2 files changed, 19 insertions(+)

Comments

Daniel Golle Dec. 14, 2020, 12:47 p.m. UTC | #1
Hi Florian,

On Mon, Dec 14, 2020 at 01:36:27PM +0100, Florian Eckert wrote:
> By adding the extra command `info` it is now possible to retrieve all
> relevant data from a procd started service directly via the init script.
> 
> Until now, you have to query the ubus with the command:
> ubus call service list '{"name":"<xxx>","verbose":true}'
> 
> With this change, the init script is now used with the command:
> /etc/init.d/<xxx> info
> 
> Signed-off-by: Florian Eckert <fe@dev.tdt.de>
> ---
>  package/base-files/files/etc/rc.common |  5 +++++
>  package/system/procd/files/procd.sh    | 14 ++++++++++++++
>  2 files changed, 19 insertions(+)
> 
> diff --git a/package/base-files/files/etc/rc.common b/package/base-files/files/etc/rc.common
> index f39b69464e..c7fde31d41 100755
> --- a/package/base-files/files/etc/rc.common
> +++ b/package/base-files/files/etc/rc.common
> @@ -121,6 +121,7 @@ extra_command "enabled" "Check if service is started on boot"
>  	extra_command "running" "Check if service is running"
>  	extra_command "status" "Service status"
>  	extra_command "trace" "Start with syscall trace"
> +	extra_command "info" "Dump service info as json"
>  
>  	. $IPKG_INSTROOT/lib/functions/procd.sh
>  	basescript=$(readlink "$initscript")
> @@ -173,6 +174,10 @@ extra_command "enabled" "Check if service is started on boot"
>  			_procd_status "$(basename ${basescript:-$initscript})" "$1"
>  		fi
>  	}
> +
> +	info() {
> +		_procd_info "$(basename ${basescript:-$initscript})"
> +	}
>  }
>  
>  ALL_COMMANDS="${ALL_COMMANDS} ${EXTRA_COMMANDS}"
> diff --git a/package/system/procd/files/procd.sh b/package/system/procd/files/procd.sh
> index d86b7219da..1969cdf973 100644
> --- a/package/system/procd/files/procd.sh
> +++ b/package/system/procd/files/procd.sh
> @@ -474,6 +474,20 @@ _procd_status() {
>  	fi
>  }
>  
> +_procd_info() {
> +	local service="$1"
> +	local data
> +
> +	data=$(_procd_ubus_call list | jsonfilter -e '@["'"$service"'"]')
> +	[ -z "$data" ] && { echo "not found"; return 3; }
> +
> +	json_init
> +	json_add_string name "$service"
> +	json_add_boolean verbose "1"
> +	json_add_string name "$service"

This line seems to be a duplicate of the identical line above.
Adding the field twice doesn't make sense.



> +	_procd_ubus_call list
> +}
> +
>  procd_open_data() {
>  	local name="$1"
>  	json_set_namespace procd __procd_old_cb
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Adrian Schmutzler Dec. 14, 2020, 1:10 p.m. UTC | #2
Hi,

> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-bounces@lists.openwrt.org]
> On Behalf Of Florian Eckert
> Sent: Montag, 14. Dezember 2020 13:36
> To: daniel@makrotopia.org
> Cc: openwrt-devel@lists.openwrt.org; Florian Eckert <fe@dev.tdt.de>;
> Florian.Eckert@googlemail.com
> Subject: [PATCH] procd: add info json output

please bump PKG_RELEASE for both packages.

Best

Adrian

> 
> By adding the extra command `info` it is now possible to retrieve all relevant
> data from a procd started service directly via the init script.
> 
> Until now, you have to query the ubus with the command:
> ubus call service list '{"name":"<xxx>","verbose":true}'
> 
> With this change, the init script is now used with the command:
> /etc/init.d/<xxx> info
> 
> Signed-off-by: Florian Eckert <fe@dev.tdt.de>
> ---
>  package/base-files/files/etc/rc.common |  5 +++++
>  package/system/procd/files/procd.sh    | 14 ++++++++++++++
>  2 files changed, 19 insertions(+)
> 
> diff --git a/package/base-files/files/etc/rc.common b/package/base-
> files/files/etc/rc.common
> index f39b69464e..c7fde31d41 100755
> --- a/package/base-files/files/etc/rc.common
> +++ b/package/base-files/files/etc/rc.common
> @@ -121,6 +121,7 @@ extra_command "enabled" "Check if service is started
> on boot"
>  	extra_command "running" "Check if service is running"
>  	extra_command "status" "Service status"
>  	extra_command "trace" "Start with syscall trace"
> +	extra_command "info" "Dump service info as json"
> 
>  	. $IPKG_INSTROOT/lib/functions/procd.sh
>  	basescript=$(readlink "$initscript")
> @@ -173,6 +174,10 @@ extra_command "enabled" "Check if service is
> started on boot"
>  			_procd_status "$(basename ${basescript:-
> $initscript})" "$1"
>  		fi
>  	}
> +
> +	info() {
> +		_procd_info "$(basename ${basescript:-$initscript})"
> +	}
>  }
> 
>  ALL_COMMANDS="${ALL_COMMANDS} ${EXTRA_COMMANDS}"
> diff --git a/package/system/procd/files/procd.sh
> b/package/system/procd/files/procd.sh
> index d86b7219da..1969cdf973 100644
> --- a/package/system/procd/files/procd.sh
> +++ b/package/system/procd/files/procd.sh
> @@ -474,6 +474,20 @@ _procd_status() {
>  	fi
>  }
> 
> +_procd_info() {
> +	local service="$1"
> +	local data
> +
> +	data=$(_procd_ubus_call list | jsonfilter -e '@["'"$service"'"]')
> +	[ -z "$data" ] && { echo "not found"; return 3; }
> +
> +	json_init
> +	json_add_string name "$service"
> +	json_add_boolean verbose "1"
> +	json_add_string name "$service"
> +	_procd_ubus_call list
> +}
> +
>  procd_open_data() {
>  	local name="$1"
>  	json_set_namespace procd __procd_old_cb
> --
> 2.20.1
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
diff mbox series

Patch

diff --git a/package/base-files/files/etc/rc.common b/package/base-files/files/etc/rc.common
index f39b69464e..c7fde31d41 100755
--- a/package/base-files/files/etc/rc.common
+++ b/package/base-files/files/etc/rc.common
@@ -121,6 +121,7 @@  extra_command "enabled" "Check if service is started on boot"
 	extra_command "running" "Check if service is running"
 	extra_command "status" "Service status"
 	extra_command "trace" "Start with syscall trace"
+	extra_command "info" "Dump service info as json"
 
 	. $IPKG_INSTROOT/lib/functions/procd.sh
 	basescript=$(readlink "$initscript")
@@ -173,6 +174,10 @@  extra_command "enabled" "Check if service is started on boot"
 			_procd_status "$(basename ${basescript:-$initscript})" "$1"
 		fi
 	}
+
+	info() {
+		_procd_info "$(basename ${basescript:-$initscript})"
+	}
 }
 
 ALL_COMMANDS="${ALL_COMMANDS} ${EXTRA_COMMANDS}"
diff --git a/package/system/procd/files/procd.sh b/package/system/procd/files/procd.sh
index d86b7219da..1969cdf973 100644
--- a/package/system/procd/files/procd.sh
+++ b/package/system/procd/files/procd.sh
@@ -474,6 +474,20 @@  _procd_status() {
 	fi
 }
 
+_procd_info() {
+	local service="$1"
+	local data
+
+	data=$(_procd_ubus_call list | jsonfilter -e '@["'"$service"'"]')
+	[ -z "$data" ] && { echo "not found"; return 3; }
+
+	json_init
+	json_add_string name "$service"
+	json_add_boolean verbose "1"
+	json_add_string name "$service"
+	_procd_ubus_call list
+}
+
 procd_open_data() {
 	local name="$1"
 	json_set_namespace procd __procd_old_cb