Solved

startup script for different linux versions

Posted on 2008-06-23
10
2,335 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
ID: 21852461
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
ID: 21853436
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
ID: 21856225
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
ID: 21856574
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
ID: 21857265
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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 14

Expert Comment

by:mikelfritz
ID: 21857369
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
ID: 21869234
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
ID: 21869464
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
ID: 21875689
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
ID: 21894974
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Users are often faced with high disk consumption without really knowing where the largest amount of data resides. Disk Usage Analyzer (aka Baobab) is is a graphical, menu-driven application to analyse disk usage in any Gnome environment and can e…
1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 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

15 Experts available now in Live!

Get 1:1 Help Now