Browse Source

Merge pull request #692 from chris5560/master

[privoxy] back to old-style initscript not using procd
Steven Barth 10 years ago
parent
commit
a052782dea
3 changed files with 68 additions and 57 deletions
  1. 7
    9
      net/privoxy/Makefile
  2. 18
    0
      net/privoxy/files/privoxy.hotplug
  3. 43
    48
      net/privoxy/files/privoxy.init

+ 7
- 9
net/privoxy/Makefile View File

@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
9 9
 
10 10
 PKG_NAME:=privoxy
11 11
 PKG_VERSION:=3.0.22
12
-PKG_RELEASE:=1
12
+PKG_RELEASE:=2
13 13
 
14 14
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-stable-src.tar.gz
15 15
 PKG_SOURCE_URL:=@SF/ijbswa
@@ -47,7 +47,7 @@ Version: $(PKG_VERSION)-$(PKG_RELEASE)
47 47
 endef
48 48
 
49 49
 CONFIGURE_ARGS += \
50
-	--sysconfdir=/etc/privoxy \
50
+	--sysconfdir=/etc/privoxy
51 51
 
52 52
 # needed otherwise errors during compile
53 53
 MAKE_FLAGS:=
@@ -67,9 +67,8 @@ define Package/privoxy/preinst
67 67
 	#!/bin/sh
68 68
 	# if run within buildroot exit
69 69
 	[ -n "$${IPKG_INSTROOT}" ] && exit 0
70
-	# stop service # if PKG_UPGRADE NOT WORKING
71
-	# [ "$${PKG_UPGRADE}" = "1" ] && /etc/init.d/privoxy stop
72
-	/etc/init.d/privoxy stop >/dev/null 2>&1
70
+	# stop service if PKG_UPGRADE
71
+	[ "$${PKG_UPGRADE}" = "1" ] && /etc/init.d/privoxy stop >/dev/null 2>&1
73 72
 	exit 0	# supress errors from stop command
74 73
 endef
75 74
 
@@ -78,9 +77,8 @@ define Package/privoxy/install
78 77
 	$(CP) $(PKG_INSTALL_DIR)/usr/sbin/privoxy $(1)/usr/sbin/
79 78
 	$(INSTALL_DIR) $(1)/etc/init.d
80 79
 	$(INSTALL_BIN) ./files/privoxy.init $(1)/etc/init.d/privoxy
81
-	# no longer needed because running with procd
82
-	# $(INSTALL_DIR) $(1)/etc/hotplug.d/iface
83
-	# $(INSTALL_BIN) ./files/privoxy.hotplug $(1)/etc/hotplug.d/iface/80-privoxy
80
+	$(INSTALL_DIR) $(1)/etc/hotplug.d/iface
81
+	$(INSTALL_BIN) ./files/privoxy.hotplug $(1)/etc/hotplug.d/iface/80-privoxy
84 82
 
85 83
 	$(INSTALL_DIR) $(1)/etc/privoxy
86 84
 	$(CP) $(PKG_INSTALL_DIR)/etc/privoxy/* $(1)/etc/privoxy/
@@ -89,7 +87,7 @@ define Package/privoxy/install
89 87
 	$(INSTALL_CONF) ./files/privoxy.oldconfig $(1)/etc/privoxy/config
90 88
 	# create .old file to be removed with next pacakge builds during update
91 89
 	$(INSTALL_CONF) ./files/privoxy.oldconfig $(1)/etc/privoxy/config.old
92
-
90
+	# copy NEW config
93 91
 	$(INSTALL_DIR) $(1)/etc/config
94 92
 	$(INSTALL_CONF) ./files/privoxy.config $(1)/etc/config/privoxy
95 93
 endef

+ 18
- 0
net/privoxy/files/privoxy.hotplug View File

@@ -0,0 +1,18 @@
1
+#!/bin/sh
2
+
3
+# only (re-)start on ifup
4
+[ "$ACTION" = "ifup" ] || exit 0
5
+
6
+PIDFILE=/var/run/privoxy.pid
7
+
8
+_PID=$(cat $PIDFILE 2>/dev/null)
9
+kill -1 $_PID 2>/dev/null
10
+if [ $? -eq 0 ]; then
11
+	# only restart if already running
12
+	logger -p daemon.info -t "privoxy[$_PID]" \
13
+		"Restart request due to '$ACTION' of interface '$INTERFACE'"
14
+	/etc/init.d/privoxy restart
15
+else
16
+	# only start if enabled
17
+	/etc/init.d/privoxy enabled && /etc/init.d/privoxy start
18
+fi

+ 43
- 48
net/privoxy/files/privoxy.init View File

@@ -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
 }