Skip to content

Instantly share code, notes, and snippets.

@GeoffWilliams
Last active Aug 29, 2015
Embed
What would you like to do?
init script for squid on openWRT
#!/bin/sh /etc/rc.common
# Squid 3.4 control script for openwrt
#
# Assumes a squid installation under /usr/local/squid, all other
# values are parsed from the squid config file so no need to edit
# locally
#
# Copyright (C) 2007 OpenWrt.org
START=99
STOP=99
export PATH=/usr/local/squid/bin:/usr/local/squid/sbin:$PATH
CONFIG_FILE="/etc/squid.conf"
TARGET_LOG_DIR="/var/log/squid"
# parsed from config file
CACHE_DIR=$(awk '/^cache_dir/ {print $3;}' $CONFIG_FILE)
SQUID_USER=$(awk '/^cache_effective_user/ {print $2;}' $CONFIG_FILE)
LOG_DIR=$(awk '/^cache_log/ {gsub(/\/[^\/]+$/,"", $2); print $2;};' $CONFIG_FILE)
SQUID_CMD="squid -f $CONFIG_FILE"
start() {
echo "Squid options parsed from config file:"
echo " CONFIG_FILE $CONFIG_FILE"
echo " CACHE_DIR $CACHE_DIR"
echo " SQUID_USER $SQUID_USER"
echo " LOG_DIR $LOG_DIR"
echo " SQUID_CMD $SQUID_CMD"
# LOG_DIR should refer to a location on usb storage to keep
# potentially huge log files out of ramdisk ;-) For
# convenience we will symlink this directory back to
# /var/log/squid so the logs are easy to find
if [ ! -d "$LOG_DIR" ] ; then
mkdir -p "$LOG_DIR"
chown "$SQUID_USER" "$LOG_DIR"
fi
# For convenience we will symlink this directory back to
# /var/log/squid so the logs are easy to find
if [ ! -L "$TARGET_LOG_DIR" ] ; then
ln -s "$LOG_DIR" "$TARGET_LOG_DIR"
fi
if [ ! -d "$CACHE_DIR" ] ; then
echo "No cache dir found at ${CACHE_DIR} creating it now..."
mkdir -p "$CACHE_DIR"
chown "$SQUID_USER" "$CACHE_DIR"
$SQUID_CMD -z
fi
echo "Starting squid..."
$SQUID_CMD
}
stop() {
echo "Stopping squid..."
$SQUID_CMD -k shutdown
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment