5.6 Boot Scripts

Most likely, you'll want Squid to start automatically every time your computer boots. Different operating systems vary widely in how their boot-up scripts work. I'll describe some common environments here, but you may need to refer to your particular operating system for specific information.

5.6.1 /etc/rc.local

One of the easiest schemes is the /etc/rc.local script. This is simply a shell script that runs as root each time the system boots. Using this script to start Squid is as easy as adding the following line:

/usr/local/squid/sbin/squid -s

Of course your installation prefix may be different, and you may like to use some other command-line options. Don't use the -N option here.

If, for some reason, you're not using the cache_effective_user directive, you can try using su to start Squid as a non-root user:

/usr/bin/su nobody -c '/usr/local/squid/sbin/squid -s'

5.6.2 init.d and rc.d

The init.d and rc.d schemes use a separate shell script to start different services. These scripts are often located in one of the following directories: /sbin/init.d, /etc/init.d, and /usr/local/etc/rc.d. The scripts usually take a single command-line argument, which is either start or stop. Some systems only use the start argument. Here's a basic script for starting Squid:



# this script starts and stops Squid

case "$1" in


          /usr/local/squid/sbin/squid -s

          echo -n ' Squid'



          /usr/local/squid/sbin/squid -k shutdown



Linux users may want to add commands that set the file-descriptor limits before running Squid. For example:

echo 8192 > /proc/sys/fs/file-max

limit -HSn 8192

To use this script, find the appropriate directory in which such scripts are stored. Give it a meaningful name, similar to the others. Perhaps S98squid or simply squid.sh. Be sure to test the script by rebooting your computer rather than assuming it will work.

5.6.3 /etc/inittab

Another scheme supported on some operating systems is the /etc/inittab file. On these systems, the init process starts and stops services based on the run level. A typical inittab entry looks like this:

sq:2345:once:/usr/local/squid/sbin/squid -s

With this entry, the init process starts Squid just once and then forgets about it. Squid makes sure it stays running as described previously. Alternatively, you can do it like this:

sq:2345:respawn:/usr/local/squid/sbin/squid -Ns

Here, since we use the respawn option, init restarts Squid if the process exits. If you use respawn, be sure to use the -N option.

After editing the inittab file, use this command to make init reread its configuration file and start Squid:

# init q

    Appendix A. Config File Reference