How to start a program automaticaly at boot?

I would like to start squid service at boot.

Although squid service is turned on

chkconfig squid
squid  on

it takes full three minutes to start squid proxy after the login. That means waiting three minutes before I can get access to Internet.

Instead of waiting for three minutes, I usually start squid manually as follows:

boris@DC7100:~> su
DC7100:/home/boris # service squid start
Starting WWW-proxy squid                                             done
DC7100:/home/boris #

Can I automate this, so that (see below) is always executed at startup, or when I start FireFox?

service squid start

And of course, how to do that?

Thanks in advance,

You can start it up when system started.
Yast -> System -> System Services(Runlevel)

But i m not sure, that squid will be there or not. Just give it a try.

Thanks for the suggestion.

Squid is already there, and it is enabled. But that is not the issue.

Actually squid starts automatically at boot, only 3 minutes after the login screen. That is unacceptable, I just can’t wait 3 minutes each time before I get access to Internet.

I don’t know why it takes so long, and I don’t really care. As a workaround, I would like that flowing is executed immediately after login.

service squid start

I’m doing this manually, and I’m getting tired of starting up terminal window and typing this each time, over and over again.
(Besides my girlfriend does not know the root password, so she must wait 3 minutes before she can start using FireFox).

Can I write something in .bashrc that does this for me?

Try putting the command in /etc/init.d/boot.local

OK, I tried starting squid from /etc/init.d/boot.local

Did it work? Yes and no!

Squid is now started (on time as I asked for:)), still FireFox is not able to open any page. It keeps endlessly loading, but nothing happens:(.

Unless I restart squid, FireFox can’t open any page.

service squid restart

In /etc/init.d/boot.local, there is a line that says:

Here you should add things, that should happen directly after booting

before we’re going to the first run level.

Probably, starting squid that early (before run level 1) is not effective.

I suppose that ideal time to start squid is after the wireless connection is established, which happens after I unlock the keyring (WEP code is locked by the keyring).
Is there a way to lock/unlock squid service with keyring as well?

by putting squid in boot.local it is started before your network and apache are up, thus it won’t work as boot.local executes stuff before network service is up and squid needs to be started after network is up and after apache is up

Not sure about your strange bahavior of squid. Works here without such a long delay. I don’t see anything wrong with the bootscript of squid that can cause such a delay

@blnl: You haven’t explained what kind of network connection you have, whether it’s made with ifup or by networkmanager. Squid really works best with a fixed IP connection. If you are going to be running it on a machine with a dynamic IP assignment, then you need to start it after the connection has been made and DNS resolution is available.

Putting this line in the root crontable will do it:

@reboot sleep 10;service squid restart

You might have to adjust the 10. It’s an inelegant but effective, efficacious and extremely easy expediency rotfl!

@ken_yap: My network connection is made by the Network Manager (IP obtained by DHCP). My modem is running DHCP server, but the IP addresses are fixed to MAC addresses. So, in fact each PC gets a fixed IP address. However, the network will connect only after the keyring pasword is entered (somehow my WEP key got into the keyring, and I never succeded in fixing this).

@swerdna: What is a “root crontable”?
Sorry, I’m new to Linux.:slight_smile:

Have a look at this tutorial: Cron Tables (Crontab) in Suse / openSUSE [Event Scheduler for 10.x, 11.x]

A cron table is a table of entries for tasks you want to have performed, at regular intervals or upon booting. A root cron table performs the tasks in the name of the root user. A standard cron table perofrms the task in the name of the user who owns the table (it’s a text file). The line of code I wrote says essentially: “at boot time, wait 10 seconds and then restart the squid service as root”.

Ok, what you might want to do is have the interface up event trigger the starting of the squid service so that the network and DNS are ready and squid doesn’t hang because of unavailability of those.

Unfortunately this is an advanced topic, but what you have to do is to write a script to go into /etc/sysconfig/network/if-up.d. There are a couple of existing scripts there you can use as a guideline. The script receives the interface name as the second argument so you make it check for the right interface before you do anything.

A corresponding down script can be put in /etc/sysconfig/network/if-down.d as you would expect. In fact the same script can be two-faced, by having it check its own pathname and doing the up action or the down action depending. That’s why the existing scripts are actually symlinks to the actual script in /etc/sysconfig/network/scripts/.

Thank you all for these useful suggestions.

Crontable sounds as a nice workaround. First I’ll try using the crontable for starting squid service, until I learn how to write a script with interface up event trigger (which seems as more elegant solution).