startup script for different linux versions

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...
LVL 3
raj_nbrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mikelfritzCommented:
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
raj_nbrAuthor Commented:
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
mikelfritzCommented:
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

raj_nbrAuthor Commented:
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
mikelfritzCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mikelfritzCommented:
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
raj_nbrAuthor Commented:
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
raj_nbrAuthor Commented:
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
raj_nbrAuthor Commented:
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
raj_nbrAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Distributions

From novice to tech pro — start learning today.