|
Lines 130-135
sub sanityCheckParams {
Link Here
|
| 130 |
return @errs; |
130 |
return @errs; |
| 131 |
} |
131 |
} |
| 132 |
|
132 |
|
|
|
133 |
# We need to make sure this value is lowercase |
| 134 |
$inf->{slapd}->{InstScriptsEnabled} = lc $inf->{slapd}->{InstScriptsEnabled}; |
| 135 |
|
| 136 |
if ("true" ne $inf->{slapd}->{InstScriptsEnabled} && "false" ne $inf->{slapd}->{InstScriptsEnabled}) { |
| 137 |
debug(1, "InstScriptsEnabled is not a valid boolean"); |
| 138 |
return ('error_invalid_boolean', $inf->{slapd}->{InstScriptsEnabled}); |
| 139 |
} |
| 140 |
|
| 141 |
|
| 133 |
return (); |
142 |
return (); |
| 134 |
} |
143 |
} |
| 135 |
|
144 |
|
|
Lines 204-216
sub makeDSDirs {
Link Here
|
| 204 |
my $mode = getMode($inf, 7); |
213 |
my $mode = getMode($inf, 7); |
| 205 |
my @errs; |
214 |
my @errs; |
| 206 |
|
215 |
|
|
|
216 |
my @dsdirs = qw(config_dir schema_dir log_dir lock_dir run_dir tmp_dir cert_dir db_dir ldif_dir bak_dir); |
| 217 |
if ($inf->{slapd}->{InstScriptsEnabled} eq "true") { |
| 218 |
@dsdirs = qw(inst_dir config_dir schema_dir log_dir lock_dir run_dir tmp_dir cert_dir db_dir ldif_dir bak_dir); |
| 219 |
} |
| 220 |
|
| 207 |
# These paths are owned by the SuiteSpotGroup |
221 |
# These paths are owned by the SuiteSpotGroup |
| 208 |
# This allows the admin server to run as a different, |
222 |
# This allows the admin server to run as a different, |
| 209 |
# more privileged user than the directory server, but |
223 |
# more privileged user than the directory server, but |
| 210 |
# still allows the admin server to manage directory |
224 |
# still allows the admin server to manage directory |
| 211 |
# server files/dirs without being root |
225 |
# server files/dirs without being root |
| 212 |
for my $kw (qw(inst_dir config_dir schema_dir log_dir lock_dir run_dir tmp_dir |
226 |
for my $kw (@dsdirs) { |
| 213 |
cert_dir db_dir ldif_dir bak_dir)) { |
|
|
| 214 |
my $dir = $inf->{slapd}->{$kw}; |
227 |
my $dir = $inf->{slapd}->{$kw}; |
| 215 |
@errs = makePaths($dir, $mode, $inf->{General}->{SuiteSpotUserID}, |
228 |
@errs = makePaths($dir, $mode, $inf->{General}->{SuiteSpotUserID}, |
| 216 |
$inf->{General}->{SuiteSpotGroup}); |
229 |
$inf->{General}->{SuiteSpotGroup}); |
|
Lines 262-317
sub createInstanceScripts {
Link Here
|
| 262 |
my $myperl = "!$perlexec"; |
275 |
my $myperl = "!$perlexec"; |
| 263 |
my $mydevnull = (-f "/dev/null" ? " /dev/null " : " NUL "); |
276 |
my $mydevnull = (-f "/dev/null" ? " /dev/null " : " NUL "); |
| 264 |
|
277 |
|
| 265 |
# determine initconfig_dir |
278 |
# If we have InstScriptsEnabled, we likely have setup.inf or the argument. |
| 266 |
my $initconfig_dir = $inf->{slapd}->{initconfig_dir} || get_initconfigdir($inf->{General}->{prefix}); |
279 |
# However, during an upgrade, we need to know if we should upgrade the template files or not. |
| 267 |
|
280 |
# For now, the easiest way is to check to if the directory exists, and if is does, we assume we want to upgrade / create the updated scripts. |
| 268 |
my %maptable = ( |
281 |
if ($inf->{slapd}->{InstScriptsEnabled} eq "true" || -d $inf->{slapd}->{inst_dir} ) { |
| 269 |
"DS-ROOT" => $inf->{General}->{prefix}, |
282 |
debug(1, "Creating or updating instance directory scripts\n"); |
| 270 |
"SEP" => "/", # works on all platforms |
283 |
# determine initconfig_dir |
| 271 |
"SERVER-NAME" => $inf->{General}->{FullMachineName}, |
284 |
my $initconfig_dir = $inf->{slapd}->{initconfig_dir} || get_initconfigdir($inf->{General}->{prefix}); |
| 272 |
"SERVER-PORT" => $inf->{slapd}->{ServerPort}, |
285 |
|
| 273 |
"PERL-EXEC" => $myperl, |
286 |
my %maptable = ( |
| 274 |
"DEV-NULL" => $mydevnull, |
287 |
"DS-ROOT" => $inf->{General}->{prefix}, |
| 275 |
"ROOT-DN" => $inf->{slapd}->{RootDN}, |
288 |
"SEP" => "/", # works on all platforms |
| 276 |
"LDIF-DIR" => $inf->{slapd}->{ldif_dir}, |
289 |
"SERVER-NAME" => $inf->{General}->{FullMachineName}, |
| 277 |
"SERV-ID" => $inf->{slapd}->{ServerIdentifier}, |
290 |
"SERVER-PORT" => $inf->{slapd}->{ServerPort}, |
| 278 |
"BAK-DIR" => $inf->{slapd}->{bak_dir}, |
291 |
"PERL-EXEC" => $myperl, |
| 279 |
"SERVER-DIR" => $inf->{General}->{ServerRoot}, |
292 |
"DEV-NULL" => $mydevnull, |
| 280 |
"CONFIG-DIR" => $inf->{slapd}->{config_dir}, |
293 |
"ROOT-DN" => $inf->{slapd}->{RootDN}, |
| 281 |
"INITCONFIG-DIR" => $initconfig_dir, |
294 |
"LDIF-DIR" => $inf->{slapd}->{ldif_dir}, |
| 282 |
"INST-DIR" => $inf->{slapd}->{inst_dir}, |
295 |
"SERV-ID" => $inf->{slapd}->{ServerIdentifier}, |
| 283 |
"RUN-DIR" => $inf->{slapd}->{run_dir}, |
296 |
"BAK-DIR" => $inf->{slapd}->{bak_dir}, |
| 284 |
"PRODUCT-NAME" => "slapd", |
297 |
"SERVER-DIR" => $inf->{General}->{ServerRoot}, |
| 285 |
"SERVERBIN-DIR" => $inf->{slapd}->{sbindir}, |
298 |
"CONFIG-DIR" => $inf->{slapd}->{config_dir}, |
| 286 |
"DB-DIR" => $inf->{slapd}->{db_dir} |
299 |
"INITCONFIG-DIR" => $initconfig_dir, |
| 287 |
); |
300 |
"INST-DIR" => $inf->{slapd}->{inst_dir}, |
| 288 |
|
301 |
"RUN-DIR" => $inf->{slapd}->{run_dir}, |
| 289 |
my $dir = "$inf->{General}->{prefix}@taskdir@"; |
302 |
"PRODUCT-NAME" => "slapd", |
| 290 |
for my $file (glob("$dir/template-*")) { |
303 |
"SERVERBIN-DIR" => $inf->{slapd}->{sbindir}, |
| 291 |
my $basename = $file; |
304 |
"DB-DIR" => $inf->{slapd}->{db_dir} |
| 292 |
$basename =~ s/^.*template-//; |
305 |
); |
| 293 |
my $destfile = "$inf->{slapd}->{inst_dir}/$basename"; |
306 |
|
| 294 |
|
307 |
|
| 295 |
next if ($skip and -f $destfile); # in skip mode, skip files that already exist |
308 |
my $dir = "$inf->{General}->{prefix}@taskdir@"; |
| 296 |
|
309 |
for my $file (glob("$dir/template-*")) { |
| 297 |
if (!open(SRC, "< $file")) { |
310 |
my $basename = $file; |
| 298 |
return ("error_opening_scripttmpl", $file, $!); |
311 |
$basename =~ s/^.*template-//; |
| 299 |
} |
312 |
my $destfile = "$inf->{slapd}->{inst_dir}/$basename"; |
| 300 |
if (!open(DEST, "> $destfile")) { |
313 |
debug(1, "$destfile\n"); |
| 301 |
return ("error_opening_scripttmpl", $destfile, $!); |
314 |
|
| 302 |
} |
315 |
next if ($skip and -f $destfile); # in skip mode, skip files that already exist |
| 303 |
my $contents; # slurp entire file into memory |
316 |
|
| 304 |
read SRC, $contents, int(-s $file); |
317 |
if (!open(SRC, "< $file")) { |
| 305 |
close(SRC); |
318 |
return ("error_opening_scripttmpl", $file, $!); |
| 306 |
while (my ($key, $val) = each %maptable) { |
319 |
} |
| 307 |
$contents =~ s/\{\{$key\}\}/$val/g; |
320 |
if (!open(DEST, "> $destfile")) { |
| 308 |
} |
321 |
return ("error_opening_scripttmpl", $destfile, $!); |
| 309 |
print DEST $contents; |
322 |
} |
| 310 |
close(DEST); |
323 |
my $contents; # slurp entire file into memory |
| 311 |
my @errs = changeOwnerMode($inf, 5, $destfile); |
324 |
read SRC, $contents, int(-s $file); |
| 312 |
if (@errs) { |
325 |
close(SRC); |
| 313 |
return @errs; |
326 |
while (my ($key, $val) = each %maptable) { |
|
|
327 |
$contents =~ s/\{\{$key\}\}/$val/g; |
| 328 |
} |
| 329 |
print DEST $contents; |
| 330 |
close(DEST); |
| 331 |
my @errs = changeOwnerMode($inf, 5, $destfile); |
| 332 |
if (@errs) { |
| 333 |
return @errs; |
| 334 |
} |
| 314 |
} |
335 |
} |
|
|
336 |
} else { |
| 337 |
debug(1, "No instance directory scripts will be updated or created\n"); |
| 315 |
} |
338 |
} |
| 316 |
|
339 |
|
| 317 |
return (); |
340 |
return (); |
|
Lines 639-645
sub initDatabase {
Link Here
|
| 639 |
return (); |
662 |
return (); |
| 640 |
} |
663 |
} |
| 641 |
|
664 |
|
| 642 |
my $cmd = "$inf->{slapd}->{inst_dir}/ldif2db -n $inf->{slapd}->{ds_bename} -i \'$ldiffile\'"; |
665 |
my $cmd = "$inf->{slapd}->{sbindir}/ldif2db -Z $inf->{slapd}->{ServerIdentifier} -n $inf->{slapd}->{ds_bename} -i \'$ldiffile\'"; |
| 643 |
$? = 0; # clear error condition |
666 |
$? = 0; # clear error condition |
| 644 |
my $output = `$cmd 2>&1`; |
667 |
my $output = `$cmd 2>&1`; |
| 645 |
my $result = $?; |
668 |
my $result = $?; |
|
Lines 662-668
sub startServer {
Link Here
|
| 662 |
my @errs; |
685 |
my @errs; |
| 663 |
# get error log |
686 |
# get error log |
| 664 |
my $errLog = "$inf->{slapd}->{log_dir}/errors"; |
687 |
my $errLog = "$inf->{slapd}->{log_dir}/errors"; |
| 665 |
my $startcmd = "$inf->{slapd}->{inst_dir}/start-slapd"; |
688 |
my $startcmd = "$inf->{slapd}->{sbindir}/start-dirsrv $inf->{slapd}->{ServerIdentifier}"; |
| 666 |
if ("@systemdsystemunitdir@" and (getLogin() eq 'root')) { |
689 |
if ("@systemdsystemunitdir@" and (getLogin() eq 'root')) { |
| 667 |
$startcmd = "/bin/systemctl start @package_name@\@$inf->{slapd}->{ServerIdentifier}.service"; |
690 |
$startcmd = "/bin/systemctl start @package_name@\@$inf->{slapd}->{ServerIdentifier}.service"; |
| 668 |
} |
691 |
} |
|
Lines 875-880
sub setDefaults {
Link Here
|
| 875 |
"@datadir@", |
898 |
"@datadir@", |
| 876 |
$inf->{General}->{prefix}); |
899 |
$inf->{General}->{prefix}); |
| 877 |
|
900 |
|
|
|
901 |
if (!defined($inf->{slapd}->{InstScriptsEnabled})) { |
| 902 |
$inf->{slapd}->{InstScriptsEnabled} = "false"; |
| 903 |
} |
| 904 |
|
| 878 |
if (!defined($inf->{slapd}->{inst_dir})) { |
905 |
if (!defined($inf->{slapd}->{inst_dir})) { |
| 879 |
$inf->{slapd}->{inst_dir} = "$inf->{General}->{ServerRoot}/slapd-$servid"; |
906 |
$inf->{slapd}->{inst_dir} = "$inf->{General}->{ServerRoot}/slapd-$servid"; |
| 880 |
} |
907 |
} |
|
Lines 975-983
sub updateSelinuxPolicy {
Link Here
|
| 975 |
system("restorecon -R $localstatedir/lib/@PACKAGE_NAME@"); |
1002 |
system("restorecon -R $localstatedir/lib/@PACKAGE_NAME@"); |
| 976 |
} |
1003 |
} |
| 977 |
|
1004 |
|
|
|
1005 |
my @inst_dirs = qw(config_dir schema_dir log_dir lock_dir run_dir tmp_dir cert_dir db_dir ldif_dir bak_dir); |
| 1006 |
if ($inf->{slapd}->{InstScriptsEnabled} eq "true") { |
| 1007 |
@inst_dirs = qw(inst_dir config_dir schema_dir log_dir lock_dir run_dir tmp_dir cert_dir db_dir ldif_dir bak_dir); |
| 1008 |
} |
| 978 |
# run restorecon on all instance directories we created |
1009 |
# run restorecon on all instance directories we created |
| 979 |
for my $kw (qw(inst_dir config_dir schema_dir log_dir lock_dir run_dir tmp_dir |
1010 |
for my $kw (@inst_dirs) { |
| 980 |
cert_dir db_dir ldif_dir bak_dir)) { |
|
|
| 981 |
my $dir = $inf->{slapd}->{$kw}; |
1011 |
my $dir = $inf->{slapd}->{$kw}; |
| 982 |
system("restorecon -R $dir"); |
1012 |
system("restorecon -R $dir"); |
| 983 |
} |
1013 |
} |
|
Lines 1231-1244
sub createDSInstance {
Link Here
|
| 1231 |
} |
1261 |
} |
| 1232 |
|
1262 |
|
| 1233 |
sub stopServer { |
1263 |
sub stopServer { |
| 1234 |
my $instancedir = shift; |
1264 |
my $instance = shift; |
| 1235 |
my $prog = $instancedir . "/stop-slapd"; |
1265 |
my $prog = "@sbindir@/stop-dirsrv"; |
| 1236 |
if (-x $prog) { |
1266 |
if (-x $prog) { |
| 1237 |
$? = 0; |
1267 |
$? = 0; |
| 1238 |
# run the stop command |
1268 |
# run the stop command |
| 1239 |
my $output = `$prog 2>&1`; |
1269 |
my $output = `$prog $instance 2>&1`; |
| 1240 |
my $status = $?; |
1270 |
my $status = $?; |
| 1241 |
debug(3, "stopping server $instancedir returns status $status: output $output\n"); |
1271 |
debug(3, "stopping server $instance returns status $status: output $output\n"); |
| 1242 |
if ($status) { |
1272 |
if ($status) { |
| 1243 |
debug(1,"Warning: Could not stop directory server: status $status: output $output\n"); |
1273 |
debug(1,"Warning: Could not stop directory server: status $status: output $output\n"); |
| 1244 |
# if the server is not running, that's ok |
1274 |
# if the server is not running, that's ok |
|
Lines 1254-1260
sub stopServer {
Link Here
|
| 1254 |
return; |
1284 |
return; |
| 1255 |
} |
1285 |
} |
| 1256 |
|
1286 |
|
| 1257 |
debug(1, "Successfully stopped server $instancedir\n"); |
1287 |
debug(1, "Successfully stopped server $instance\n"); |
| 1258 |
return 1; |
1288 |
return 1; |
| 1259 |
} |
1289 |
} |
| 1260 |
|
1290 |
|
|
Lines 1331-1353
sub removeDSInstance {
Link Here
|
| 1331 |
$conn->close(); |
1361 |
$conn->close(); |
| 1332 |
|
1362 |
|
| 1333 |
# stop the server |
1363 |
# stop the server |
| 1334 |
my $instdir = ""; |
1364 |
if (!stopServer($inst)) { |
| 1335 |
if ($entry) { |
1365 |
if ($force) { |
| 1336 |
foreach my $path ( @{$entry->{"nsslapd-instancedir"}} ) |
1366 |
debug(1, "Warning: Could not stop directory server - Error: $! - forcing continue\n"); |
| 1337 |
{ |
1367 |
} elsif ($! == ENOENT) { # stop script not found or server not running |
| 1338 |
if (!stopServer($path)) { |
1368 |
debug(1, "Warning: Could not stop directory server: already removed or not running\n"); |
| 1339 |
if ($force) { |
1369 |
push @errs, [ 'error_stopping_server', $inst, $! ]; |
| 1340 |
debug(1, "Warning: Could not stop directory server - Error: $! - forcing continue\n"); |
1370 |
} else { # real error |
| 1341 |
} elsif ($! == ENOENT) { # stop script not found or server not running |
1371 |
debug(1, "Error: Could not stop directory server - aborting - use -f flag to force removal\n"); |
| 1342 |
debug(1, "Warning: Could not stop directory server: already removed or not running\n"); |
1372 |
push @errs, [ 'error_stopping_server', $inst, $! ]; |
| 1343 |
push @errs, [ 'error_stopping_server', $path, $! ]; |
1373 |
return @errs; |
| 1344 |
} else { # real error |
|
|
| 1345 |
debug(1, "Error: Could not stop directory server - aborting - use -f flag to force removal\n"); |
| 1346 |
push @errs, [ 'error_stopping_server', $path, $! ]; |
| 1347 |
return @errs; |
| 1348 |
} |
| 1349 |
} |
| 1350 |
$instdir = $path; |
| 1351 |
} |
1374 |
} |
| 1352 |
} |
1375 |
} |
| 1353 |
|
1376 |
|
|
Lines 1363-1380
sub removeDSInstance {
Link Here
|
| 1363 |
push @errs, remove_tree($entry, "nsslapd-errorlog", $instname, 1); |
1386 |
push @errs, remove_tree($entry, "nsslapd-errorlog", $instname, 1); |
| 1364 |
} |
1387 |
} |
| 1365 |
|
1388 |
|
| 1366 |
# instance dir |
|
|
| 1367 |
if ( -d $instdir && $instdir =~ /$instname/ ) |
| 1368 |
{ |
| 1369 |
# clean up pid files (if any) |
| 1370 |
remove_pidfile("STARTPIDFILE", $inst, $instdir, $instname, $rundir, $product_name); |
| 1371 |
remove_pidfile("PIDFILE", $inst, $instdir, $instname, $rundir, $product_name); |
| 1372 |
|
1389 |
|
| 1373 |
my $rc = rmtree($instdir); |
1390 |
# instance dir |
| 1374 |
if ( 0 == $rc ) |
1391 |
my $instdir = ""; |
|
|
1392 |
if ($entry) { |
| 1393 |
foreach my $instdir ( @{$entry->{"nsslapd-instancedir"}} ) |
| 1375 |
{ |
1394 |
{ |
| 1376 |
push @errs, [ 'error_removing_path', $instdir, $! ]; |
1395 |
if ( -d $instdir && $instdir =~ /$instname/ ) |
| 1377 |
debug(1, "Warning: $instdir was not removed. Error: $!\n"); |
1396 |
{ |
|
|
1397 |
# clean up pid files (if any) |
| 1398 |
remove_pidfile("STARTPIDFILE", $inst, $instdir, $instname, $rundir, $product_name); |
| 1399 |
remove_pidfile("PIDFILE", $inst, $instdir, $instname, $rundir, $product_name); |
| 1400 |
|
| 1401 |
my $rc = rmtree($instdir); |
| 1402 |
if ( 0 == $rc ) |
| 1403 |
{ |
| 1404 |
push @errs, [ 'error_removing_path', $instdir, $! ]; |
| 1405 |
debug(1, "Warning: $instdir was not removed. Error: $!\n"); |
| 1406 |
} |
| 1407 |
} |
| 1378 |
} |
1408 |
} |
| 1379 |
} |
1409 |
} |
| 1380 |
# Finally, config dir |
1410 |
# Finally, config dir |