Solved

startup script for different linux versions

Posted on 2008-06-23
10
2,332 Views
Last Modified: 2013-12-06
I need to write a a script that inserts a line into startup script of linux machines. I am doing this as part of installation of a software developed by me. During installation, I need to make sure that the newly installed program is part of startup script, so that it gets started automatically when the system boots. This should happen, regardless of linux version or flavour. In red hat, I used to write a script to insert a line into /etc/rc.d/rc.local and it works fine.

Now, in Suse enterprise, rc.d folder is not there in etc folder. Instead of that, rc.d shortcut is available, which points to rc.init folder. In this folder again, rc.local file is not there. Instead, notmal rc.0, rc.1 rc.2 etc are available.

Now, what is the best method to make sure that my program is whenever linux starts up? In which script should I insert lines to call my executable during startup? If rc.d and rc.local are not available in the linux version, should I create the folders and files? (One site says I can create the folder/file)

Please guide...
0
Comment
Question by:raj_nbr
  • 6
  • 4
10 Comments
 
LVL 14

Expert Comment

by:mikelfritz
Comment Utility
http://www.novell.com/coolsolutions/feature/15380.html

Or just put your start script in /etc/rcX.d (filename Must start with upper case "S") where X is the runlevel of the system.  It won't hurt if you put/link it in all normal runlevels ie: /etc/rc2.d /etc/rc3.d /etc/5.d ... (3 and 5 are the most common)


Contents of /etc/rc3.d and or rc5.d:
/usr/bin/start_your_thing

0
 
LVL 3

Author Comment

by:raj_nbr
Comment Utility
Thanks Mike. Some clarifications..

1. Currently, I am doing it this way.

a.  installation script looks for rc.d folder
b. It then looks for rc.local script
c. It inserts a line in the script file, which calls my program. ie: I simple add a line. The line will be the name of the executable file (with path) with commandline arguments.

This works fine in Red hat. But in Suse, in some machines, rc.d is actually a link to a folder called init.d ie: rc.s folder as such does not exist. Inside init.d, there is no file with rc.local. ie: There is no file where I can insert the my program with commandline arguments.

As I mentioned earlier, I had found some information on net, which said that, in case the file does not exist, you can simply create a file called rc.local and then insert your commands inside. When system boots up, it will execute the rc.local file created by me, automatically.

But your suggestion is that,  the best method is to write a script file, and then simply copy it to rc5.d folder inside rc.d folder. ie: in suse, write a script file, and then simply copy it to rc5.d folder inside init.d folder, since rc.d is just a link to rc.d. Any script file, copied to rc5.d folder will automatically get executed when the system starts. If I add it to rc3.d folder also, then, even though the script is present in 2 folders, it will not get executed twice. Somehow it will only get executed once, and no harm will take place.

Am I right? Please confirm...

Thanking you again..



1. If I write a script file
0
 
LVL 14

Expert Comment

by:mikelfritz
Comment Utility
The number on the rcX.d folder coresponds to the run level the system boots to.  You can usually find out by looking in inittab.  The script would only get executed once.  If the system boots to run level 5 then it will process any scripts in /etc/rc.d/rc5.d and won't touch /etc/rc.d/rc3.d.  So you could write the script and link/copy it into all normal run levels and it will execute only once, but will work regardless of the run level.  Remember that the script name you write should follow the format:
"SXXscritpname"  upper case "S" is important,  XX is a number (lower numbers execute first, I normally use 99 to have it run near the end of the boot)

EX - for Redhat and SUSE the runlevels are: (note that 3 and 5 are the most likely)

#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:

SCO Openserver uses runlevel 2 by default, but the dir is /etc/rc2.d not /etc/rc.d/rc2.d

AIX 5.3 uses run level 2 by default and the dir is /etc/rc.d/rc2.d

0
 
LVL 3

Author Comment

by:raj_nbr
Comment Utility
Thanks again.
Actually, the requirement is to write an installation script, that copies the executables, and inserts the lines in the startupscript to run the exucutables at startup. Users who are going to use the software will not know about the runlevel. This code will be used to automate installations, by many users.

1. So is it required to check the run-level before deciding where to copy my script to? ie: Installation script must check the run-level first and then copy the autoexecution script to the right folder. Is this right?

2. I can name my script as I want and simply copy it to the rc5.d or whatever folder I need to copy it to - right? Name doesn't matter right? As long as the default runlevel is 5 , all scripts in this folder will be run, right?

3. I again got a suggestion that, the best way to do this is to insert the code in rc.local file since it would always be executed. I was informed that, if that file was not there, then I can simply create a file with name rc.d and insert the line that calls my executable. Could you comment on this please.

Thanks again
0
 
LVL 14

Accepted Solution

by:
mikelfritz earned 250 total points
Comment Utility
1. You should not need to check the run level.  just create a startup script and link/copy it to both /etc/rc.d/rc3.d and /etc/rc.d/rc5.d  

2.  The name MUST start with upper case S then a two digit number - use 99 - then some unique name like this

S99rajstart

init will only process the script if it starts with a "S" and the number determines the order in which they run.

3.  Sounds like it might work, but I don't know if all flavors will process a rc.local - however all will process the rcX.d folders.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 14

Expert Comment

by:mikelfritz
Comment Utility
who -r will give you the current run level if you want to check it and then only put the script in the dir for the runlevel.
0
 
LVL 3

Author Comment

by:raj_nbr
Comment Utility
Just a clarification

1. I  copied the script to rc3.d and rc5.d.  Runlevel was found to be 5 when I used who -r
2. The name of the script is S99scadamonitor. The script has just one line

/etc/local/scada/scmon 2 3 40

scmon is the program and 2 3 40  are command line arguments.

3. I can click on the scipt and the script executes fine. It works in terminal mode also. The program starts normally and forks into memory as a background process.
4. But, the script doesn't get executed during startup !!! (suse enterprise)
5. If I insert "/etc/local/scada/scmon 2 3 40" in rc.local in Redhat 9, it gets executed during bootup.

Where  do you think is the mistake?
0
 
LVL 3

Author Comment

by:raj_nbr
Comment Utility
Guess I haven't mentioned the shell to be used to execute the script. Haven't corrected it, but then hope that is the reason. It works in rc.local since it has a shell line existing already..
0
 
LVL 3

Author Comment

by:raj_nbr
Comment Utility
It is not executing my script!!!!

Is there a possibility that the system is configured not to execute the scripts in rc5.d and rc3.d ? I tried starting the file with S25 instead of S99 since the last script was starting with S24, but it didnt help..
0
 
LVL 3

Author Comment

by:raj_nbr
Comment Utility
Anyway, after lot of research, I found a decent way to automate the start-up.

1. Check the linux flavor. If it is suse, the insert the code in bood.local, else insert it in rc.local
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now