• The main start/stop script goes into /etc/init.d (Redhat, this could be little different on other variants of Unix.
  • Functions that can be used can be found in /etc/init.d/functions
  • Use chkconfig –add <script name>
  • Use chkconfig –list <script name> to check if it’s added and start levels set
  • Use chkconfig –del <script name> to delete
  • man chkconfig for further options or information
  • Please see example below for machine-1, where we are trying to start/stop NM, AdminServer and then the managed server(s)

 

[root@machine-1 ~]# cd /etc/init.d/
[root@machine-1 init.d]# cat auto-wls
#!/bin/bash
#
# Copy this file to /etc/init.d/ (or /etc/rc.d/init.d/ depending on your system) and activate it as such:
# On RedHat, and derivatives, install with "chkconfig --add auto-wls"
# Description: WLS auto start/stop script
# chkconfig: 35 99 12
# This  says  that  the  random  script  should  be  started in levels 3,5, that its start priority should be 99, and that its stop priority should be 12
# Define run level if you wish "chkconfig  auto-wls  --level 3,4,5"
# Check if it's added and it's levels "chkconfig --list auto-wls"
# Delete if not needed "chkconfig --del auto-wls"
# Supported functions "/etc/init.d/functions"

RETVAL=0
# "start" function
start () {
su - oracle -c "/home/oracle/wls-auto-start.sh"
return $RETVAL
}

# "stop" function
stop () {
su - oracle -c "/home/oracle/wls-auto-stop.sh"
return $RETVAL
}
# main case statement
case "$1" in
  'start')
        start
        ;;
  'stop')
        stop
        ;;
  '*')
        echo "Usage: "$0' (stop|start)'
                exit 1
        ;;
esac
exit $?
[root@machine-1 init.d]# chkconfig --add auto-wls
[root@machine-1 init.d]# chkconfig --list auto-wls
auto-wls        0:off   1:off   2:off   3:on    4:off   5:on    6:off

[root@machine-1  init.d]# ls -lrt
....
....
-rwxr-xr-x  1 root      root          3488 Jul 12 12:04 httpd
-rwxr-xr-x  1 root      root          2001 Jul 12 12:04 htcacheclean
-rwxr-xr-x  1 root      root          1027 Dec  8 15:32 auto-wls
[root@machine-1  init.d]#
[root@machine-1 init.d]# ls -lrt /home/oracle/wls-auto*
-rwx------ 1 oracle oinstall 507 Dec  8 12:38 /home/oracle/wls-auto-stop.sh
-rwx------ 1 oracle oinstall 522 Dec  8 12:53 /home/oracle/wls-auto-start.sh

Example stop script: wls-auto-stop.sh

#!/bin/bash
cd /home/oracle/wlstscripts-new
# Set environment
source   set-wls12.2.1-env.sh
# Stop Cluster server
java weblogic.WLST wlServerLifeCycleManager.py odi_domain ODI_Cluster  ODI_server1 stop
#### Add more servers here ###
# Stop Admin
java weblogic.WLST  wlServerLifeCycleManager.py odi_domain AdminServer stop
# Stop NM
java weblogic.WLST  wlServerLifeCycleManager.py odi_domain nm machine-1 stop

Example start script: wls-auto-start.sh

#!/bin/bash
cd /home/oracle/wlstscripts-new
# Set environment
source   set-wls12.2.1-env.sh
# Start NM
java weblogic.WLST  wlServerLifeCycleManager.py odi_domain nm machine-1 start
# Start Admin
java weblogic.WLST  wlServerLifeCycleManager.py odi_domain AdminServer start
# Start Individual Server(s)
java weblogic.WLST wlServerLifeCycleManager.py odi_domain ODI_Cluster ODI_server1 start
#### Add more clusters/servers here ###