LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-12-2007, 04:24 PM   #1
Avatar
Member
 
Registered: May 2001
Location: Canada
Distribution: old ones
Posts: 555

Rep: Reputation: 33
Start 2 programs at boot time


Hello, I know this has been asked a bazillion times and I did several searches to that effect but I'm still foggy (hence why I'm posting in Newbie).

I'm running a server with Ubuntu Edgy (6.10).

I need to add two things to the startup sequence so that I don't have to do it manually every time the power goes off or the server gets rebooted.

1. Run my firewall script, located in /etc/init.d
2. Start the "pon" internet connection.

It absolutely MUST be in that order, if I start the connection first then run the firewall, none of the clients can connect. In fact, I would like to ensure it is done correctly by first running poff then pon again.

By searching LQ I have discovered the following things.

- that I must determine my runlevel (which is 2)
- that I must link my script in the /etc/rc2.d directory
- I must use the "man" command to determine how to do this exactly
- I must read the README file that is included in the rc2.d directory

So the readme has me all confused.

It seems to suggest that you can only run scripts that are in the specific /etc/init.d directory

Quote:
The scripts are all symbolic links whose targets are located in /etc/init.d/ .
I was all proud of myself for figuring out how to do my startup sequence without any help, but alas. It was not to be.

I need to start the pon program which is in /usr/bin and not in /etc/init.d - so how do I do this?

Additionally, how can I make sure pon is not already running, and if it is, disable it using poff, then run the firewall script, then run pon? I tried putting a link in my /etc/rc2.d that starts with K but it involves complicated math and I don't think it would work anyway seeing as how poff is located in /usr/bin as well.
 
Old 12-12-2007, 04:58 PM   #2
derxob
Member
 
Registered: Apr 2006
Location: Los Angeles, California
Distribution: Slackware, Ubuntu
Posts: 68

Rep: Reputation: 16
Quote:
It seems to suggest that you can only run scripts that are in the specific /etc/init.d directory

Quote:
The scripts are all symbolic links whose targets are located in /etc/init.d/ .
I was all proud of myself for figuring out how to do my startup sequence without any help, but alas. It was not to be.

I need to start the pon program which is in /usr/bin and not in /etc/init.d - so how do I do this?
Create a file in /etc/init.d/ called "run-pon"
Code:
touch /etc/init.d/run-pon
Open run-pon file
Code:
vi /etc/init.d/run-pon
Tell run-pon file to execute /usr/bin/pon
Code:
#!/bin/sh
/usr/bin/pon
Make run-pon file executable
Code:
chmod +x /etc/init.d/run-pon
Link the /etc/init.d/run-pon file to /etc/rc2.d/
Code:
ln -s /etc/init.d/run-pon /etc/rc2.d/S99run-pon
Hope this helps!

Last edited by derxob; 12-12-2007 at 04:59 PM.
 
Old 12-12-2007, 05:04 PM   #3
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
OK, any startup scripts in your /etc/rc*.d directories that start with K are run with the "stop" parameter. You need it to start with S so it will be run with the "start" parameter. Also, the number after the S or K is the order in which the scripts are run (starting with 01 up to 99).

To make the link for runlevel 2 run:

Code:
cd /etc/rc2.d
ln -s /etc/init.d/firewall S08firewall
(I chose S08 above because that is the order that my iptables script runs. You may want to make "08" something else.)

Also, how did you determine 2 was your default runlevel? Typically things are run at 3 or 5, but I'm not super up on my Ubuntu. Anyway, you probably also want to make the links for the other runlevels 3, 4, and 5 as well as the stop scripts (ln -s /etc/init.d/firewall K92firewall) for runlevels 0, 1, and 6. That way when you switch runlevels, it will run those scripts if they need to be run.

Also, not sure about Ubuntu, but Red Hat and Fedora have a tool, chkconfig that does all of this automatically.

The following script SHOULD work to start and stop your internet connection. I give it with no guarantee (but I'll be glad to look at it if it doesn't work and you supply feedback as to why). Put it in /etc/init.d and call it something (ispconnect ?). Then link it as you did firewall above but increment the number (in this case it would be 09).

Code:
#!/bin/sh
# See how we were called.
case "$1" in
  start)
        # Start daemon.
        echo -n $"Starting internet connection: "
        /usr/bin/pon
        ;;
  stop)
        # Stop daemon.
        echo -n $"Shutting down internet connection: "
        /usr/bin/poff
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart}"
        ;;
esac

exit
You will need to make the script executable:
Code:
chmod 755 /etc/init.d/ispconnect
HTH

Forrest

Last edited by forrestt; 12-12-2007 at 05:10 PM. Reason: Fixed path to pon and poff in script
 
Old 12-13-2007, 09:34 AM   #4
Avatar
Member
 
Registered: May 2001
Location: Canada
Distribution: old ones
Posts: 555

Original Poster
Rep: Reputation: 33
Wow, you guys. That was really awesome! I got two clear, detailed answers that I can understand and implement. Thanks very much, derxob and forrestt. I am really satisfied with both your answers.

Quote:
Also, how did you determine 2 was your default runlevel?
I literally typed "runlevel" at the command prompt. (I learned that trick yesterday while searching. You can also type "who -r"). This is a server only, not a desktop machine, so it doesn't have a GUI. I think that's was runlevel 2 means.

Forrestt: Can you tell me more about your script. It looks like it does the same thing as derxob's two line script. It is just curiosity on my part, but I wonder why use a complex script like that, what is the reason? is it better to use one type of script over the other? When I was looking in my init.d directory I noticed that most of the scripts are written that way.

Now with derxob's script, I would modify it slightly so that I could ensure pon wasn't already running, like so:

Code:
#!/bin/sh
/usr/bin/poff
< some command to make it wait a moment, like sleep 3 - I'll have to look it up >
/usr/bin/pon
Is there a way to do this with your type of script? or better yet, check to see first if there is a PID for pon or something?

Anyway, thanks again for your help, I really appreciate it.
 
  


Reply


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
Choosing programs that load at boot time DiBosco Linux - Software 4 02-13-2007 11:44 AM
Getting programs to start on boot? tmtd Linux - General 1 04-04-2006 11:37 AM
Adding programs to run during boot time JonnyW247 Linux - Software 1 02-05-2006 04:52 PM
start two programs at the same time. Brian1 Programming 16 01-01-2006 04:36 PM
GUI based interphase to start programs at boot time. softgun Debian 2 10-24-2003 02:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:52 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration