|
@@ -1,7 +1,7 @@
|
1
|
1
|
#!/bin/sh /etc/rc.common
|
2
|
2
|
|
3
|
3
|
START=80
|
4
|
|
-USE_PROCD=1
|
|
4
|
+STOP=20
|
5
|
5
|
|
6
|
6
|
PIDFILE=/var/run/privoxy.pid
|
7
|
7
|
CFGFILE=/var/etc/privoxy.conf
|
|
@@ -68,57 +68,52 @@ _uci2conf() {
|
68
|
68
|
mv -f $CFGTEMP $CFGFILE
|
69
|
69
|
}
|
70
|
70
|
|
71
|
|
-# privoxy should auto-reload it's configuration
|
72
|
|
-# but it only reload on next connect to one of the listen_address
|
73
|
|
-# if we create a new listen_address privoxy never reload
|
74
|
|
-reload_service() {
|
75
|
|
- # so we restart here because rc.common reload_service only start without stopping
|
76
|
|
- restart "$@"
|
77
|
|
-
|
78
|
|
- # the following should normally work but see above
|
79
|
|
-# _uci2conf # convert uci config
|
|
71
|
+boot() {
|
|
72
|
+ return 0 # will be started by "iface" hotplug events
|
80
|
73
|
}
|
81
|
74
|
|
82
|
|
-service_triggers() {
|
83
|
|
- procd_add_reload_trigger "privoxy"
|
|
75
|
+start() {
|
|
76
|
+ # if already running do nothing
|
|
77
|
+ local _PID=$(cat $PIDFILE 2>/dev/null)
|
|
78
|
+ kill -1 $_PID 2>/dev/null && return 0
|
|
79
|
+
|
|
80
|
+ _uci2conf
|
|
81
|
+ /usr/sbin/privoxy --pidfile $PIDFILE --user privoxy.privoxy $CFGFILE
|
|
82
|
+
|
|
83
|
+ # verify startup
|
|
84
|
+ _PID=$(cat $PIDFILE 2>/dev/null)
|
|
85
|
+ kill -1 $_PID 2>/dev/null
|
|
86
|
+ local _ERR=$?
|
|
87
|
+ [ $_ERR -eq 0 ] \
|
|
88
|
+ && logger -p daemon.notice -t "privoxy[$_PID]" "Started successfully"\
|
|
89
|
+ || logger -p daemon.warn -t "privoxy[-----]" "Failed to start"
|
|
90
|
+ return $_ERR
|
84
|
91
|
}
|
85
|
92
|
|
86
|
|
-start_service() {
|
87
|
|
- # redefined callback for sections when calling config_load
|
88
|
|
- config_cb() {
|
89
|
|
- # $1 type of config section
|
90
|
|
- # $2 name of section
|
91
|
|
- [ "$1" = "interface" ] && \
|
92
|
|
- procd_add_interface_trigger interface.* $2 /etc/init.d/privoxy restart
|
93
|
|
- }
|
94
|
|
-
|
95
|
|
- _uci2conf # convert uci config
|
96
|
|
-
|
97
|
|
- procd_open_instance
|
98
|
|
-
|
99
|
|
- procd_set_param command /usr/sbin/privoxy
|
100
|
|
- procd_append_param command --no-daemon # for procd run in foreground
|
101
|
|
- procd_append_param command --pidfile $PIDFILE # set pid file
|
102
|
|
- procd_append_param command --user privoxy.privoxy # set user
|
103
|
|
- procd_append_param command $CFGFILE # config file
|
104
|
|
-
|
105
|
|
- procd_set_param file $CFGFILE # set configration file
|
106
|
|
-
|
107
|
|
- procd_open_trigger # we need a restart on interface events not a reload
|
108
|
|
- config_load network # load network configuration and set trigger(s) in config_cb() above
|
109
|
|
- procd_close_trigger
|
110
|
|
-
|
111
|
|
- procd_close_instance
|
112
|
|
-}
|
113
|
|
-
|
114
|
|
-service_running() {
|
115
|
|
- logger_trick() {
|
116
|
|
- sleep 1 # give privoxy time to completely come up
|
117
|
|
- logger -p daemon.notice -t "privoxy[$(cat $PIDFILE)]" "Service started successfully"
|
118
|
|
- }
|
119
|
|
- logger_trick &
|
|
93
|
+reload() {
|
|
94
|
+ # reload is also used by luci-app-privoxy
|
|
95
|
+ local _PID=$(cat $PIDFILE 2>/dev/null)
|
|
96
|
+ kill -1 $_PID 2>/dev/null
|
|
97
|
+ if [ $? -eq 0 ]; then
|
|
98
|
+ # only restart if already running
|
|
99
|
+ restart
|
|
100
|
+ else
|
|
101
|
+ # only start if enabled
|
|
102
|
+ enabled && start
|
|
103
|
+ fi
|
|
104
|
+ return 0
|
120
|
105
|
}
|
121
|
106
|
|
122
|
|
-stop_service() {
|
123
|
|
- logger -p daemon.notice -t "privoxy[$(cat $PIDFILE)]" "Service shutdown"
|
|
107
|
+stop() {
|
|
108
|
+ local _PID=$(cat $PIDFILE 2>/dev/null)
|
|
109
|
+ kill -15 $_PID 2>/dev/null
|
|
110
|
+ sleep 1 # give time to shutdown
|
|
111
|
+ local _tmp=$(pgrep privoxy)
|
|
112
|
+ if [ -z "$_tmp" ]; then
|
|
113
|
+ logger -p daemon.notice -t "privoxy[$_PID]" "Shutdown successfully"
|
|
114
|
+ else
|
|
115
|
+ killall -9 privoxy
|
|
116
|
+ logger -p daemon.warn -t "privoxy[-----]" "Shutdown forced by KILL"
|
|
117
|
+ fi
|
|
118
|
+ return 0
|
124
|
119
|
}
|