#!/sbin/sh # . /lib/svc/share/smf_include.sh # # Because we depend on repository properties (and hence on knowing our # service's FMRI) to locate the squid instance, we exit with ERR_NOSMF # if we're not run via the restarter. # if [ -z "$SMF_FMRI" ]; then echo "Squid startup script must be run via the SMF framework" exit $SMF_EXIT_ERR_NOSMF fi # # Figure out where squid is installed by querying the repository # SQUID_HOME=`svcprop -p squid/homedir $SMF_FMRI` [ $? != 0 ] && exit $SMF_EXIT_ERR_CONFIG # # Allow admin to specify an optional squid/conffile property; otherwise, # squid.conf is assumed to be in $SQUID_HOME/etc/squid.conf. # CONF_FILE=`svcprop -p squid/conffile $SMF_FMRI 2>/dev/null` [ $? != 0 ] && CONF_FILE=$SQUID_HOME/etc/squid.conf PATH=$SQUID_HOME/sbin:/bin:/usr/bin export PATH [ ! -f $CONF_FILE ] && exit $SMF_EXIT_ERR_CONFIG case "$1" in start) # # Check validity of the conf file; this lets us # cleanly go to maintenance on configuration errors. # squid -f $CONF_FILE -k parse if [ $? != 0 ]; then echo Validation of $CONF_FILE failed; check for syntactic \ errors and see previous messages. exit $SMF_EXIT_ERR_CONFIG fi # # A dirty hack; it would be extremely helpful if squid had an # option to tell us the cache dir. Anyway, grovel the .conf file # to work out the cache directory. If not present, then default to # $SQUID_HOME/var/cache, which is what squid seems to use as its # default. # CACHE_DIR=`egrep '^[ \t]*cache_dir' $CONF_FILE | \ awk '{print $3}'` [ -z "$CACHE_DIR" ] && CACHE_DIR=$SQUID_HOME/var/cache if [ ! -d $CACHE_DIR ]; then echo $0: admin must mkdir cache root directory \(believed \ to be $CACHE_DIR\) and set permissions exit $SMF_EXIT_ERR_CONFIG fi # # Use squid -z to create the cache directory hierarchy if it doesn't # exist. This is a convience. # if [ ! -d $CACHE_DIR/00 ]; then echo $0: creating cache directories at $CACHE_DIR squid -f $CONF_FILE -z if [ $? != 0 ]; then echo $0: cache directory creation failed! exit $SMF_EXIT_ERR_CONFIG fi fi # # Start squid, allowing it to daemonize. # squid -f $CONF_FILE -sY ;; stop) squid -f $CONF_FILE -k shutdown ;; *) echo "Usage: $0 {start|stop}" exit 1 ;; esac