Code

- wrong directory for a gosa-si-client.socket
[gosa.git] / gosa-si / gosa-si-client
index f048269b98e04a6a8560601464effb227197a275..d1d62dff398c670b322f2f8c859db2338eb917a7 100755 (executable)
 #
 #*********************************************************************
 
+=head1 NAME
+
+gosa-si-client - Client for GOsa support infrastructure
+
+=head1 SYNOPSIS
+
+gosa-si-client [-hvf] [-c config]
+
+=head1 OPTIONS
+
+B<-h>, B<--help>
+    print out this help message
+
+B<-v>, B<--verbose>
+    be verbose (multiple v's will increase verbosity) 
+    -v          ERROR level
+    -vvv        WARNING  + ERROR level
+    -vvvvv      INFO + WARNING level
+    -vvvvvvv    DEBUG + INFO level
+    -vvvvvvvvv  in and out going xml messages will be displayed
+
+B<-f>, B<--foreground> 
+    foregroud, process will not be forked to background
+
+B<-c> I<file>, B<--config=>I<file>
+    configuration file, default F</etc/gosa-si/client.conf>
+
+B<-x> <dump>
+     dump configuration to stdout
+     ( 1 = current, 2 = default )
+
+=head1 DESCRIPTION
+
+B<gosa-si-client> belongs to the support infrastructure of GOsa. 
+The client registrates at a GOsa-SI-server and accepts messages from it. 
+Each message is related to a working instruction which will be executed on the client. 
+Depending on the message an answer can be send back to the server.
+
+=head1 BUGS 
+
+Please report any bugs, or post any suggestions, to the GOsa mailing list <gosa-devel@oss.gonicus.de> or to <https://oss.gonicus.de/labs/gosa>
+
+
+=head1 LICENCE AND COPYRIGHT
+
+This code is part of GOsa (L<http://www.gosa-project.org>)
+
+Copyright (C) 2003-2010 GONICUS GmbH
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+=cut
+
 use strict;
 use warnings;
 
@@ -25,6 +81,7 @@ use MIME::Base64;
 use XML::Simple;
 use File::Basename;
 use File::Spec;
+use File::Pid;
 use Net::ARP;
 
 use POE qw(Component::Server::TCP Wheel::FollowTail Wheel::Run);
@@ -70,18 +127,17 @@ our $terminal_server_hash;
 our $opts_dnslookup;
 
 # where is the config stored by default and his name
-our $config = '/etc/fts/fts.conf';
+our $config = '/etc/gosa-si/client.conf';
 
 # by default dumping of config is undefined
 our $dump_config = undef;
 
-
 # default variables
 my $REGISTERED = 0;
 
 # path to fifo for non-gosa-si-client messages to gosa-si-server
-my $fai_com_fifo = "/var/run/gosa-si-client.socket";
-my $system_com_fifo = "/var/run/gosa-si-client-system-com.socket";
+my $fai_com_fifo = "/var/run/gosa-si/gosa-si-client.socket";
+my $system_com_fifo = "/var/run/gosa-si/gosa-si-client-system-com.socket";
 my %files_to_watch = (fai_fifo => $fai_com_fifo, system_fifo => $system_com_fifo); 
 
 # in function register_at_gosa_si_server, after which period of seconds a new registration should be tried if a registration was not successful until now
@@ -289,10 +345,11 @@ sub check_pid {
         unlink( $pid_file );
     }
 
+               my $LOCK_FILE2;
     # create a syslog msg if it is not to possible to open PID file
     if (not sysopen(LOCK_FILE, $pid_file, O_WRONLY|O_CREAT|O_EXCL, 0644)) {
        my($msg) = "Couldn't obtain lockfile '$pid_file' ";
-        if (open(my $LOCK_FILE2, '<', $pid_file)
+        if (open($LOCK_FILE2, '<', "$pid_file")
                 && ($pid = <$LOCK_FILE2>))
         {
             chomp($pid);
@@ -325,7 +382,7 @@ sub sig_int_handler {
 #      system("kill `ps -C gosa-si-server -o pid=`");
        $global_kernel->yield('shutdown');
        
-#      $pid->remove or warn "Could not remove $pidfile\n";
+       $pid->remove or warn "Could not remove $pid_file\n";
 
   exit(0);
 }
@@ -901,7 +958,7 @@ sub trigger_logged_in_users_report {
                        @logged_in_user_list = split(/\s/, $result);
                }
                
-        system("echo 'CURRENTLY_LOGGED_IN ".join(" ", @logged_in_user_list)."' > /var/run/gosa-si-client.socket"); 
+        system("echo 'CURRENTLY_LOGGED_IN ".join(" ", @logged_in_user_list)."' > /var/run/gosa-si/gosa-si-client.socket"); 
         $kernel->delay_set('trigger_logged_in_users_report', $trigger_logged_in_users_report_delay);
     } else {
         # try it in 10 sec again
@@ -1235,7 +1292,8 @@ sub post_processing_and_sending
 
 sub find_servers {
     # add gosa-si-server address from config file at first position of server list
-    my $server_check_cfg = Config::IniFiles->new( -file => $cfg_file );
+               #my $server_check_cfg = Config::IniFiles->new( -file => $cfg_file );
+    my $server_check_cfg = Config::IniFiles->new( -file => $config );
 
     # Parse servers string
     my @conf_servers = split(',', $servers_string);
@@ -1342,10 +1400,18 @@ if( defined $dump_config ) {
 }
 
 #  read and set config parameters
-#&check_cmdline_param ;
-&read_configfile($cfg_file, %cfg_defaults);
-&check_pid;
+&read_configfile($config, %cfg_defaults);
+#&check_pid;
+
+# Create the PID object
+# Ensure you put a name that won't clobber
+#   another program's PID file
+$pid = File::Pid->new({
+   file  => $pid_file,
+});
 
+# Write the PID file
+$pid->write;
 
 # forward error messages to logfile
 if ( ! $foreground ) {
@@ -1360,19 +1426,19 @@ if( ! $foreground ) {
     $pid = fork;
     setsid                    or die "Can't start a new session: $!";
     umask 0;
-} else { 
-    $pid = $$; 
+#} else {
+#    $pid = $$;
 }
 
 # Do something useful - put our PID into the pid_file
-if( 0 != $pid ) {
-    open( my $LOCK_FILE, ">", "$pid_file" );
-    print $LOCK_FILE "$pid\n";
-    close( $LOCK_FILE );
-    if( !$foreground ) { 
-        exit( 0 ) 
-    };
-}
+#if( 0 != $pid ) {
+#    open( my $LOCK_FILE, ">", "$pid_file" );
+#    print $LOCK_FILE "$pid\n";
+#    close( $LOCK_FILE );
+#    if( !$foreground ) {
+#        exit( 0 )
+#    };
+#}
 
 # parse head url and revision from svn
 my $client_status_hash = { 'developmental'=>'revision', 'stable'=>'release'};
@@ -1398,7 +1464,7 @@ daemon_log("gosa-si-client started!", 1);
 daemon_log("INFO: status: $client_status", 1);
 daemon_log("INFO: ".$client_status_hash->{$client_status}.": $client_revision", 1); 
 
-# delete old DBsqlite lock files
+# to be changed maybe not trace of it when running 
 system('rm -f /tmp/gosa_si_lock*gosa-si-client*');
 
 # detect ip and mac address and complete host address
@@ -1457,26 +1523,26 @@ if ($system_com eq "enabled")
 
 POE::Session->create(
        inline_states => {
-               _start => \&_start, 
-        _default => \&_default,
-        sig_handler => \&sig_handler,
-        register_at_gosa_si_server => \&register_at_gosa_si_server,
+               _start => \&_start,
+               _default => \&_default,
+               sig_handler => \&sig_handler,
+               register_at_gosa_si_server => \&register_at_gosa_si_server,
 
-        # trigger periodical tasks
-        trigger_new_key => \&trigger_new_key,
-        trigger_logged_in_users_report => \&trigger_logged_in_users_report,
-        trigger_seen_messages => \&trigger_seen_messages,
+               # trigger periodical tasks
+               trigger_new_key => \&trigger_new_key,
+               trigger_logged_in_users_report => \&trigger_logged_in_users_report,
+               trigger_seen_messages => \&trigger_seen_messages,
 
                # trigger non periodical tasks
                trigger_set_terminal_server => \&trigger_set_terminal_server,
-        
-        # handle records from each defined file differently
-        fai_fifo_record => \&fai_fifo_got_record,
+
+               # handle records from each defined file differently
+               fai_fifo_record => \&fai_fifo_got_record,
                system_fifo_record => \&system_fifo_got_record,
 
-        # handle file resets and errors the same way for each file
-        file_reset => \&generic_file_reset,
-        file_error => \&generic_file_error,
+               # handle file resets and errors the same way for each file
+               file_reset => \&generic_file_reset,
+               file_error => \&generic_file_error,
        }
 );