Tuesday, March 16, 2010

How do I modify a service startup script so that chkconfig can manage in which runlevels it's active?

Problem

Not all scripts with start/stop/status options are manageable by chkconfig, but you can add a self-defined script into system service which can be handled by chkconfig.



Environment
Red Hat Enterprise Linux 3, 4, 5



Resolution

1. The script should adhere to the following requirements:

1) Indicates what shell is used to run the script.


2) Indicates which run level should the service be started by default as well as the start and stop priority levels. The start/stop priority levels are important for services that depend on other services.In the following 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 99 is the start priority. The lower the number the higher the priority and the sooner a service will be started. The 01 is the stop priority. The lower the number the higher the priority and the sooner a service will be stopped when changing runlevels.



3) A short description for the service. The description may extend up to several (commented) lines as necessary. Use the backslash character if the comment extends to several lines.


Below is an example of /etc/init.d/yourscript :


#!/bin/sh
#
# chkconfig: 345 99 01
#
# description: your script is a test service
#
case $1 in
start)
echo "your script starting"
# TODO:
;;
restart)
echo "your script stopping"
echo "your script starting"
# TODO:
;;
status)
echo "your script running"
# TODO:
;;
stop)
echo "your script stopping"
# TODO:
;;
esac
2. Make sure that the script is executable.


# chmod 0755 /etc/init.d/yourscript
3. Create a soft link to /etc/init.d/yourscript


If you want to start the service in runlevel 5:

# cd /etc/rc.d/rc5.d
# ln -s ../init.d/yourscript S99yourscript

If you want to start the service in runlevel 3:

# cd /etc/rc.d/rc3.d
# ln -s ../init.d/yourscript S99yourscript
4. Add the script to service


# chkconfig --add yourscript
5. Now, you can test this self-defined service


# service yourscript start
# service yourscript status
# service yourscript stop
6. If you want to yourscript started when system boot up


# chkconfig yourscript on

Finally, if you do not want to put yourscript into service, you can just call it from /etc/rc.d/rc.local.


# echo /etc/init.d/yourscript >> /etc/rc.d/rc.local


link--> http://kbase.redhat.com/faq/docs/DOC-7239

Monday, March 8, 2010

Start and stop applications with wsadmin
You can use wsadmin to start and stop applications in your application server.

Start applications with wsadmin
Stop applications with wsadmin
Start applications with wsadmin

To start an application with wsadmin, follow these steps:

On the OS/400 command line, run the STRQSH (Start Qshell) command.

Run the cd command to change to the directory that contains the wsadmin tool:

cd /QIBM/ProdData/WebASE/ASE5/bin
Start wsadmin.

At the wsadmin prompt, run this command to identify the application manager MBean for the server where the application resides and assign it the appManager variable:

set appManager [$AdminControl queryNames type=ApplicationManager,*]
This command returns the application manager MBean.

Run this command to start the application:

$AdminControl invoke $appManager startApplication myApp
where myApp is the name of the application that you want to start.

Stop applications with wsadmin

To stop applications with wsadmin, follow these steps:

On the OS/400 command line, run the STRQSH (Start Qshell) command.

Run the cd command to change to the directory that contains the wsadmin tool:

cd /QIBM/ProdData/WebASE/ASE5/bin
Start wsadmin.

At the wsadmin prompt, run this command to identify the application manager MBean for the server where the application resides, and assign it to the appManager variable:

set appManager [$AdminControl queryNames type=ApplicationManager,*]
This command returns the application manager MBean.

You can stop a single application or stop all of the applications that are running in your application server.

To stop a single application, run this command:

$AdminControl invoke $appManager stopApplication myApp
where myApp is the name of the application that you want to stop.

To stop all of the running applications in your application server, follow these steps:

Run this command to query the running applications in the application server and assign the result to the apps variable:

set apps [$AdminControl queryNames type=Application,*]
This command returns a list of application MBeans.

Run this command to stop all of the running applications:

foreach app $apps {set appName [$AdminControl getAttribute $app name];
$AdminControl invoke $appManager stopApplication $appName}
Note: This command has been wrapped for display purposes.