## is starting.
#
sub Init () {
+ # Setup signal handler.
+ &SignalHandler();
+
# Setup IPC mechanism via Socket in an own thread.
threads->create(\&Socket);
# Return the position.
return $position;
}
+
+#
+## Function for capturing process signals.
+#
+## This function captures any sent process signals and will call various
+## actions, basend on the captured signal.
+#
+sub SignalHandler {
+ $SIG{INT} = \&Shutdown;
+ $SIG{TERM} = \&Shutdown;
+ $SIG{QUIT} = \&Shutdown;
+}
+
+#
+## Shutdown function.
+#
+## This function is used to do a clean shutdown of guardian. It will be called
+## by the signal handler when recieving INT (2), QUIT (3) and TERM (15) signals.
+#
+sub Shutdown () {
+ # Remove socket file on exit.
+ &Guardian::Socket::RemoveSocketFile();
+
+ # Exit guardian.
+ exit;
+}