diff mbox

[V3,2/5] package/squid: add init script

Message ID 1416322487-14247-3-git-send-email-guillaume.gardet@oliseo.fr
State Superseded
Headers show

Commit Message

Guillaume GARDET Nov. 18, 2014, 2:54 p.m. UTC
Signed-off-by: Guillaume GARDET <guillaume.gardet@oliseo.fr>

---
 package/squid/S97squid | 36 ++++++++++++++++++++++++++++++++++++
 package/squid/squid.mk |  7 +++++++
 2 files changed, 43 insertions(+)
 create mode 100644 package/squid/S97squid

Comments

Thomas Petazzoni Nov. 23, 2014, 9:18 p.m. UTC | #1
Dear Guillaume GARDET,

On Tue, 18 Nov 2014 15:54:44 +0100, Guillaume GARDET wrote:

> +# (Re)create log directory and give access to squid user (nobody)
> +if [ ! -d $SQUID_LOG_DIR ]; then
> +	mkdir -p $SQUID_LOG_DIR 
> +	chmod 777 $SQUID_LOG_DIR

Clearly, this doesn't look good. Don't we have a better option than 777
the log directory?

> +    restart | force-reload)
> +	$0 stop
> +	sleep 2

sleep 2 really needed here?

> +	$0 start
> +	if [ "$?" != "0" ]; then
> +		exit 1
> +	fi
> +	;;
> +     *)
> +	echo "Usage: /etc/init.d/S97squid {start|stop|restart|force-reload}"

Replace /etc/init.d/S97squid by $0 maybe?

Thanks,

Thomas
Guillaume GARDET Nov. 29, 2014, 7:41 p.m. UTC | #2
Le 23/11/2014 22:18, Thomas Petazzoni a écrit :
> Dear Guillaume GARDET,
>
> On Tue, 18 Nov 2014 15:54:44 +0100, Guillaume GARDET wrote:
>
>> +# (Re)create log directory and give access to squid user (nobody)
>> +if [ ! -d $SQUID_LOG_DIR ]; then
>> +	mkdir -p $SQUID_LOG_DIR
>> +	chmod 777 $SQUID_LOG_DIR
> Clearly, this doesn't look good. Don't we have a better option than 777
> the log directory?

Maybe create a squid user? Not sure how to handle this in buildroot. What do you think?

>
>> +    restart | force-reload)
>> +	$0 stop
>> +	sleep 2
> sleep 2 really needed here?

Not sure.

>
>> +	$0 start
>> +	if [ "$?" != "0" ]; then
>> +		exit 1
>> +	fi
>> +	;;
>> +     *)
>> +	echo "Usage: /etc/init.d/S97squid {start|stop|restart|force-reload}"
> Replace /etc/init.d/S97squid by $0 maybe?

If you want.


Guillaume
Thomas Petazzoni Nov. 30, 2014, 8:33 a.m. UTC | #3
Hello,

On Sat, 29 Nov 2014 20:41:52 +0100, Guillaume GARDET - Oliséo wrote:

> >> +# (Re)create log directory and give access to squid user (nobody)
> >> +if [ ! -d $SQUID_LOG_DIR ]; then
> >> +	mkdir -p $SQUID_LOG_DIR
> >> +	chmod 777 $SQUID_LOG_DIR
> > Clearly, this doesn't look good. Don't we have a better option than 777
> > the log directory?
> 
> Maybe create a squid user? Not sure how to handle this in buildroot. What do you think?

Well, if squid currently runs as root, why do you need to "chmod 777"
the log directory?

But indeed, it would be nicer to run squid as a user. Look at
<pkg>_USERS and <pkg>_PERMISSIONS in the Buildroot manual, or grep
through the packages for such definitions, you'll see some examples on
how to achieve that.

Best regards,

Thomas
diff mbox

Patch

diff --git a/package/squid/S97squid b/package/squid/S97squid
new file mode 100644
index 0000000..0908784
--- /dev/null
+++ b/package/squid/S97squid
@@ -0,0 +1,36 @@ 
+#!/bin/sh
+
+SQUID_BIN="/usr/sbin/squid"
+SQUID_LOG_DIR="/var/log/squid"
+SQUID_PID=/var/run/squid.pid
+SQUID_CONF=/etc/squid.conf
+SQUID_OPTS=""
+
+# (Re)create log directory and give access to squid user (nobody)
+if [ ! -d $SQUID_LOG_DIR ]; then
+	mkdir -p $SQUID_LOG_DIR 
+	chmod 777 $SQUID_LOG_DIR
+fi
+
+case "$1" in
+    start)
+	echo -n "Starting WWW-proxy squid "
+	start-stop-daemon -S -x $SQUID_BIN -- -f $SQUID_CONF $SQUID_OPTS
+	[ $? == 0 ] && echo "OK" || echo "FAIL"
+	;;
+    stop)
+	echo -n "Shutting down WWW-proxy squid "
+	start-stop-daemon -K -x $SQUID_BIN
+	;;
+    restart | force-reload)
+	$0 stop
+	sleep 2
+	$0 start
+	if [ "$?" != "0" ]; then
+		exit 1
+	fi
+	;;
+     *)
+	echo "Usage: /etc/init.d/S97squid {start|stop|restart|force-reload}"
+	exit 1
+esac
diff --git a/package/squid/squid.mk b/package/squid/squid.mk
index ed51881..b0fa69f 100644
--- a/package/squid/squid.mk
+++ b/package/squid/squid.mk
@@ -50,4 +50,11 @@  endef
 
 SQUID_POST_INSTALL_TARGET_HOOKS += SQUID_CLEANUP_TARGET
 
+define SQUID_INSTALL_INIT_SYSV
+        # install start/stop script
+        @if [ ! -f $(TARGET_DIR)/etc/init.d/S97squid ]; then \
+                $(INSTALL) -m 0755 -D package/squid/S97squid $(TARGET_DIR)/etc/init.d/S97squid; \
+        fi
+endef
+
 $(eval $(autotools-package))