Pour des besoins de sauvegarde cohérente de l'environnement ITIM, on a parfois besoin d'arrêter l'application ITIM, sans forcément arrêter le serveur WebSphere, qui est généralement supervisé par l'exploitation.
Dans un contexte de script de production, il est possible d'arrêter / démarrer une application via l'utilitaire wsadmin fourni avec WebSphere.
Cet utilitaire permet d'interagir avec le serveur d'application via un langage de script (jython notamment). Voici par exemple le script python et le shell qui encapsule ce script, qui permet d'arrêter et relancer l'application ITIM (on une autre).
Ce shell permet de lancer un script python ou de lancer wsadmin en interactif, selon la présence ou non d'une option.
#!/bin/bash
#
# Run jython
if [ "$1" != "" ] ; then
/product/websphere/AppServer/bin/wsadmin.sh -lang jython -f $*
else
echo "Mode interactif"
/product/websphere/AppServer/bin/wsadmin.sh -lang jython
fi
Le script lance l'utilitaire wsadmin.sh, avec le langage python.
Le script python de gestion d'application est un script python, qui accepte 2 options :
# Application Manager with wsadmin
# -------------------------------------------------------------------------------
# Starts / Stops a Business Level Application on WebSphere Application Server
#
# Mainly used for ITIM
# -------------------------------------------------------------------------------
import sys
if len(sys.argv) != 2:
print " "
print "Usage: AppManager [start|stop] Application, where Application is the name of the application you want to start or stop"
print " "
sys.exit(-1)
adminAction = sys.argv[0]
my_AppName = sys.argv[1]
print "-------------------------------------------------"
print "Asked to ",adminAction," application ",my_AppName
print "-------------------------------------------------"
if adminAction=="start":
print "Starting application",my_AppName
AdminBLA.startBLA(my_AppName)
if adminAction=="stop":
print "Stopping application",my_AppName
AdminBLA.stopBLA(my_AppName)
print "End of AppManager"
L'arrêt de l'application ITIM s'effectue avec la ligne de commande :
./jython AppManager.py stop ITIM
Le démarrage de l'application s'effectue, de la même manière :
./jython AppManager.py start ITIM
Le résultat du lancement de cette ligne est :
./jython AppManager.py start ITIM
WASX7209I: Connected to process "server1" on node node01 using SOAP connector; The type of process is: UnManagedProcess
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv variable: "[start, ITIM]"
-------------------------------------------------
Asked to start application ITIM
-------------------------------------------------
Starting application ITIM
---------------------------------------------------------------
---------------------------------------------------------------
AdminBLA: Start a business level application
BLA ID (or BLA name): ITIM
Usage: AdminBLA.startBLA("ITIM")
Return: State that the business-level application is started.
---------------------------------------------------------------
End of AppManager
Note : il faut lancer ce script avec un utilisateur disposant de droits suffisants : soit l'utilisateur wasadm (le propriétaire des répertoires /product/websphere) ou le compte root.