Absent Member.. Absent Member..
Absent Member..
297 views

Stop SCEMAIL using Javascript

I have a schedule that runs every 30 minutes to check for SCEMAIL in system status to see if it's running.  If it's not, it then starts SCEMAIL by calling the us.external.launch.NEW function and starts the scsmtp.exe file.  See below:

function CheckOn(name)

{

 var Processes = system.functions.processes("user")

 for (i=0;i<system.functions.lng(Processes);i++)

      {

        var A = system.functions.str(Processes[i])

        var A = system.functions.strrep(A, "{", "")

        var A = system.functions.strrep(A, "}", "")

        var A = system.functions.strrep(A, "[", "")

        var A = system.functions.strrep(A, "]", "")

        var B = new Array

        B = A.split(",")

        var C=B[3].replace(/\"/g,"")

        if (C==" "+name)

            {

                  return true

            }

      }

 return false

}

 

function SCEmail()

//This checks to see if SCEMAIL is running in the System Status and restarts it if not

{

 var IsOn = system.library.Processes.CheckOn("SCEMAIL")

 if (IsOn != true)

      {

        print("start file");

        var RetCode

        var File = "C:\\Program Files (x86)\\HP\\Service Manager 7.11\\Server\\RUN\\scsmtp.exe"

        system.functions.rtecall("callrad", RetCode, "us.launch.external.NEW", ["name", "boolean1"], [File, false], false)

        print("end file");

       }

 return

}

 

 

I want to be setup another schedule that will run another javascript to STOP that SCEMAIL in system status.  This will be used during time change periods so emails will be sent with the correct time.

 

Any ideas on how this javascript would be written?  Or if there is another way to do what I'm trying without having to run scsmtp.exe as a Windows Service and use Windows Started Tasks?

0 Likes
13 Replies
Micro Focus Expert
Micro Focus Expert

In SM 7.11, and even more advanced in SM 9.21 you have options to shutdown a process identified by its host, and process id (pid).

sm -shutdown -host:my.server.org -pid:12345

You should be able to get this host and pid from the Processes Object that you do already inspect.


0 Likes
Absent Member.. Absent Member..
Absent Member..

Thanks. I will test with this to see if it will work for what I want. I know that SCAutoListener is running on the same PID as SCEMail but I guess I could run a JS to restart that too if it's down.

I'll keep you posted.
0 Likes

There is also a built in process in SM that can be used to watch background processes and restart them if they die.  For detail on it, check the helpserver docuementation for the article titled "Restart stopped background processes automatically"

0 Likes
Absent Member.
Absent Member.

Correct, that in-built monitoring process is called Anubis. Look in the documentation for that..

In general, SM is not really suited to work as a systems management tool in itself. This is better handled by other HP products usch as SiteScope or Ops Manager with SPI..
Thank you for using the HPSW forums. If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution.
0 Likes
Absent Member.. Absent Member..
Absent Member..

I see the information on Anubis, but my issue is that I need to STOP the scemail and then start it.  I have a process in place already that will start it if it is stopped.  I will continue to read about anubis to make sure I understand it.  I also still want to test stopping it from a command line, but have not been able to do tha yet.

 

Thanks for all the feedback!

0 Likes
Absent Member.
Absent Member.

Kirsten, what you are trying to accomplish will be very dificult if not almost impossible to do from within SM using a JavaScript. The problem is that you don't know beforehad what the PID of the SCEMAIL process is that needs to be stopped.

You need somehow to find out what the PID is, issue the stop command for that PID, and then also plan the restarting of SCEMAIL again.

The Anubis process is not suited for what you want to do. Anubis is primarily designed to restart processes that have stopped unplanned. In your example the stopping of SCEMAIL is planned.

From a functional perspective, the stopping of SCEMAIL during maintenance should be part of the normal change process, hence should be done manually, as should the restart of it.
If this maintenance period is frequently reoccuring, and always has a predefined time length, then you could consider automating it.

But my opinion is that this is done better by other products then SM. SM is simply not designed to perform these tasks effectively, and efficiently.
Thank you for using the HPSW forums. If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution.
0 Likes
Absent Member.. Absent Member..
Absent Member..

Yes, I see what you mean as the PID changes each time it restarts.

I am really just trying to figure this out so that we don't have to do it manually during the Spring and Fall time change, but I'm thinking that is not an option at this point 😞

Too bad there is not a way to terminate a user like there is a way to terminate the pid ~ sm -shutdown -host:my.server.org -pid:12345 ~ That would be great and would work perfectly...Maybe an enhancement to add that functionality is in order.

0 Likes
Micro Focus Expert
Micro Focus Expert

The problem I see here is that we have no functionality to shutdown a single thread at the moment. An user session is a thread - not a process.
The other issue I see that an user can run multiple sessions. How to address this situation?
0 Likes
Absent Member.
Absent Member.

Armin, if you are on Windows there is a workaround way to do it if you use the Process Explorer from the MS Sysinternals Suite. There you have the option to look inside a process, and kill an underlying thread.

I don't know if something similar exists on Unix though..
Thank you for using the HPSW forums. If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution.
0 Likes
Absent Member.
Absent Member.

This level of tailoring certainly carries some risks (scheduling the termination of threads/processes, not directly supported, over-extending RAD calls, etc), but it is possible to terminate a thread/process using JavaScript.

 

1. Locate the SCEMAIL entry (structured array element) within the processes() function

2. Record the Session ID (position 2 in the element) and Host Name (position 8 in the element)

3. Execute the callrad rtecall using the "signal" command panel:

 

system.functions.rtecall("callrad", returnCode, "signal", ["name", "string1"], [<Session ID>, <Host Name>], false);

 

Note: This was tested against a vertically-scaled 7.11 system but it should also work in a horizontally-scaled environment.

0 Likes
Absent Member.
Absent Member.

In re-reading this entire post, it seems that Kristen is attempting to address a problem caused by timechange.

 

Does your company cycle SM timechange? 

If not, do you experience a problem with the scheduler and the sent time attribute on emails after timechange without a cycle?

 

This is what we are experiencing.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.