summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
e02ed02)
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
require Guardian::Base;
require Guardian::Config;
require Guardian::Base;
require Guardian::Config;
+require Guardian::Logger;
require Guardian::Parser;
require Guardian::Socket;
require Guardian::Parser;
require Guardian::Socket;
# Push the may be given config file argument.
my %mainsettings = &Guardian::Config::UseConfig($cmdargs{"config"});
# Push the may be given config file argument.
my %mainsettings = &Guardian::Config::UseConfig($cmdargs{"config"});
+# Initialize Logger.
+my $logger = Guardian::Logger->New(%mainsettings);
+$logger->Log("debug", "Logger successfully initialized...");
+
# Shared hash between the main process and all threads. It will store all
# monitored files and their current file position.
my %monitored_files :shared = ();
# Shared hash between the main process and all threads. It will store all
# monitored files and their current file position.
my %monitored_files :shared = ();
# Grab the data of the top enqueued event.
my $event = $queue->peek();
# Grab the data of the top enqueued event.
my $event = $queue->peek();
- print "Got event: $event\n";
+ # Log processed event.
+ $logger->Log("debug", "QUEUE - Processed event: $event");
# Drop processed event from queue.
$queue->dequeue();
# Drop processed event from queue.
$queue->dequeue();
# Switch watcher into non-blocking mode.
$watcher->blocking(0);
# Switch watcher into non-blocking mode.
$watcher->blocking(0);
+ # Log successfully spawned worker.
+ $logger->Log("debug", "Spawned worker thread for: $file");
+
# Infinite loop.
while(1) {
# Check for any events and perform them, if there
# Infinite loop.
while(1) {
# Check for any events and perform them, if there
# Create the Server socket by calling the responsible function.
my $server = &Guardian::Socket::Server();
# Create the Server socket by calling the responsible function.
my $server = &Guardian::Socket::Server();
+ # Log successfull creation of socket.
+ $logger->Log("debug", "Listening to Socket...");
+
# Accept incomming connections from the socket.
while (my $connection = $server->accept()) {
# Autoflush the socket after the data
# Accept incomming connections from the socket.
while (my $connection = $server->accept()) {
# Autoflush the socket after the data
# Remove any newlines.
chomp($message);
# Remove any newlines.
chomp($message);
+ # Log recieved socket command.
+ $logger->Log("debug", "Socket - Recieved message: $message");
+
# Send the recieved data message to the
# socket parser.
my $action = &Guardian::Socket::Message_Parser($message);
# Send the recieved data message to the
# socket parser.
my $action = &Guardian::Socket::Message_Parser($message);
# Loop through the hash which contains the monitored files and start
# a worker thread for each single one.
foreach my $file (keys %monitored_files) {
# Loop through the hash which contains the monitored files and start
# a worker thread for each single one.
foreach my $file (keys %monitored_files) {
+ $logger->Log("debug", "Starting worker thread for $file");
# Create worker thread for the file.
push @running_workers, threads->create(\&Worker,$file);
}
# Create worker thread for the file.
push @running_workers, threads->create(\&Worker,$file);
}
# thread so perl can do an automatically clean-up.
$worker->kill('KILL');
}
# thread so perl can do an automatically clean-up.
$worker->kill('KILL');
}
+ $logger->Log("debug", "All workers are stopped now...");
## reloading all configure options and stopping/starting the worker threads.
#
sub Reload () {
## reloading all configure options and stopping/starting the worker threads.
#
sub Reload () {
+ # Log reload.
+ $logger->Log("info", "Reload configuration...");
+
# Stop all running workers.
&StopWorkers();
# Stop all running workers.
&StopWorkers();
## by the signal handler when recieving INT (2), QUIT (3) and TERM (15) signals.
#
sub Shutdown () {
## by the signal handler when recieving INT (2), QUIT (3) and TERM (15) signals.
#
sub Shutdown () {
+ # Log shutdown.
+ $logger->Log("info", "Shutting down...");
+
# Stop all workers.
&StopWorkers();
# Stop all workers.
&StopWorkers();
+ # Log good bye message.
+ $logger->Log("debug", "Good Bye!");
+