- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Run shell script before server shutdown and after ...
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
Forums
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
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
тАО01-02-2008 07:06 AM
тАО01-02-2008 07:06 AM
/u01/stop_tuxedo.sh
/u01/start_tuxedo.sh
Thanks,
Gulam.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-02-2008 08:42 AM
тАО01-02-2008 08:42 AM
SolutionA lot of samples you will find in /etc/rc.d/init.d, you can use one as template.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-02-2008 11:59 AM
тАО01-02-2008 11:59 AM
Re: Run shell script before server shutdown and after startup.
the scripts should be located in /etc/init.d instead of /etc/rc.d/init.d and /etc/rc0.d instead of /etc/rc.d/rc0.d respectively.
The simplest possible script would be something like this:
#!/bin/sh
case "$1" in
start)
/u01/start_tuxedo.sh
;;
stop)
/u01/stop_tuxedo.sh
;;
*)
echo "Usage: $(basename $0)
;;
esac
Save the above script as /etc/init.d/tuxedo, then set it executable with
chmod a+x /etc/init.d/tuxedo
Then find the correct runlevel used by your distribution. It's typically 3 or 5: the exact meaning of various runlevels depends on your distribution, but runlevel 0 means "shut down and halt/power-off the system", 1 is "go to single user mode" and 6 is "shut down and restart".
Look into the file /etc/inittab. In it, you'll find a line like this:
id:3:initdefault:
The number identifies the system's default runlevel (3 in this case).
To make your script a part of normal system startup & shutdown, you'll need to add two symbolic links. If your default runlevel is 3, you'll need to add the startup link to directory /etc/rc3.d; if 5, then use directory /etc/rc5.d instead.
To add the startup link as the last action of startup of runlevel 3:
ln -s /etc/init.d/tuxedo /etc/rc3.d/S99tuxedo
(S means "start", 99 causes this script to be run after all the other actions. The main runlevel-change script runs your script with a command line like "/etc/init.d/tuxedo start")
To add the shutdown link as the first action of the shutdown procedure, you must add it to both /etc/rc0.d and /etc/rc6.d:
ln -s /etc/init.d/tuxedo /etc/rc0.d/K01tuxedo
ln -s /etc/init.d/tuxedo /etc/rc6.d/K01tuxedo
(K means "kill": it makes the main runlevel-change script to run your script with a command line like "/etc/init.d/tuxedo stop".)
Instead of making the symbolic links manually, you can usually use some tool to automatically add your script to the startup/shutdown configuration. If you're running RedHat or Fedora, there should be a nice tool named "chkconfig": read its man page for more information.
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-02-2008 05:16 PM
тАО01-02-2008 05:16 PM
Re: Run shell script before server shutdown and after startup.
The first is a commented section that allows the script to be managed by the chkconfig tool. Here is an example:
#!/bin/bash
#
# chkconfig 345 10 90
# description This is where you put a description of your service
In this example, the numbers 345 after the chkconfig directive represent the runlevels that the service will be enabled for by default. In this example the service will be enabled by default for runlevels 3, 4, and 5.
The 10 is the start priority. The lower the number the higher the priority and the sooner a service will be started. The 90 is the stop priority. The lower the number the higher the priority and the sooner a service will be stopped when changing runlevels.
The second essential component is that the script must support being called with the arguments "start" and "stop." The script will be called with "start" as an argument when the service is being started at a given runlevel and "stop" when it is being stopped. Within these functions the script should touch a lock file in the /var/lock/subsys/ folder. If this is not done, the script will automatically start, but will not stop automatically. This should be done in the following manner:
start() {
...
touch /var/lock/subsys/servicename
}
stop() {
...
rm -f /var/lock/subsys/servicename
}
Once you have created a script that conforms to these two requirements, place a copy of it into the /etc/init.d/ directory and execute the command:
chkconfig --add servicename
This will register the service and create the necessary links in the appropriate rcX.d directories. You can now administer this service using chkconfig command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-03-2008 01:39 AM
тАО01-03-2008 01:39 AM
Re: Run shell script before server shutdown and after startup.
You could integrate these scripts into an existing deamon start/stop.
Edit a script in /etc/init.d
Better.
Put the scripts in a fresh script in /etc/init.d
Usually I copy cron as a template.
Then in /etc/rc#.d (# is number) softlink to the script in /etc/init.d If it starts with an S it runs at startup
If it starts with a K it runs at shutdown.
Case sensitive, small letters will do nothing.
example:
cd /etc/rc5.d
ln -s /etc/init.d/myscript S90myscript
cd /etc/rc4.d
ln -s /etc/init.d/myscript K10myscript
The above example runs the start/strop script /etc/init.d/myscript in start mode at run level 5 and stop(kill) mode at run level 4.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-03-2008 03:39 AM
тАО01-03-2008 03:39 AM
Re: Run shell script before server shutdown and after startup.
place the startup script in /etc/rc.local
and you can shutdown the server using the script.