xray-core: fix service start / reload
authorTianling Shen <cnsztl@project-openwrt.eu.org>
Wed, 3 Feb 2021 22:53:47 +0000 (06:53 +0800)
committerTianling Shen <cnsztl@project-openwrt.eu.org>
Thu, 4 Feb 2021 03:50:40 +0000 (11:50 +0800)
Fix starting problem:
Starting function should be named 'start_service' instead of 'start_instance'.

Fix reloading problem:
Register reload tigger for uci config itself.
And, xray does not support reload currently, so use legacy restart as reload.

Fixes: 6c9b96352fb5e7d6acdf8f14ea4f9251cd09926b ("xray-core: add init script")
Signed-off-by: Tianling Shen <cnsztl@project-openwrt.eu.org>
net/xray-core/files/xray.init

index f45df1b94a03bc502a3e127fe9bc54b10af3d95f..8ee5caa8f89980cf3dd0e98c246f2d3aad9b68d8 100755 (executable)
@@ -7,7 +7,7 @@ CONF="xray"
 PROG="/usr/bin/xray"
 CAPA_FILE="/etc/capabilities/xray.json"
 
-start_instance() {
+start_service() {
        config_load "$CONF"
 
        local enabled
@@ -24,7 +24,7 @@ start_instance() {
        config_get datadir "config" "datadir" "/usr/share/xray"
        config_get format "config" "format" "json"
 
-       procd_open_instance
+       procd_open_instance "$CONF"
        procd_set_param command "$PROG" run
        [ -n "$confdir" ] && procd_append_param command -confdir "$confdir"
        [ -n "$conffiles" ] && {
@@ -42,10 +42,19 @@ start_instance() {
        procd_set_param respawn
 
        [ -x "/sbin/ujail" -a -e "$CAPA_FILE" ] && {
-               procd_add_jail xray
+               procd_add_jail "$CONF"
                procd_set_param capabilities "$CAPA_FILE"
                procd_set_param user nobody
                procd_set_param no_new_privs 1
        }
        procd_close_instance
 }
+
+reload_service() {
+       stop
+       start
+}
+
+service_triggers() {
+       procd_add_reload_trigger "$CONF"
+}