LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 02-17-2010, 08:49 PM   #1
gr33d
Member
 
Registered: Dec 2008
Posts: 41

Rep: Reputation: 15
Question use /etc/init.d/squid to start both instances


ubuntu jaunty i386. i finally have two instances running on ports 3128 and 3129 on these two commands:

squid
squid -f /etc/squid/squid2.conf

i want both of these to start on boot. as far as i know, /etc/init.d/squid runs on boot (the port 3128 version), but i need the 3129 instance to run as well. should i somehow create another shell script that can automatically start this? (preferably on boot) im not very shell script savvy :/

thanks in advance!

more /etc/init.d/squid
Code:
#! /bin/sh
#
# squid         Startup script for the SQUID HTTP proxy-cache.
#
# Version:      @(#)squid.rc  2.20  01-Oct-2001  miquels@cistron.nl
#
### BEGIN INIT INFO
# Provides:          squid
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs $network
# Should-Start:      $named
# Should-Stop:       $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Squid HTTP Proxy
### END INIT INFO

NAME=squid
DAEMON=/usr/sbin/squid
LIB=/usr/lib/squid
PIDFILE=/var/run/$NAME.pid
SQUID_ARGS="-D -YC"

[ ! -f /etc/default/squid ] || . /etc/default/squid

. /lib/lsb/init-functions

PATH=/bin:/usr/bin:/sbin:/usr/sbin

[ -x $DAEMON ] || exit 0

grepconf () {
        w="     " # space tab
        sq=/etc/squid/squid.conf
        # sed is cool.
        res=`sed -ne '
                s/^'$1'['"$w"']\+\([^'"$w"']\+\).*$/\1/p;
                t end;
                d;
                :end q' < $sq`
        [ -n "$res" ] || res=$2
        echo "$res"
}

grepconf2 () {
        w="     " # space tab
        sq=/etc/squid/$NAME.conf
        # sed is cool.
        res=`sed -ne '
                s/^'$1'['"$w"']\+[^'"$w"']\+['"$w"']\+\([^'"$w"']\+\).*$/\1/p;
                t end;
                d;
                :end q' < $sq`
        [ -n "$res" ] || res=$2
        echo "$res"
}

#
#       Try to increase the # of filedescriptors we can open.
#
maxfds () {
        [ -n "$SQUID_MAXFD" ] || return
        [ -f /proc/sys/fs/file-max ] || return 0
        global_file_max=`cat /proc/sys/fs/file-max`
        minimal_file_max=$(($SQUID_MAXFD + 4096))
        if [ "$global_file_max" -lt $minimal_file_max ]
        then
                echo $minimal_file_max > /proc/sys/fs/file-max
        fi
        ulimit -n $SQUID_MAXFD
}

start () {
        cdr=`grepconf2 cache_dir /var/spool/$NAME`
        ctp=`grepconf cache_dir ufs`

        case "$cdr" in
                [0-9]*)
                        log_failure_msg "squid: squid.conf contains 2.2.5 syntax
 - not starting!"
                        log_end_msg 1
                        exit 1
                        ;;
        esac

        #
    # Create spool dirs if they don't exist.
    #
        if [ -d "$cdr" -a ! -d "$cdr/00" ] || [ "$ctp" = "coss" -a ! -f "$cdr" ]
        then
                log_warning_msg "Creating squid cache structure"
                $DAEMON $SQUID_ARGS -z
        fi

        if [ "$CHUID" = "" ]; then
                CHUID=root
        fi

        maxfds
        umask 027
        start-stop-daemon --quiet --start \
                --pidfile $PIDFILE \
                --chuid $CHUID \
                --exec $DAEMON -- $SQUID_ARGS < /dev/null
        return $?
}

stop () {
        PID=`cat $PIDFILE 2>/dev/null`
        start-stop-daemon --stop --quiet --pidfile $PIDFILE --name squid
        #
        #       Now we have to wait until squid has _really_ stopped.
        #
        sleep 2
        if test -n "$PID" && kill -0 $PID 2>/dev/null
        then
                log_action_begin_msg " Waiting"
                cnt=0
                while kill -0 $PID 2>/dev/null
                do
                        cnt=`expr $cnt + 1`
                        if [ $cnt -gt 24 ]
                        then
                                log_action_end_msg 1
                                return 1
                        fi
                        sleep 5
                        log_action_cont_msg ""
                done
                log_action_end_msg 0
                return 0
        else
                return 0
        fi
}

case "$1" in
    start)
        log_daemon_msg "Starting Squid HTTP proxy" "squid"
        if start ; then
                log_end_msg $?
        else
                log_end_msg $?
        fi
        ;;
    stop)
        log_daemon_msg "Stopping Squid HTTP proxy" "squid"
        if stop ; then
                log_end_msg $?
        else
                log_end_msg $?
        fi
        ;;
    reload|force-reload)
        log_action_msg "Reloading Squid configuration files"
        $DAEMON -k reconfigure
        ;;
    restart)
        log_daemon_msg "Restarting Squid HTTP proxy" "squid"
        stop
        if start ; then
                log_end_msg $?
        else
                log_end_msg $?
        fi
        ;;
    status)
       status_of_proc -p "$PIDFILE" "$DAEMON" squid && exit 0 || exit $?
        ;;
    *)
        echo "Usage: /etc/init.d/$NAME {start|stop|reload|force-reload|restart|s
tatus}"
        exit 3
        ;;
esac

exit 0
 
Old 02-18-2010, 08:03 AM   #2
jvaldivia
Member
 
Registered: Sep 2007
Distribution: Debian Lenny
Posts: 61
Blog Entries: 2

Rep: Reputation: 19
There is a section called start)

on that section a line that starts squid (3128)

--exec $DAEMON -- $SQUID_ARGS

I will just add another lines right after the one already mention, lets say:

start-stop-daemon --quiet --start \
--pidfile $PIDFILE2 \
--chuid $CHUID2 \
--exec $DAEMON2 -- $SQUID_ARGS2 < /dev/null

NOtice the change on the variables SQUID_ARGS2 and so on.

on Stop Section at the beginning:


PID2=`cat $PIDFILE 2>/dev/null`
start-stop-daemon --stop --quiet --pidfile $PIDFILE2 --name squid2
sleep 2

At the very beginning of the script when DAEMON exists add the other variables used:

$DAEMON2=/path
$SQUID_ARGS=the other squid definitions
 
Old 02-24-2010, 10:41 AM   #3
gr33d
Member
 
Registered: Dec 2008
Posts: 41

Original Poster
Rep: Reputation: 15
beautiful. one typo at the end of your post--the new SQUID_ARGS variable is SQUID_ARGS2, and it works perfect!

thanks!
 
Old 02-24-2010, 02:34 PM   #4
jvaldivia
Member
 
Registered: Sep 2007
Distribution: Debian Lenny
Posts: 61
Blog Entries: 2

Rep: Reputation: 19
I'm glad you have it working now !!
 
  


Reply

Tags
shell script, squid


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Init script in /etc/init.d does not start at boot tdnnash25 Linux - Server 4 12-18-2009 04:40 PM
Squid multiple instances log problem Shwick Linux - Server 1 01-01-2009 10:08 PM
please help me. everytime i log in kde4.1 many instances of kate start up.:( rd1381 Linux - Software 3 09-05-2008 06:41 AM
Start two instances of a program simultaneously using bash Daws Linux - General 5 05-26-2007 12:54 PM
How do you determine the number of NFS instances to start? BrianK Linux - Networking 6 10-26-2004 05:23 AM


All times are GMT -5. The time now is 02:53 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration