Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
SMS Forum Index » Suggestions

Post new topic   Reply to topic
rc.squid
View previous topic :: View next topic  
Author Message
keopp
Senior Member


Joined: 08 Nov 2008
Posts: 155
Location: Romania

PostPosted: Sat Mar 28, 2009 11:49 am    Post subject: rc.squid Reply with quote

Hello.
I really like SMS and want it continoussly improved.

Squid is a very powerfull and usefull tool and needs a init script.
I propose the following rc.squid, found during my google trips:

Code:

#!/bin/sh
#
# Slackware Startup Script for Squid
# ----------------------------------
#
# Written by:  Marco A. Frias B. <marcofrias@linuxpackages.net>
#
# Changelog:
#
# 0.1: 14/Sep/2008 by Marco A. Frias B. <marcofrias@linuxpackages.net>
#      * Initial write Script.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Based on Startup Script written by:
#   Frank Bodammer, Peter Poeml, Klaus Singvogel <feedback@suse.de>
#   David Somero <xgizzmo@slackbuilds.org>
#
# NOTE:
#      This script can be run directly from a root command shell, using:
#
# # /etc/rc.d/rc.squid start
# or
# # /etc/rc.d/rc.squid stop
#
# For automatic startup, it should be added to /etc/rc.d/rc.local. A sample
# startup line:
#
# if [ -x /etc/rc.d/rc.squid ]; then
#   /etc/rc.d/rc.squid start
# fi
#
# For automatic shutdown, it should be added to /etc/rc.d/rc.local_shutdown. A
# sample startup line:
#
# if [ -x /etc/rc.d/rc.squid ]; then
#   /etc/rc.d/rc.squid stop
# fi
#

DAEMON=/usr/sbin/squid
CFGFILE=/etc/squid/squid.conf
PIDFILE=/var/run/squid.pid
PID=-1

# Only start if we can find the daemon.
if [ ! -x $DAEMON ] ; then
  echo "Squid is not installed correctly." >&2
  exit 1
fi

check_run() {
  if [ -f "$PIDFILE" ]; then
    read LINE < "$PIDFILE"
    [ -z "${LINE//[0-9]/}" -a -d "/proc/$LINE" ] && PID="$LINE"
    if [ -n "$PID" ]; then
      return 0
    fi
    return 1 # Squid is dead and /var/run pid file exists
  fi
  return 3 # Squid is not running
}

start() {
  # See if it's already running. Look *only* at the pid file.
  check_run
  case $? in
   0)
    echo "Squid (pid $PID) is running..."
    exit 0
    ;;
   1)
    echo "Squid is dead but pid file exists..."
    exit 1
    ;;
  esac

  # determine which one is the cache_swap directory
  CACHE_SWAP=$(awk '/^cache_dir/ {print $3}' $CFGFILE)
  [ -z "$CACHE_SWAP" ] && CACHE_SWAP=/var/cache/squid

  for cachedir in $CACHE_SWAP; do
    if [ ! -d $cachedir/00 ]; then # create missing cache directories
      echo "Creating swap directories in $cachedir"
      $DAEMON -z -F > /dev/null 2>&1
    fi
  done

  sleep 2
  echo -n "Starting Squid: "
  $DAEMON -DF
  if [ $? -eq 0 ]; then
    echo "ok"
  else
    echo "failed"
  fi
}

stop() {
  # See if it's already running. Look *only* at the pid file.
  check_run
  case $? in
   1)
    echo "Squid is dead but pid file exists..."
    exit 1
    ;;
   3)
    echo "Squid is not running..."
    exit 0
    ;;
  esac

  COUNTDOWN=$(awk '/^shutdown_lifetime/ {print $2}' $CFGFILE)
  [ -z "$COUNTDOWN" ] && COUNTDOWN=30

  echo -n "Shutting down Squid in $COUNTDOWN seconds: "
  $DAEMON -k shutdown

  while [ $COUNTDOWN -gt 0 ]; do

    $DAEMON -k check 2> /dev/null
    if [ $? -ne 0 ]; then
      break
    fi

    sleep 1
    echo -n "."
    COUNTDOWN=`expr $COUNTDOWN - 1`
  done
  echo ""
}

restart() {
  stop
  sleep 1
  start
}

reload() {
  # See if it's already running. Look *only* at the pid file.
  check_run
  case $? in
   1)
    echo "Squid is dead but pid file exists..."
    exit 1
    ;;
   3)
    echo "Squid is not running..."
    exit 0
    ;;
  esac

  echo -n "Reloading Squid: "
  $DAEMON -k reconfigure
  if [ $? -eq 0 ]; then
    echo "ok"
  else
    echo "failed"
  fi
}

status() {
  # See if it's already running. Look *only* at the pid file.
  check_run
  case "$?" in
   0)
    echo "Squid (pid $PID) is running..."
    exit 0
    ;;
   1)
    echo "Squid is dead but pid file exists..."
    exit 1
    ;;
   3)
    echo "Squid is not running..."
    exit 0
    ;;
  esac
}

# Parse command line parameters.
case $1 in
start)
  start
  ;;
stop)
  stop
  ;;
restart)
  restart
  ;;
reload)
  reload
  ;;
status)
  status
  ;;
*)
  # Print help
  echo "Usage: $0 {start|stop|restart|reload|status}" 1>&2
  exit 1
  ;;
esac

exit 0
Back to top
View user's profile Send private message
gerasimos_h
Site Admin


Joined: 09 Aug 2007
Posts: 1743
Location: Greece

PostPosted: Sat Mar 28, 2009 12:29 pm    Post subject: Reply with quote

There is already an rc.scipt posted here quite simpler than yours.
I'll test it, thanks.

gerasimos_h

_________________
Superb! Mini Server Project Manager
http://sms.it-ccs.com
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    SMS Forum Index » Suggestions All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

SMS - Superb! Mini Server Project © 2016
Powered by phpBB © 2001, 2002 phpBB Group
iCGstation v1.0 Template By Ray © 2003, 2004 iOptional