// 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 ...
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.
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