- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- How to add scripts in Linux system start and shutd...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-17-2008 11:39 AM
тАО12-17-2008 11:39 AM
I got a task, setup OEM agent start and stop scripts into Linux system start/stop process, let Linux system automatic run OEM start script after system boot up and automatic run OEM stop script before system shutdown or reboot.
How to do that?
There are over 10 RHEL AS 4 update 6 servers installed oracle DB and OEM agnent.
I just know RH linux start script in /etc/rc.d/rc and /etc/rc.d/init.d ... where is stop script and how to accomplish my goal?
Any answers will be very appreciate.
-G
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-17-2008 01:06 PM
тАО12-17-2008 01:06 PM
SolutionThe files in /etc/rc#.d/ are links to these scripts, in most cases.
Basically, you create a script in /etc/init.d/ with start and stop options.
To have your script start, (run level 3, for ex.), create a symbolic link in /etc/rc3.d:
- cd /etc/rc3.d/
- ln -s ../init.d/scriptname S##scriptname
the rc script will start all scripts with a capital S in numerical order.
The shutdown portion is similar. Go to the run level that you want to shutdown at:
- cd /etc/rc3.d/
- ln -s ../init.d/scriptname K##scriptname
the rc script will shutdown all scripts with a capital K in numerical order.
Hope this helps,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-17-2008 01:07 PM
тАО12-17-2008 01:07 PM
Re: How to add scripts in Linux system start and shutdown scripts?
Thanks a lot for your fast reply and good answers.
Have a good day.
-Gary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-17-2008 01:31 PM
тАО12-17-2008 01:31 PM
Re: How to add scripts in Linux system start and shutdown scripts?
One question for you, whether run level 3 just a command line xterm mode and run level 5 we could have GUI interface X? If so, if I wanna set system auto run the S script when system boot up to both run level 3 and 5 and auto run the K script before system shutdown/reboot at both run level 3 and 5, do I need set the link #ln in rc3.d and rc5.d?
As we know run-level 0 is halt, 6 is reboot, for K shutdown script, do I need set it in rc0.d and rc6.d.
Thank a lot.
-Gary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-17-2008 01:56 PM
тАО12-17-2008 01:56 PM
Re: How to add scripts in Linux system start and shutdown scripts?
You should create one combined startup/shutdown script, so that the script will start up the application when called with a command like:
<scriptname> start
and stop it when called with:
<scriptname> stop
This script must be placed in /etc/init.d.
After this, you must create symbolic links as Autocross.US described.
NOTE: in RHEL, there is a nice little "chkconfig" tool that helps in creating/deleting/changing the symbolic links. It requires that you put two specially-formed comment lines in your application startup/shutdown script:
# chkconfig: 345 80 20
# description: some text describing your app
The numbers on the chkconfig line:
- The first number (345) is a list of runlevels you'll want your application to run. 3 is the standard runlevel when running without GUI on the console, 5 is with the X Window System GUI. 4 is a "spare" runlevel you can define yourself if you need a special mode for your system. It is not used by default, but the convention is to keep it configured about the same as runlevels 3 and 5.
- 80 is the "starting position" number, meaning that this application will be started rather late in the boot process. You should choose this number according to the needs of your application: if you try to make the application start too early, all disks may not be mounted yet, network adapters might not be initialized or some system services might not be started yet.
- 20 is the "shutdown order" number. Unless your application has special requirements, it is recommended that the sum of startup and shutdown order numbers for each application should be 100.
When you have added the two "magic" comment lines to your startup/shutdown script, just place the script to /etc/init.d and run:
chkconfig --add <scriptname>
If you need to temporarily block the system from starting/stopping the application automatically, you can use:
chkconfig <scriptname> off
To restore the auto-start function, use:
chkconfig <scriptname> on
If you want your script to display a cool green OK message at startup and shutdown, your script should use certain pre-defined functions (this is RedHat only; other Linux distributions may do things very differently). There is usually an example script "skeleton" named /etc/init.d/skel; make a copy of it and flesh it out.
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-17-2008 02:20 PM
тАО12-17-2008 02:20 PM
Re: How to add scripts in Linux system start and shutdown scripts?
That's great!
Thank you very very much for your above detail explanations, include: chkconfig: 345 80 20, example skel ...
I will try it soon.
Thanks a again.
Have a good day.
-Gary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-17-2008 02:33 PM
тАО12-17-2008 02:33 PM
Re: How to add scripts in Linux system start and shutdown scripts?
Question for you,
I havn't found the example script that you metioned above. I didn't find any /etc/init.d/skel and skeleton. In HP-UX skel is a directory for setting normal user's profile etc... not a executable script.
Any comments?
But anyway, I could find another in /etc/init.d.
Thanks a lot.
-Gary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2008 12:46 AM
тАО12-18-2008 12:46 AM
Re: How to add scripts in Linux system start and shutdown scripts?
Skel is something that describe how the basics of something works.
Skel in user handling just tells us how the users environment should look when we create a user.
A init.d skel file would have "examples" that show you how to write the basics of a startup script or atleast enough for you to copy and then modify it in a way you seem fit.
When it comes to startup scripts pretty much every script in init.d looks the same.
And you're right above (didn't see any answers above). rc#.d is the runlevel. As Autocross described above you put your S##script and K##script in the rc#.d to set the runlevel.
So if you want to run it in both 3 and 5 you'd have to put in the ln in both. This thou would probably make it start twice unless you write some kind of support checking if the application exists.
Normally I usually write a pid file.
#!/bin/bash
/path/to/program & # Launch it to the background
pid=$!
echo "$pid" > /path/to/pids/program-$pid
This is a really simplistic version, normally you use "case" to make it start and stop. This also makes it easier to kill the process during your stop procedure :)
Hope I didn't rant too much again :P
Best regards
Fredrik Eriksson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2008 12:49 AM
тАО12-18-2008 12:49 AM
Re: How to add scripts in Linux system start and shutdown scripts?
See the directory /usr/share/doc/initscripts-
Note that the documentation file originates from the old RedHat Linux 7.0, but RedHat's startup script system has not changed much since then: only the old RedHat specialty of using the directory /etc/rc.d/init.d instead of /etc/init.d has been removed, just as described in the beginning of the file.
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2008 07:54 AM
тАО12-18-2008 07:54 AM
Re: How to add scripts in Linux system start and shutdown scripts?
Thanks a bunch for your all kindly help and detail explanation.
-Gary