Skip to content

Commit 62522bc

Browse files
authored
Support /etc/sysctl.d/ for Debian-based systems (#7509)
On Debian-based systems, /etc/sysctl.conf doesn't exist and /etc/sysctl.d/ directory is used instead. Modified xcatconfig to prefer /etc/sysctl.d/99-xcat.conf when the directory exists, falling back to /etc/sysctl.conf for backward compatibility.
1 parent 9bcdb35 commit 62522bc

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

xCAT-server/sbin/xcatconfig

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -867,23 +867,43 @@ sub settunables
867867
}
868868

869869
# set for after reboot
870-
if (!(-f "/etc/sysctl.conf.xcatbackup")) { # not already backed up
871-
$cmd = "cp /etc/sysctl.conf /etc/sysctl.conf.xcatbackup";
870+
my $sysctl_file;
871+
if (-d "/etc/sysctl.d") {
872+
$sysctl_file = "/etc/sysctl.d/99-xcat.conf";
873+
if (!(-f "$sysctl_file")) {
874+
$cmd = "touch $sysctl_file";
875+
my $outref = xCAT::Utils->runcmd("$cmd", 0);
876+
if ($::RUNCMD_RC != 0)
877+
{
878+
xCAT::MsgUtils->message('E', "Could not create $sysctl_file.");
879+
exit 1;
880+
}
881+
}
882+
} elsif (-f "/etc/sysctl.conf") {
883+
$sysctl_file = "/etc/sysctl.conf";
884+
} else {
885+
xCAT::MsgUtils->message('E', "Could not find /etc/sysctl.d directory or /etc/sysctl.conf.");
886+
exit 1;
887+
}
888+
889+
my $sysctl_backup = "$sysctl_file.xcatbackup";
890+
if (!(-f "$sysctl_backup")) {
891+
$cmd = "cp $sysctl_file $sysctl_backup";
872892
my $outref = xCAT::Utils->runcmd("$cmd", 0);
873893
if ($::RUNCMD_RC != 0)
874894
{
875-
xCAT::MsgUtils->message('E', "Could not backup /etc/sysctl.conf.");
895+
xCAT::MsgUtils->message('E', "Could not backup $sysctl_file.");
876896
exit 1;
877897
}
878898
}
879899

880900
#delete all occurance of the attribute and then add xCAT settings
881-
`sed -i '/net.ipv4.neigh.default.gc_thresh1 /'d /etc/sysctl.conf`;
882-
`echo "net.ipv4.neigh.default.gc_thresh1 = 1024" >>/etc/sysctl.conf`;
883-
`sed -i '/net.ipv4.neigh.default.gc_thresh2 /'d /etc/sysctl.conf`;
884-
`echo "net.ipv4.neigh.default.gc_thresh2 = 4096" >>/etc/sysctl.conf`;
885-
`sed -i '/net.ipv4.neigh.default.gc_thresh3 /'d /etc/sysctl.conf`;
886-
`echo "net.ipv4.neigh.default.gc_thresh3 = 8192" >>/etc/sysctl.conf`;
901+
`sed -i '/net.ipv4.neigh.default.gc_thresh1 /'d $sysctl_file`;
902+
`echo "net.ipv4.neigh.default.gc_thresh1 = 1024" >>$sysctl_file`;
903+
`sed -i '/net.ipv4.neigh.default.gc_thresh2 /'d $sysctl_file`;
904+
`echo "net.ipv4.neigh.default.gc_thresh2 = 4096" >>$sysctl_file`;
905+
`sed -i '/net.ipv4.neigh.default.gc_thresh3 /'d $sysctl_file`;
906+
`echo "net.ipv4.neigh.default.gc_thresh3 = 8192" >>$sysctl_file`;
887907

888908
}
889909

0 commit comments

Comments
 (0)