Commit ed606a90 authored by etiennemeleard's avatar etiennemeleard
Browse files

[*change] Default config location is now /etc/sympa/ (or $sysconfig/sympa/)...

[*change] Default config location is now /etc/sympa/ (or $sysconfig/sympa/) instead of /etc/. This solves the problem of config file lock creation being denied when trying to read the binary version of the config file at startup. WARNING : to upgrade the config location one MUST run sympa.pl --upgrade_config_location before any other upgrading operation.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@11475 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 3619845c
......@@ -60,7 +60,7 @@ if test "$fhs" = "yes"; then
spooldir=$localstatedir/spool/sympa
arcdir=$localstatedir/lib/sympa/arc
bouncedir=$localstatedir/lib/sympa/bounce
confdir=$sysconfdir
confdir=$sysconfdir/sympa
else
# redefine default values for some standard variables,
# but only if no value was given
......@@ -91,7 +91,7 @@ else
staticdir=$prefix/static_content
arcdir=$prefix/arc
bouncedir=$prefix/bounce
confdir=/etc
confdir=/etc/sympa
fi
# substitute custom variables
......
......@@ -2421,7 +2421,7 @@ sub _load_binary_cache {
my $lock_fh = Sympa::LockedFile->new($param->{'config_file'}, 2, '<');
unless ($lock_fh) {
Log::do_log('err', 'Could not create new lock');
Log::do_log('err', 'Could not create new lock, error was : %s', Sympa::LockedFile::last_error());
return undef;
}
......
......@@ -30,6 +30,8 @@ use Encode qw();
use English qw(-no_match_vars);
use File::Find qw();
use File::Path qw();
use File::Basename;
use Fcntl ':mode';
use POSIX qw();
use Sympa::Archive;
......
......@@ -98,6 +98,7 @@ unless (
'conf_2_db', 'export_list',
'health_check', 'service=s',
'send_digest', 'keep_digest',
'upgrade_config_location',
)
) {
pod2usage(-exitval => 1, -output => \*STDERR);
......@@ -132,7 +133,8 @@ $main::options{'batch'} = 1
|| $main::options{'sync_list_db'}
|| $main::options{'export_list'}
|| $main::options{'health_check'}
|| $main::options{'send_digest'};
|| $main::options{'send_digest'}
|| $main::options{'upgrade_config_location'};
# Some option force foreground mode
$main::options{'foreground'} = 1
......@@ -150,6 +152,54 @@ if ($main::options{'help'}) {
} elsif ($main::options{'version'}) {
printf "Sympa %s\n", Sympa::Constants::VERSION;
exit 0;
} elsif ($main::options{'upgrade_config_location'}) {
my $config_file = Conf::get_sympa_conf();
if(-f $config_file) {
printf "Sympa configuration already located at %s\n", $config_file;
exit 0;
}
my ($file, $dir, $suffix) = File::Basename::fileparse($config_file);
my $old_dir = $dir;
$old_dir =~ s/sympa\///;
# Try to create config path if it does not exist
unless(-d $dir) {
my $error;
File::Path::make_path($dir, {mode => 0755, owner => 'sympa', group => 'sympa', error => \$error});
if(@$error) {
my $diag = pop @$error;
my ($target, $error) = %$diag;
die "Unable to create $target: $error";
}
}
# Check ownership of config folder
my @stat = stat($dir);
my $user = (getpwuid $stat[4])[0];
if($user ne 'sympa') {
die "Config dir $dir exists but is not owned by sympa (owned by $user)";
}
# Check permissions on config folder
if(($stat[2] & Fcntl::S_IRWXU) != Fcntl::S_IRWXU) {
die "Config dir $dir exists, but sympa does not have rwx permissions on it";
}
# Move files from old location to new one
opendir(my $dh, $old_dir) or die("Could not open $dir for reading");
my @files = grep(/^(ww)?sympa\.conf.*$/, readdir($dh));
closedir($dh);
foreach my $file (@files) {
unless(File::Copy::move("$old_dir/$file", "$dir/$file")) {
die "Could not move $old_dir/$file to $dir/$file : $!";
}
}
printf "Sympa configuration moved to $dir\n";
exit 0;
} elsif ($main::options{'health_check'}) {
## Health check
......
......@@ -30,6 +30,10 @@ use Getopt::Long;
use Pod::Usage;
use Sys::Hostname qw();
use File::Path;
use File::Basename;
use Fcntl ':mode';
use Sympa::ConfDef;
use Sympa::Constants;
use Sympa::ModDef;
......@@ -129,6 +133,29 @@ sub create_configuration {
print STDERR "$conf file already exists, exiting\n";
exit 1;
}
# Try to create config path
my ($file, $dir, $suffix) = File::Basename::fileparse($conf);
my $error;
File::Path::make_path($dir, {mode => 0755, owner => 'sympa', group => 'sympa', error => \$error});
if(@$error) {
my $diag = pop @$error;
my ($target, $error) = %$diag;
die "Unable to create $target: $error";
}
# Check ownership of config folder
my @stat = stat($dir);
my $user = (getpwuid $stat[4])[0];
if($user ne 'sympa') {
die "Config dir $dir exists but is not owned by sympa (owned by $user)";
}
# Check permissions on config folder
if(($stat[2] & Fcntl::S_IRWXU) != Fcntl::S_IRWXU) {
die "Config dir $dir exists, but sympa does not have rwx permissions on it";
}
unless (open NEWF, '>', $conf) {
die "Unable to open $conf: $ERRNO";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment