Video Screencast Help
Symantec to Separate Into Two Focused, Industry-Leading Technology Companies. Learn more.

Winodws Process Script

Created: 19 Sep 2012 • Updated: 18 Oct 2012 | 10 comments
This issue has been solved. See solution.

Hi,  I'm looking for a sample windows script that can monitor processes to use in VCS.  Anyone have any ideas?

Thanks in advance!

Comments 10 CommentsJump to latest comment

Wally_Heim's picture

Hi Grumpy15,

I do have some sample process scripts that I can provide. But I would like to know more about what you are trying to do before we go that route.

Can you provide more details on what you are trying to do?  We have several agents that might do what you need without the scripting involved with the Process agent.

The ServiceMonitor resource will monitor the running state of a Windows service.  However, it does not control (start/stop) a windows service.

The GenericService resource can be used to control (start, stop and monitor) a windows service.

The Process agent allows you to provide scripts or executables for the start, stop and monitor entry points. 

The Process resource also allows you to provide a single exe to the StartProgram attribute without defining the StopProgram and the MonitorProgram attributes.  The only catch is that the exe has to stay running so that the process agent will monitor for the running exe (process PID) and will terminate the exe during the stop.

Depending on what you are actually trying to do we might have other resources or methods to help you do what you want.

Thank you,

Wally

Grumpy15's picture

Hi Wally,

I have a program that I need to start and stop by running a batch file.  I was looking for something to put in the Process Monitor that can monitor multiple process and trigger a failover if one of them goes down.  The Process Agent is what I was actually planning on using.

The application itself does not come with a Process Monitor.

Thanks!

Darla

Wally_Heim's picture

Hi Darla,

That sounds good for the Process agent then.  Here some sample scripts that you can use and a simple main.cf config to show you how to use them.

Add in your own code that you need executed in the file for the entry point that you need it executed.  Keep in mind that if you have more than 1 Process resource then the 3 files below will need to be unique to that resource and the marker.id file will also need to be unique.

Create 3 files with the content below in the c:\process\ folder on each node of the cluster:

*******************

start.bat that contains:

   echo > c:\process\marker.id

*******************

stop.bat that contains:

   del c:\process\marker.id

*******************

monitor.pl that contains:

   $LockFile = "C:\\process\\marker.id";

   if (-f "$LockFile") {
    exit(110);
   } else {
    exit(100);
   }

*******************

main.cf excerpt:

 Process Process (
  StartProgram = "c:\\sampleprocess\\start.bat"
  StopProgram = "c:\\sampleprocess\\stop.bat"
  MonitorProgram = "\"C:\\Program Files\\Veritas\\VRTSPerl\\bin\\perl.exe\" c:\\sampleprocess\\monitor.pl"
  )
 

Thank you,

Wally

Wally_Heim's picture

Sorry, I missed that the main.cf was pointing to the wrong location until after I posted the message above.  The corrected main.cf sample should be:

main.cf excerpt:

 Process Process (
  StartProgram = "c:\\process\\start.bat"
  StopProgram = "c:\\process\\stop.bat"
  MonitorProgram = "\"C:\\Program Files\\Veritas\\VRTSPerl\\bin\\perl.exe\" c:\\process\\monitor.pl"
  )

Grumpy15's picture

Hi Wally,

So for each process, it will need to have it's own resource?  The reason I ask is that the start script, starts 9 services/processes.  I'm not quite understanding how I would break that out.

Thanks!

Darla

Wally_Heim's picture

Hi Darla,

As long as the processes are all going to be in the same service group you can use 1 Process resource.  However, if you need multiple service groups then you will need at least 1 Process resource per service group.

If I needed multiple Process resources then I would create a folder structure like this on each node, copy the 3 files into each and modify according to the folder that they are in and what I need them to do.

c:\Process\Res1\

c:\Process\Res2\

c:\Process\Res3\

Let me know if you have more questions.

Thank you,

Wally

Grumpy15's picture

Hi Wally,

All in one ServiceGroup.  Once start.bat runs, I need java_jsrv.exe, perl.exe, httpd.exe monitored and trigger a failover at that time.  Would I add all of the EXEs into the ProcessMonitor?

Thanks,

Darla

Wally_Heim's picture

Hi Darla,

I'm not sure exactly how these executables work and how you are executing them from the script/batch file.  It sounds like you don't really need to use the scripts for EXEs.

You can configure the process agent like this for a single EXE.

 Process Java_Process (
  StartProgram = "<path_to_exe>\\java_jsrv.exe"
  )

 Process Httpd_Process (
  StartProgram = "<path_to_exe>\\httpd.exe"
  )

The perl.exe is typically used with a script that will exit.  You should use the sample script that I provide and call your perl script from there.  If the version of perl.exe that you are executing is a process that stays running without a script then just use the process agent as I described for the Java and httpd processes above.

Thank you,

Wally

Grumpy15's picture

Hi Wally,

Is it possible to set up a process to be monitored only?  I see a line item in the attributes, but it is not editable.

Our batch file runs a perl script that starts all 9 processes and then closes out, however, we need to make sure all 9 processes stay running.  Would i only need to monitor the perl.exe?

Sorry about the confusion.

Thanks,

Darla

Wally_Heim's picture

Hi Darla,

If the perl script exits then the perl.exe that is running it is terminated.  As such, the process agent will not be able to monitor the perl.exe that it started in the StartProgram attribute.

Your start program run your script to start all of your processes.

The monitor program can run tasklist and you can check its output for the running processes that you need to ensure is running.  If all 9 processes are there then return a value of 110 (online).  If you do not find all 9 processes are running then return a value of 100 (offline).

The stop program will do what you need to end all 9 processes.

Thank you,

Wally

SOLUTION