summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a1042e3)
raw | patch | inline | side by side (parent: a1042e3)
author | opensides <opensides@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 17 May 2010 09:10:12 +0000 (09:10 +0000) | ||
committer | opensides <opensides@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 17 May 2010 09:10:12 +0000 (09:10 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18504 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-si/gosa-si-client | patch | blob | history | |
gosa-si/gosa-si-server | patch | blob | history |
diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client
index f048269b98e04a6a8560601464effb227197a275..19542cf5696087e77a49b8667f341e07d4c4b17c 100755 (executable)
--- a/gosa-si/gosa-si-client
+++ b/gosa-si/gosa-si-client
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);
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
# 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 $pidfile\n";
exit(0);
}
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);
# 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
+my $pid = File::Pid->new({
+ file => $pidfile,
+});
+# Write the PID file
+$pid->write;
# forward error messages to logfile
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'};
diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 489202349658efcbb38bfd513692122e762dda3d..13960654cc342a3d42a2cfde0a96748055dd12b8 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
use File::Path;
use Net::LDAP;
use Net::LDAP::Util qw(:escape);
+use File::Pid;
use GOsaSI::GosaSupportDaemon;
use POE qw(Component::Server::TCP Wheel::Run Filter::Reference);
my $server_headURL;
my $server_revision;
my $server_status;
-our $prg= basename($0);
-our $verbose= 0;
my $db_module = "DBsqlite";
{
my $modules_path = "/usr/lib/gosa-si/modules";
use lib "/usr/lib/gosa-si/modules";
-our $global_kernel;
my ($foreground, $ping_timeout);
my ($server);
my ($gosa_server, $job_queue_timeout, $job_queue_loop_delay);
my ($messaging_db_loop_delay);
-my ($procid, $pid);
+my $procid;
my $arp_fifo;
my $debug_parts = 0;
my $debug_parts_bitstring;
my %repo_dirs=();
# Variables declared in config file are always set to 'our'
-our (%cfg_defaults, $log_file, $pid_file,
+our (%cfg_defaults, $log_file, $pid_file, $pid
$server_ip, $server_port, $ClientPackages_key, $dns_lookup,
$arp_activ, $gosa_unit_tag,
$GosaPackages_key, $gosa_timeout,
our $known_functions;
our $root_uid;
our $adm_gid;
+our $verbose= 0;
+our $global_kernel;
+
+# where is the config stored by default and his name
+our $config = '/etc/gosa-si/server.conf';
+
+# by default dumping of config is undefined
+our $dump_config = undef;
# if foreground is not null, script will be not forked to background
$foreground = 0 ;
@@ -286,20 +292,34 @@ our $check_periodic = {"months"=>'', "weeks"=>'', "days"=>'', "hours"=>'', "minu
);
+#############################
+#
+# @brief Display error message and/or help text.
+#
+# In correspondence to previous GetOptions
+#
+# @param $text - string to print as error message
+# @param $help - set true, if you want to show usage help
+#
+sub usage
+{
+ my( $text, $help ) = @_;
-#=== FUNCTION ================================================================
-# NAME: usage
-# PARAMETERS: nothing
-# RETURNS: nothing
-# DESCRIPTION: print out usage text to STDERR
-#===============================================================================
-sub usage {
- print STDERR << "EOF" ;
-usage: $prg [-hvf] [-c config] [-d number]
+ $text = undef if( 'h' eq $text );
+ (defined $text) && print STDERR "\n$text\n";
- -h : this (help) message
- -c <file> : config file
- -f : foreground, process will not be forked to background
+ if( (defined $help && $help)
+ || (!defined $help && !defined $text) )
+{
+ print STDERR << "EOF";
+
+ usage: $0 [-hvf] [-c config] [-d number]
+
+ -h : this (help) message
+ -c <file> : config file (default: ${config})
+ -x <cfg> : dump configuration to stdout
+ ( 1 = current, 2 = default )
+ -f : foreground (don't fork)
-v : be verbose (multiple to increase verbosity)
'v': error logs
'vvv': warning plus error logs
256 : creation of packages_list_db
512 : ARP debug information
EOF
- exit(0);
+}
+ print( "\n" );
+
+ exit( -1 );
+}
+
+#############################
+#
+# @brief Manage gosa-si-client configuration.
+#
+# Will exit after successfull dump to stdout (type = 1 | 2)
+#
+# Dump type can be:
+# 1: Current gosa-si-client configuration in config file (exit)
+# 2: Default gosa-si-client configuration (exit)
+# 3: Dump to logfile (no exit)
+#
+# @param int config type
+#
+sub dump_configuration {
+
+ my( $cfg_type ) = @_;
+
+ return if( ! defined $cfg_type );
+
+ if(1==$cfg_type ) {
+ print( "# Current gosa-si-server configuration\n" );
+ } elsif (2==$cfg_type) {
+ print( "# Default gosa-si-server configuration\n" );
+ } elsif (3==$cfg_type) {
+ daemon_log( "Dumping gosa-si-server configuration\n", 2 );
+ } else {
+ return;
+ }
+
+ foreach my $section (keys %cfg_defaults) {
+ if( 3 != $cfg_type ) {
+ print( "\n[${section}]\n" );
+ } else {
+ daemon_log( "\n [${section}]\n", 3 );
+ }
+
+ foreach my $param (sort( keys %{$cfg_defaults{ $section }})) {
+ my $pinfo = $cfg_defaults{ $section }{ $param };
+ my $value;
+ if (1==$cfg_type) {
+ if( defined( ${@$pinfo[ 0 ]} ) ) {
+ $value = ${@$pinfo[ 0 ]};
+ print( "$param=$value\n" );
+ } else {
+ print( "#${param}=\n" );
+ }
+ } elsif (2==$cfg_type) {
+ $value = @{$pinfo}[ 1 ];
+ if( defined( @$pinfo[ 1 ] ) ) {
+ $value = @{$pinfo}[ 1 ];
+ print( "$param=$value\n" );
+ } else {
+ print( "#${param}=\n" );
+ }
+ } elsif (3==$cfg_type) {
+ if( defined( ${@$pinfo[ 0 ]} ) ) {
+ $value = ${@$pinfo[ 0 ]};
+ daemon_log( " $param=$value\n", 3 )
+ }
+ }
+ }
+ }
+
+
+# We just exit at stdout dump
+ if( 3 == $cfg_type ) {
+ daemon_log( "\n", 3 );
+ } else {
+ exit( 0 );
+ }
}
#=== FUNCTION ================================================================
# NAME: sig_int_handler
-# PARAMETERS: signal - string - signal arose from system
+# PARAMETERS: signal - string - signal came from system
# RETURNS: nothing
-# DESCRIPTION: handels tasks to be done befor signal becomes active
+# DESCRIPTION: handle tasks to be done before signal becomes active
#===============================================================================
sub sig_int_handler {
my ($signal) = @_;
daemon_log("shutting down gosa-si-server", 1);
- #$global_kernel->yield('shutdown');
+ $global_kernel->yield('shutdown');
+
+ # to be removed rather crude !!
+ #system("kill `ps -C gosa-si-server -o pid=`");
- system("kill `ps -C gosa-si-server -o pid=`");
+ $pid->remove or warn "Could not remove $pidfile\n";
exit(0);
}
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-arp+" => \$no_arp,
- "d=s" => \$debug_parts,
- ) or &usage("", 1);
+#
+# Parse options and allow '-vvv'
+Getopt::Long::Configure( 'bundling' );
+GetOptions( 'v|verbose+' => \$verbose,
+ 'h|help' => \&usage,
+ 'c|config=s' => \$config,
+ 'x|dump-config=i' => \$dump_config,
+ 'f|foreground' => \$foreground)
+ 'd=s' => \$debug_parts,
+ or usage( '', 1 );
+
+# We may want to dump the default configuration
+if( defined $dump_config ) {
+ if($dump_config==1) {
+ } elsif ($dump_config==2) {
+ dump_configuration( $dump_config );
+ } else {
+ usage( "Dump configuration value has to be 1 or 2" );
+ }
+}
# read and set config parameters
-&check_cmdline_param ;
-&read_configfile($cfg_file, %cfg_defaults);
-&check_pid;
+#&check_cmdline_param ;
+#&read_configfile($cfg_file, %cfg_defaults);
+&read_configfile($config, %cfg_defaults);
+#&check_pid;
+# not sure but seems to be for igonring phantom
$SIG{CHLD} = 'IGNORE';
+# Create the PID object
+# Ensure you put a name that won't clobber
+# another program's PID file
+my $pid = File::Pid->new({
+ file => $pidfile,
+});
+
+# Write the PID file
+$pid->write;
+
# forward error messages to logfile
if( ! $foreground ) {
open( STDIN, '+>/dev/null' );
$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 $server_status_hash = { 'developmental'=>'revision', 'stable'=>'release'};
daemon_log("0 INFO: importing database module '$db_module'", 1);
# connect to incoming_db
- $incoming_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
+ $incoming_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
# connect to gosa-si job queue
- $job_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
+ $job_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
# connect to known_clients_db
- $known_clients_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
+ $known_clients_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
# connect to foreign_clients_db
- $foreign_clients_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
+ $foreign_clients_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
# connect to known_server_db
- $known_server_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
+ $known_server_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
# connect to login_usr_db
- $login_users_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
+ $login_users_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
# connect to fai_server_db
- $fai_server_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
+ $fai_server_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
# connect to fai_release_db
- $fai_release_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
+ $fai_release_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
# connect to packages_list_db
- $packages_list_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
+ $packages_list_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
# connect to messaging_db
- $messaging_db = ("GOSA::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
+ $messaging_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
} elsif ($db_module eq "DBsqlite") {
# connect to incoming_db
unlink($incoming_file_name);
- $incoming_db = GOSA::DBsqlite->new($incoming_file_name);
+ $incoming_db = ("GOsaSI::".$db_module)->new($incoming_file_name);
chmod(0640, $incoming_file_name);
chown($root_uid, $adm_gid, $incoming_file_name);
# connect to gosa-si job queue
- $job_db = GOSA::DBsqlite->new($job_queue_file_name);
+ $job_db = ("GOsaSI::".$db_module)->new($job_queue_file_name);
chmod(0640, $job_queue_file_name);
chown($root_uid, $adm_gid, $job_queue_file_name);
# connect to known_clients_db
#unlink($known_clients_file_name);
- $known_clients_db = GOSA::DBsqlite->new($known_clients_file_name);
+ $known_clients_db = ("GOsaSI::".$db_module)->new($known_clients_file_name);
chmod(0640, $known_clients_file_name);
chown($root_uid, $adm_gid, $known_clients_file_name);
# connect to foreign_clients_db
#unlink($foreign_clients_file_name);
- $foreign_clients_db = GOSA::DBsqlite->new($foreign_clients_file_name);
+ $foreign_clients_db = ("GOsaSI::".$db_module)->new($foreign_clients_file_name);
chmod(0640, $foreign_clients_file_name);
chown($root_uid, $adm_gid, $foreign_clients_file_name);
# connect to known_server_db
unlink($known_server_file_name); # do not delete, gosa-si-server should be forced to check config file and dns at each start
- $known_server_db = GOSA::DBsqlite->new($known_server_file_name);
+ $known_server_db = ("GOsaSI::".$db_module)->new($known_server_file_name);
chmod(0640, $known_server_file_name);
chown($root_uid, $adm_gid, $known_server_file_name);
# connect to login_usr_db
#unlink($login_users_file_name);
- $login_users_db = GOSA::DBsqlite->new($login_users_file_name);
+ $login_users_db = ("GOsaSI::".$db_module)->new($login_users_file_name);
chmod(0640, $login_users_file_name);
chown($root_uid, $adm_gid, $login_users_file_name);
# connect to fai_server_db
unlink($fai_server_file_name);
- $fai_server_db = GOSA::DBsqlite->new($fai_server_file_name);
+ $fai_server_db = ("GOsaSI::".$db_module)->new($fai_server_file_name);
chmod(0640, $fai_server_file_name);
chown($root_uid, $adm_gid, $fai_server_file_name);
# connect to fai_release_db
unlink($fai_release_file_name);
- $fai_release_db = GOSA::DBsqlite->new($fai_release_file_name);
+ $fai_release_db = ("GOsaSI::".$db_module)->new($fai_release_file_name);
chmod(0640, $fai_release_file_name);
chown($root_uid, $adm_gid, $fai_release_file_name);
# connect to packages_list_db
unlink($packages_list_under_construction);
- $packages_list_db = GOSA::DBsqlite->new($packages_list_file_name);
+ $packages_list_db = ("GOsaSI::".$db_module)->new($packages_list_file_name);
chmod(0640, $packages_list_file_name);
chown($root_uid, $adm_gid, $packages_list_file_name);
# connect to messaging_db
#unlink($messaging_file_name);
- $messaging_db = GOSA::DBsqlite->new($messaging_file_name);
+ $messaging_db = ("GOsaSI::".$db_module)->new($messaging_file_name);
chmod(0640, $messaging_file_name);
chown($root_uid, $adm_gid, $messaging_file_name);
}