Detection of stop command in PMon

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
Search

Post Reply
3 posts • Page 1 of 1
m_verstraeten
Posts: 1
Joined: Wed Apr 02, 2025 9:35 am

Detection of stop command in PMon

Post by m_verstraeten »

Hi All,

The code below should report several debug-lines in my LOG-viewer when I start the script from pmon, but also when I stop it via pmon.

Code: Select all

// Callback function to handle exitRequested event
void onExitRequested(string event, int exitCode) {
  DebugN("Bye bye");
  DebugN("Event: " + event);
  DebugN("Exit Code: " + exitCode);
}

// Main function
main() {
  // Connect to the exitRequested event
  sysConnect("onExitRequested", "exitRequested");
  DebugN("Script started");

  // Keep the script running to test exit
  while (true) {
    // Optional: Add a sleep or wait here to prevent busy-waiting
    delay(5); // Sleep for 1 second
  }
}
Unfortunately, the starting goes well, but when I stop it, I only see this line:
unknown user wrote:
Unexpected state, CtrlMgr, doConnectionClose, Lost Connection to Event Manager, exiting ...
Am I doing something wrong here?

I use the following version: WinCC 3.20 Patch 4

gschijndel
Posts: 373
Joined: Tue Jan 15, 2019 3:12 pm

Re: Detection of stop command in PMon

Post by gschijndel »

Your script looks fine to me, but it seems that the manager stops due to a lost event manager connection.
In that case it might not wait until your callback is executed before stopping the script (just as with a kill command).

There could be other lines to indicate why the script stops, for example like:
25/pmon, Got STOP command (SIGTERM) from 127.0.0.1, stopping the manager WCCOActrl(x) at index y
17/pmon, Stopping Manager WCCOActrl(x) with signal SIGTERM
170, Signal SIGTERM received - exiting ...
MAN: (SYS: 1 Event -num 0 CONN: 1), SHUT_DOWN_MANAGER received

The first 2 are written by the pmon, the last 2 by the manager.

BTW: You could activate a plugin to write security events to a log, like stop manager and check if this logs it.

User avatar
leoknipp
Posts: 2926
Joined: Tue Aug 24, 2010 7:28 pm

Re: Detection of stop command in PMon

Post by leoknipp »

I have tested it and the "exitRequested" function is triggered in 2 cases in my tests:
1) When the DP element _Managers.Exit is set with the manager ID for the CTRL Manager.
2) When the Event Manager is stopped using the PMon and information is distributed to all connected managers to stop.

Best Regards
Leopold Knipp
Senior Support Specialist

Post Reply
3 posts • Page 1 of 1