Page 1 of 1

Detection of stop command in PMon

Posted: Thu Apr 03, 2025 8:28 am
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

Re: Detection of stop command in PMon

Posted: Fri Apr 11, 2025 3:01 pm
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.

Re: Detection of stop command in PMon

Posted: Fri Jul 18, 2025 4:19 pm
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