[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

I need to write a python script using wsadmin which Stop's, Sync and Start's all the JVM on Node1 and then send an email after the task is done.

Posted on 2014-04-03
6
Medium Priority
?
2,225 Views
Last Modified: 2014-05-24
I am using WebSphere Application Server 7.0 running on windows. I need a wsadmin script which will do a Stop, Sync and Start of all the JVM on the node and then send an email after all the JVM's are started. I want the email notification include that it stopped, synced and started the JVM's.

Please help me out.

Thanks
0
Comment
Question by:kewlclassic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 16

Expert Comment

by:Walter Ritzel
ID: 39976974
Please look at these samples:
http://www.ibm.com/developerworks/websphere/library/samples/SampleScripts.html

http://wsadminlib.blogspot.com.br/2010/12/how-to-start-node-agent-using-scripting.html

Basic script from last link:
# Import python os library to execute external commands
import os


# Import wsadminlib.py (update this to your own wsadminlib.py path)
execfile('/tmp/wsadminlib.py')


# Node name
nodename = 'node1'


# Server name
servername = 'nodeagent'


# Counter used to keep track of while loop execution
counter = 0


while(counter < 2):
    # Check if Node agent is running
    print "\nIs Node agent running?"
    isItRunning = isServerRunning(nodename,servername)
    
    # If Node agent is running let's stop it
    # else let's start it
    if (isItRunning):
        print "YES\n"
        
        print "Request issued to stop Node agent\n"
        stopServer( nodename, servername, immediate=False )
        counter = counter + 1
    else:
        print "NO\n"
        print "Request issued to start Node agent\n"
        os.system('/opt/WAS61/profiles/node1/bin/startNode.sh')
        counter = counter + 1

Open in new window

0
 

Author Comment

by:kewlclassic
ID: 39978466
Thanks Walter. But the one which you attached above is just stopping and starting the node agent. I need one to stop all the JVM's on one node and then perform Sync and and then start all JVM's. Repeat this step for the other node as well. Once this is done, an email needs to be send confirming all task's has been done.

I don't know how to start writing a script. Any help will be much appreciated.

Thanks
0
 
LVL 16

Expert Comment

by:Walter Ritzel
ID: 39978972
Ok, let me see if I can came with something. But I believe that you need to get started on reading anything you can from the first link.

To start creating a script, is pretty much what you saw above. Python is really a simple and very efficient and effective language.

http://www.python.org is the place to start with python.

Cheers,
Walter.
0
Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

 

Author Comment

by:kewlclassic
ID: 39979157
--Walter, thanks again.

 I took few samples from this forum and wrote this one. Its works but needs modification.

I need this script to perform stop/sync/start and send email on node1 and then do the same stop/syn/start on node2 and send the email.

I took the wsadmin control commands from WebSphere Admin Console by stopping the JVM, syncing the nodes manually. But this needs to be refined. As i said above, if you can help me out using this as base script, I really appreciate it. The email thing is working fine. So please when you modify this, please include all the output results come out in email.

Thanks
Kewlclassic
#######################################

import smtplib


sender = 'xxxxxx@xxxx.com'
receivers = ['xxxxx@xxx.com.com']

#Create empty string
outmsg = ''

print "Stopping JVM's"
outmsg = outmsg + "Stopping JVM's\n"


AdminControl.invoke('WebSphere:name=ABCD_CM01,process=ABCD_CM01,platform=proxy,node=ESB-node01,j2eeType=J2EEServer,version=7.0.0.25,type=Server,mbeanIdentifier=cells/ESB_MODL/nodes/esbmodl-node01/servers/HUB_CM01/server.xml#Server_1363703386444,cell=ESB_MODL,spec=1.0,processType=ManagedProcess', 'stop')



serverCount= len(AdminControl.queryNames('type=Server,cell=ESB_MODL,node=esbmodl-node01,*').split())

while(serverCount > 1):

                print serverCount
#               outmsg = outmsg + serverCount+'\n'
                print "Server is stopping"
                outmsg = outmsg + 'Server is stopping\n'
                sleep(5)
                serverCount= len(AdminControl.queryNames('type=Server,cell=ESB_MODL,node=esbmodl-node01,*').split())

print "Server Stopped"
outmsg = outmsg + 'Server Stopped\n'

AdminControl.invoke('WebSphere:name=repository,process=nodeagent,platform=common,node=tcmesbmodl-node01,version=5.0,type=ConfigRepository,mbeanIdentifier=repository,cell=ESB_MODL,spec=1.0', 'refreshRepositoryEpoch')

AdminControl.invoke('WebSphere:name=cellSync,process=dmgr,platform=common,node=modl-dmgr-node,version=7.0.0.25,type=CellSync,mbeanIdentifier=cellSync,cell=ESB_MODL,spec=1.0', 'syncNode', '[tcmesbmodl-node01]', '[java.lang.String]')
               

Sync1 = AdminControl.completeObjectName('type=NodeSync,node=tcmesbmodl-node01,*')

SyncStatus =AdminControl.invoke(Sync1, 'sync')

print "Sync Status"
outmsg = outmsg + 'Sync Status\n'

while(SyncStatus !="true"):

               print "Sync in Progress"
#             outmsg = outmsg + 'Sync in Progress\n'
               sleep (5)
             SyncStatus =AdminControl.invoke(Sync1, 'sync')

print "Sync Complete"
outmsg = outmsg + 'Sync Complete\n'


print "Starting JVM's"
outmsg = outmsg + "Starting JVM's\n"


AdminControl.invoke('WebSphere:name=EFGH_CM01,process=EFGH_CM01,platform=common,node=tcmesbmodl-node01,diagnosticProvider=true,version=7.0.0.25,type=NodeAgent,mbeanIdentifier=NodeAgent,cell=ESB_MODL,spec=1.0', 'launchProcess', '[AGENTHUB_CM01]', '[java.lang.String]')


print "All JVM's Started"
outmsg = outmsg + "All JVM's Started\n"

# Send email

message = """From: From Person <xxxxx@xxx.com>
To: To Person <xxxxx@xxx.com
Subject: WESB MODL-Stop-Start-Sync Node1

    %s
    """ % ( outmsg )

try:
   s = smtplib.SMTP('mail1.domain.com')
   s.sendmail(sender, receivers, message)        
   print "Successfully sent email"
except SMTPException:
   print "Error: unable to send email"
0
 

Accepted Solution

by:
kewlclassic earned 0 total points
ID: 40076187
i guess i figured it out.
0
 

Author Closing Comment

by:kewlclassic
ID: 40088109
just figured it out.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question