Skip to content

Commit

Permalink
modify init.d
Browse files Browse the repository at this point in the history
  • Loading branch information
rufengsuixing committed Dec 10, 2019
1 parent 7a14f2d commit 0cd60c1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
7 changes: 7 additions & 0 deletions luasrc/model/cbi/AdGuardHome/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ o.description=translate("Will be restore when workdir/data is empty")
o = s:option(Value, "backupwdpath", translate("Backup workdir path"))
o.default = "/usr/bin/AdGuardHome"
o.datatype = "string"
o.validate=function(self, value)
if fs.stat(value,"type")=="reg" then
mp.message ="error!backup dir is a file"
return nil
end
return value
end
function mp.on_commit(map)
io.popen("/etc/init.d/AdGuardHome reload &")
end
Expand Down
44 changes: 26 additions & 18 deletions root/etc/init.d/AdGuardHome
Original file line number Diff line number Diff line change
Expand Up @@ -296,21 +296,24 @@ config_editor()
boot_service() {
config_load "${CONFIGURATION}"
config_get waitonboot $CONFIGURATION waitonboot "0"
if [ "$waitonboot" == "1" ]; then
do_redirect 0
procd_open_instance "waitnet"
procd_set_param command "/usr/share/AdGuardHome/waitnet.sh"
procd_close_instance
echo "no net start pinging"
else
start
config_get_bool enabled $CONFIGURATION enabled 0
if [ "$enabled" == "1" ]; then
if [ "$waitonboot" == "1" ]; then
do_redirect 0
procd_open_instance "waitnet"
procd_set_param command "/usr/share/AdGuardHome/waitnet.sh"
procd_close_instance
echo "no net start pinging"
else
start_service
fi
fi
}
start_service() {
# Reading config
config_load "${CONFIGURATION}"
config_get hashpass $CONFIGURATION hashpass ""
if [ ! -z "$hashpass" ]; then
if [ -n "$hashpass" ]; then
config_editor "users.password" "$hashpass" "$configpath"
uci set $CONFIGURATION.$CONFIGURATION.hashpass=""
fi
Expand Down Expand Up @@ -344,7 +347,7 @@ start_service() {
echo -e "$workdir/data/sessions.db\n$workdir/data/stats.db\n$workdir/data/querylog.json">>/lib/upgrade/keep.d/luci-app-adguardhome
fi
config_get logfile $CONFIGURATION logfile ""
if [ ! -z "$logfile" ]; then
if [ -n "$logfile" ]; then
ADDITIONAL_ARGS="$ADDITIONAL_ARGS -l $logfile"
fi

Expand Down Expand Up @@ -381,7 +384,7 @@ start_service() {
fi
procd_open_instance
get_tz
if [ ! -z "$SET_TZ" ]; then
if [ -n "$SET_TZ" ]; then
procd_set_param env TZ="$SET_TZ"
fi
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
Expand Down Expand Up @@ -413,18 +416,23 @@ reload_service()
config_load "${CONFIGURATION}"
echo "AdGuardHome reloading"
config_get_bool enabled $CONFIGURATION enabled 0
procd_send_signal $CONFIGURATION
if [ "$enabled" == "0" ]; then
procd_kill $CONFIGURATION
do_redirect 0
config_get hashpass $CONFIGURATION hashpass ""
if [ -n "$hashpass" ]; then
config_editor "users.password" "$hashpass" "$configpath"
uci set $CONFIGURATION.$CONFIGURATION.hashpass=""
fi
else
start
fi
start
echo "enabled=$enabled"
}
stop_service()
{
config_load "${CONFIGURATION}"
do_redirect 0
procd_send_signal $CONFIGURATION
config_get backupwd $CONFIGURATION backupwd "0"
if [ "$backupwd" == "1" ]; then
config_get backupwdpath $CONFIGURATION backupwdpath "/usr/bin/AdGuardHome"
Expand All @@ -435,8 +443,8 @@ stop_service()
echo "enabled=$enabled"
}
boot() {
rc_procd boot_service "$@"
if eval "type service_started" 2>/dev/null >/dev/null; then
service_started
fi
rc_procd boot_service "$@"
if eval "type service_started" 2>/dev/null >/dev/null; then
service_started
fi
}

0 comments on commit 0cd60c1

Please sign in to comment.