aboutsummaryrefslogtreecommitdiff
path: root/utils/pservice/files
diff options
context:
space:
mode:
authorYousong Zhou <yszhou4tech@gmail.com>2019-08-04 15:36:08 +0000
committerYousong Zhou <yszhou4tech@gmail.com>2019-08-06 10:09:58 +0800
commitd58a81f35cd0187866f8f06b90a375a088181210 (patch)
tree22e88ed9634906230c24e10933872d2d4f696b9e /utils/pservice/files
parent1a782269f356eeb5d2eceba248f535642b38dc94 (diff)
pservice: initial version
The can be convenient for running commands or services as procd services without needing to separately write initscripts, just uci configuration. The package was imported from [1]. [1] https://github.com/yousong/waller/tree/0a85f5c75fb70627f68cbbcab4807e02e3299e2e/pservice Ref: https://github.com/yousong/waller/issues/1 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Diffstat (limited to 'utils/pservice/files')
-rw-r--r--utils/pservice/files/pservice.config24
-rwxr-xr-xutils/pservice/files/pservice.init85
2 files changed, 109 insertions, 0 deletions
diff --git a/utils/pservice/files/pservice.config b/utils/pservice/files/pservice.config
new file mode 100644
index 000000000..0f505b398
--- /dev/null
+++ b/utils/pservice/files/pservice.config
@@ -0,0 +1,24 @@
+config pservice
+ option disabled 1
+ option name 'demo0'
+ option command /bin/sh
+ option respawn_maxfail 0
+ list args -c
+ list args 'env | logger -t $name; exec sleep $time'
+ list env 'v0=0'
+ list env 'v1=val with space'
+ list env 'name=demo0'
+ list env 'time=1799'
+ list file /tmp/sleep.conf
+
+config pservice
+ option disabled 1
+ option name 8021x
+ option command /usr/sbin/wpa_supplicant
+ option stdout 1
+ list args -i
+ list args eth0.1
+ list args -D
+ list args wired
+ list args -c
+ list args /etc/wpa_supplicant-eth0.1.conf
diff --git a/utils/pservice/files/pservice.init b/utils/pservice/files/pservice.init
new file mode 100755
index 000000000..0a275f8f7
--- /dev/null
+++ b/utils/pservice/files/pservice.init
@@ -0,0 +1,85 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2017 Yousong Zhou
+
+START=99
+
+USE_PROCD=1
+
+pservice_list_cb() {
+ local val="$1"; shift
+ local param="$1"; shift
+
+ procd_append_param "$param" "$val"
+}
+
+pservice() {
+ local cfg="$1"
+
+ eval "$(validate_pservice_section "$cfg" pservice_validate_mklocal)"
+ validate_pservice_section "$cfg" || return 1
+ [ "$disabled" = 0 ] || return 0
+ [ -x "$command" ] || return 1
+
+ procd_open_instance "$name"
+ procd_set_param command "$command"
+ procd_set_param stderr "$stderr"
+ procd_set_param stdout "$stdout"
+ procd_set_param respawn "$respawn_threshold" "$respawn_timeout" "$respawn_maxfail"
+ [ -z "$args" ] || config_list_foreach "$cfg" args pservice_list_cb command
+ if [ -n "$env" ]; then
+ procd_set_param env
+ config_list_foreach "$cfg" env pservice_list_cb env
+ fi
+ if [ -n "$file" ]; then
+ procd_set_param file
+ config_list_foreach "$cfg" file pservice_list_cb file
+ fi
+ procd_close_instance
+}
+
+start_service() {
+ config_load 'pservice'
+ config_foreach pservice pservice
+}
+
+stop_service() {
+ true
+}
+
+service_triggers() {
+ procd_open_validate
+ validate_pservice_section
+ procd_close_validate
+}
+
+pservice_validate_mklocal() {
+ local tuple opts
+
+ shift 2
+ for tuple in "$@"; do
+ opts="${tuple%%:*} $opts"
+ done
+ [ -z "$opts" ] || echo "local $opts"
+}
+
+pservice_validate() {
+ uci_validate_section pservice "$@"
+}
+
+validate_pservice_section() {
+ local cfg="$1"; shift
+ local func="$1"; shift
+
+ "${func:-pservice_validate}" pservice "$cfg" \
+ "disabled:bool:0" \
+ "name:string" \
+ "env:regex('^[a-zA-Z_][a-zA-Z0-9_]*=.*$')" \
+ "command:file" \
+ "args:list(string)" \
+ "stderr:bool:0" \
+ "stdout:bool:0" \
+ "respawn_threshold:uinteger:3600" \
+ "respawn_timeout:uinteger:5" \
+ "respawn_maxfail:uinteger:5" \
+ "file:string"
+}