From: rettenbe Date: Mon, 21 Jan 2008 10:35:00 +0000 (+0000) Subject: cleanup daemon_log messages X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9babc999348d7e826e8a9cdab847a1d8ca96000c;p=gosa.git cleanup daemon_log messages git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8514 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 19fdc07d1..351878bc6 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -394,239 +394,6 @@ sub create_known_client { return; } -#==== MAIN = main ============================================================== -# parse commandline options -Getopt::Long::Configure( "bundling" ); -GetOptions("h|help" => \&usage, - "c|config=s" => \$cfg_file, - "f|foreground" => \$foreground, - "v|verbose+" => \$verbose, - "no-bus+" => \$no_bus, - "no-arp+" => \$no_arp, - ); - -# read and set config parameters -&check_cmdline_param ; -&read_configfile; -&check_pid; - -$SIG{CHLD} = 'IGNORE'; - -# forward error messages to logfile -if( ! $foreground ) { - open(STDERR, '>>', $log_file); - open(STDOUT, '>>', $log_file); -} - -# Just fork, if we are not in foreground mode -if( ! $foreground ) { - chdir '/' or die "Can't chdir to /: $!"; - $pid = fork; - setsid or die "Can't start a new session: $!"; - umask 0; -} else { - $pid = $$; -} - -# Do something useful - put our PID into the pid_file -if( 0 != $pid ) { - open( LOCK_FILE, ">$pid_file" ); - print LOCK_FILE "$pid\n"; - close( LOCK_FILE ); - if( !$foreground ) { - exit( 0 ) - }; -} - -daemon_log(" ", 1); -daemon_log("$0 started!", 1); - -# delete old DBsqlite lock files -system('rm -f /tmp/gosa_si_lock*'); - -# connect to gosa-si job queue -my @job_col_names = ("id", "timestamp", "status", "result", "headertag", "targettag", "xmlmessage", "macaddress"); -$job_db = GOSA::DBsqlite->new($job_queue_file_name); -$job_db->create_table('jobs', \@job_col_names); - -# connect to known_clients_db -my @clients_col_names = ('hostname', 'status', 'hostkey', 'timestamp', 'macaddress', 'events'); -$known_clients_db = GOSA::DBsqlite->new($known_clients_file_name); -$known_clients_db->create_table('known_clients', \@clients_col_names); - -# connect to known_server_db -my @server_col_names = ('hostname', 'status', 'hostkey', 'timestamp'); -$known_server_db = GOSA::DBsqlite->new($known_server_file_name); -$known_server_db->create_table('known_server', \@server_col_names); - -# import all modules -&import_modules; - -# check wether all modules are gosa-si valid passwd check - -# create reading and writing vectors -my $rbits = my $wbits = my $ebits = ""; - -# add all module inputs to listening vector -# while( my ($mod_name, $info) = each %$known_modules ) { -# my ($input_address, $input_key, $input, $input_activ, $input_type) = @{$info}; -# vec($rbits, fileno $input, 1) = 1; -# -# } - - -## start arp fifo -#if ($no_arp > 0) { -# $arp_activ = "off"; -#} -#my $my_fifo; -#if($arp_activ eq "on") { -# daemon_log(" ", 1); -# $my_fifo = &open_fifo($arp_fifo_path); -# if($my_fifo == 0) { die "fifo file disappeared\n" } -# sysopen($arp_fifo, $arp_fifo_path, O_RDWR) or die "can't read from $arp_fifo: $!" ; -# -# vec($rbits, fileno $arp_fifo, 1) = 1; -#} -# - -################################### -##everything ready, okay, lets start -################################### -#while(1) { -# -# # add all handles from the childs -# while ( my ($pid, $child_hash) = each %busy_child ) { -# -# # check whether process still exists -# my $exitus_pid = waitpid($pid, WNOHANG); -# if($exitus_pid != 0) { -# delete $busy_child{$pid}; -# next; -# } -# -# # add child fhd to the listener -# my $fhd = $$child_hash{'pipe_rd'}; -# vec($rbits, fileno $fhd, 1) = 1; -# } -# -# my ($rout, $wout); -# my $nf = select($rout=$rbits, $wout=$wbits, undef, $job_queue_timeout); -# -# # error handling -# if($nf < 0 ) { -# } -# -# -## if($arp_activ eq "on" && vec($rout, fileno $arp_fifo, 1)) { -## my $in_msg = <$arp_fifo>; -## chomp($in_msg); -## print "arp_activ: msg: $in_msg\n"; -## my $act_passwd = $known_daemons->{$bus_address}->{passwd}; -## print "arp_activ: arp_passwd: $act_passwd\n"; -## -## my $in_msg_hash = $xml->XMLin($in_msg, ForceArray=>1); -## -## my $target = &get_content_from_xml_hash($in_msg_hash, 'target'); -## -## if ($target eq $server_address) { -## print "arp_activ: forward to server\n"; -## my $arp_cipher = &create_ciphering($act_passwd); -## my $crypted_msg = &encrypt_msg($in_msg, $arp_cipher); -## &activating_child($crypted_msg, $server_ip); -## } else { -## print "arp_activ: send to bus\n"; -## &send_msg_hash2address($in_msg_hash, $bus_address); -## } -## print "\n"; -## } -# -# -# # check input fhd of all modules -# while ( my ($mod_name, $info) = each %$known_modules) { -# my $input_fhd = @{$info}[2]; -# my $input_activ = @{$info}[3]; -# if (vec($rout, fileno $input_fhd, 1) && $input_activ eq 'on') { -# daemon_log(" ", 1); -# my $client = $input_fhd->accept(); -# my $other_end = getpeername($client); -# if(not defined $other_end) { -# daemon_log("client cannot be identified: $!"); -# } else { -# my ($port, $iaddr) = unpack_sockaddr_in($other_end); -# my $actual_ip = inet_ntoa($iaddr); -# daemon_log("accept client at daemon socket from $actual_ip", 5); -# my $in_msg = &read_from_socket($client); -# if(defined $in_msg){ -# chomp($in_msg); -# &activating_child($in_msg, $actual_ip, $client); -# } else { -# daemon_log("cannot read from $actual_ip", 5); -# } -# } -# } -# } -# -# # check all processing childs whether they are finished ('done') or -# while ( my ($pid, $child_hash) = each %busy_child ) { -# my $fhd = $$child_hash{'pipe_rd'}; -# -# if (vec($rout, fileno $fhd, 1) ) { -# daemon_log("process child $pid is ready to read", 5); -# -# my $in_msg; -# while (1) { -# my $part_in_msg = <$fhd>; -# if( $part_in_msg eq "ENDMESSAGE\n") { -# last; -# } -# $in_msg .= $part_in_msg; -# } -# chomp($in_msg); -# -# if (not defined $in_msg) { -# next; -# } elsif ($in_msg =~ "done") { -# daemon_log("process child read: $in_msg", 7); -# delete $busy_child{$pid}; -# $free_child{$pid} = $child_hash; -# -# } else { -# daemon_log("process child read:", 7); -# daemon_log("\n$in_msg", 8); -# # send computed answer back to connected client -# my $act_client = $busy_child{$pid}{client_ref}; -# print $act_client $in_msg."\n"; -# delete $busy_child{$pid}; -# $free_child{$pid} = $child_hash; -# -# } -# } -# } -# -# -# } -# -# -#} - -POE::Session->create -( - inline_states => { - _start => \&trigger_db_loop, - watch_for_new_jobs => \&watch_for_new_jobs, - } -); - -POE::Component::Server::TCP->new -( - Port => $server_port, - ClientInput => \&client_input, -); - -POE::Kernel->run(); -exit; - sub client_input { my ($heap,$input,$wheel) = @_[HEAP, ARG0, ARG1]; ###################################### @@ -640,7 +407,7 @@ sub client_input { if (defined $tmp) { $answer = $tmp; } - daemon_log("Got answer from module ".$module.": ".$answer,3); + daemon_log("Got answer from module ".$module.": ".$answer,8); } daemon_log("processing of msg finished", 5); @@ -660,16 +427,17 @@ sub watch_for_new_jobs { my ($kernel,$heap) = @_[KERNEL, HEAP]; # check gosa job queue for jobs with executable timestamp - my ($seconds, $minutes, $hours, $monthday, $month, - $year, $weekday, $yearday, $sommertime) = localtime(time); - $hours = $hours < 10 ? $hours = "0".$hours : $hours; - $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes; - $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds; - $month+=1; - $month = $month < 10 ? $month = "0".$month : $month; - $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday; - $year+=1900; - my $timestamp = "$year$month$monthday$hours$minutes$seconds"; +# my ($seconds, $minutes, $hours, $monthday, $month, +# $year, $weekday, $yearday, $sommertime) = localtime(time); +# $hours = $hours < 10 ? $hours = "0".$hours : $hours; +# $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes; +# $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds; +# $month+=1; +# $month = $month < 10 ? $month = "0".$month : $month; +# $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday; +# $year+=1900; +# my $timestamp = "$year$month$monthday$hours$minutes$seconds"; + my $timestamp = &get_time(); my $res = $job_db->select_dbentry( { table=>$job_queue_table_name, status=>'waiting', timestamp=>$timestamp } ); @@ -729,3 +497,96 @@ sub watch_for_new_jobs { $kernel->delay_set('watch_for_new_jobs',3); } + + +#==== MAIN = main ============================================================== +# parse commandline options +Getopt::Long::Configure( "bundling" ); +GetOptions("h|help" => \&usage, + "c|config=s" => \$cfg_file, + "f|foreground" => \$foreground, + "v|verbose+" => \$verbose, + "no-bus+" => \$no_bus, + "no-arp+" => \$no_arp, + ); + +# read and set config parameters +&check_cmdline_param ; +&read_configfile; +&check_pid; + +$SIG{CHLD} = 'IGNORE'; + +# forward error messages to logfile +if( ! $foreground ) { + open(STDERR, '>>', $log_file); + open(STDOUT, '>>', $log_file); +} + +# Just fork, if we are not in foreground mode +if( ! $foreground ) { + chdir '/' or die "Can't chdir to /: $!"; + $pid = fork; + setsid or die "Can't start a new session: $!"; + umask 0; +} else { + $pid = $$; +} + +# Do something useful - put our PID into the pid_file +if( 0 != $pid ) { + open( LOCK_FILE, ">$pid_file" ); + print LOCK_FILE "$pid\n"; + close( LOCK_FILE ); + if( !$foreground ) { + exit( 0 ) + }; +} + +daemon_log(" ", 1); +daemon_log("$0 started!", 1); + +# delete old DBsqlite lock files +system('rm -f /tmp/gosa_si_lock*'); + +# connect to gosa-si job queue +my @job_col_names = ("id", "timestamp", "status", "result", "headertag", "targettag", "xmlmessage", "macaddress"); +$job_db = GOSA::DBsqlite->new($job_queue_file_name); +$job_db->create_table('jobs', \@job_col_names); + +# connect to known_clients_db +my @clients_col_names = ('hostname', 'status', 'hostkey', 'timestamp', 'macaddress', 'events'); +$known_clients_db = GOSA::DBsqlite->new($known_clients_file_name); +$known_clients_db->create_table('known_clients', \@clients_col_names); + +# connect to known_server_db +my @server_col_names = ('hostname', 'status', 'hostkey', 'timestamp'); +$known_server_db = GOSA::DBsqlite->new($known_server_file_name); +$known_server_db->create_table('known_server', \@server_col_names); + +# import all modules +&import_modules; + +# check wether all modules are gosa-si valid passwd check + +# create session for repeatedly checking the job queue for jobs +POE::Session->create +( + inline_states => { + _start => \&trigger_db_loop, + watch_for_new_jobs => \&watch_for_new_jobs, + } +); + +# create socket for incoming xml messages +POE::Component::Server::TCP->new +( + Port => $server_port, + ClientInput => \&client_input, +); +daemon_log("start socket for incoming xml messages at port '$server_port' ", 1); + +POE::Kernel->run(); +exit; + + diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index 86895caeb..94714e384 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -66,29 +66,6 @@ my $gosa_address = "$gosa_ip:$gosa_port"; my $gosa_cipher = &create_ciphering($gosa_passwd); my $xml = new XML::Simple(); -# open gosa socket -if ($gosa_activ eq "on") { - &main::daemon_log(" ",1); - $gosa_server = IO::Socket::INET->new(LocalPort => $gosa_port, - Type => SOCK_STREAM, - Reuse => 1, - Listen => 1, - ); - if (not defined $gosa_server) { - &main::daemon_log("cannot start tcp server at $gosa_port for communication to gosa: $@", 1); - die; - } else { - &main::daemon_log("start server for communication to gosa: $gosa_address", 1); - - } -} - -# create gosa job queue as a SQLite DB -my $table_name = "jobs"; -my $sqlite = GOSA::DBsqlite->new($job_queue_file_name); - - - ## FUNCTIONS ################################################################# @@ -283,7 +260,7 @@ sub open_socket { #=============================================================================== sub process_incoming_msg { my ($crypted_msg) = @_ ; - &main::daemon_log("Got message $crypted_msg", 5); + &main::daemon_log("Got message $crypted_msg", 8); if( (not(defined($crypted_msg))) || (length($crypted_msg) <= 0)) { &main::daemon_log("function 'process_incoming_msg': got no msg", 7); return; @@ -305,7 +282,7 @@ sub process_incoming_msg { my $msg_hash; eval{ $msg = &decrypt_msg($crypted_msg, $gosa_cipher); - &main::daemon_log("GosaPackages: decrypted_msg: \n$msg", 7); + &main::daemon_log("GosaPackages: decrypted_msg: \n$msg", 8); $msg_hash = $xml->XMLin($msg, ForceArray=>1); }; diff --git a/gosa-si/modules/ServerPackages.pm b/gosa-si/modules/ServerPackages.pm index 95baac87a..cb7c976f9 100644 --- a/gosa-si/modules/ServerPackages.pm +++ b/gosa-si/modules/ServerPackages.pm @@ -58,9 +58,6 @@ my %cfg_defaults = $network_interface= &get_interface_for_ip($server_ip); $server_mac_address= &get_mac($network_interface); -&main::daemon_log("server ip address detected: $server_ip", 1); -&main::daemon_log("server mac address detected: $server_mac_address", 1); - # complete addresses my $server_address = "$server_ip:$server_port"; my $bus_address = "$bus_ip:$bus_port"; @@ -68,31 +65,13 @@ my $bus_address = "$bus_ip:$bus_port"; # create general settings for this module my $xml = new XML::Simple(); -## open server socket -#if($server_activ eq "on"){ -# &main::daemon_log(" ", 1); -# $server = IO::Socket::INET->new(LocalPort => $server_port, -# Type => SOCK_STREAM, -# Reuse => 1, -# Listen => 20, -# ); -# if(not defined $server){ -# &main::daemon_log("cannot be a tcp server at $server_port : $@"); -# die; -# } else { -# &main::daemon_log("start server: $server_address", 1); -# } -#} -# -# -## register at bus -#if ($main::no_bus > 0) { -# $bus_activ = "off" -#} -#if($bus_activ eq "on") { -# &main::daemon_log(" ", 1); -# ®ister_at_bus(); -#} +# register at bus +if ($main::no_bus > 0) { + $bus_activ = "off" +} +if($bus_activ eq "on") { + ®ister_at_bus(); +} ### functions ################################################################# @@ -437,7 +416,7 @@ sub process_incoming_msg { if( not defined $msg ) { &main::daemon_log("WARNING: ServerPackage do not understand the message:", 5); - &main::daemon_log("$@", 7); + &main::daemon_log("$@", 8); return; } diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 8c715148d..a673db58c 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -4,7 +4,7 @@ require_once("../../gosa-core/include/class_socketClient.inc"); error_reporting(E_ALL); -$sock = new Socket_Client("127.0.0.1","20082",TRUE,1); +$sock = new Socket_Client("127.0.0.1","20081",TRUE,1); #$sock = new Socket_Client("169.254.2.248","9999",TRUE,1); $sock->setEncryptionKey("secret-gosa-password");