Skip to content

Commit

Permalink
chore: 🤖 setup logrotate pt2
Browse files Browse the repository at this point in the history
  • Loading branch information
heldrida committed Oct 30, 2023
1 parent 8fcc2e1 commit 934378a
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions scripts/install_native
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ defaultPortRangeUDPStart=4300
defaultPortRangeUDPEnd=4399
defaultPortRangeTCP="$defaultPortRangeTCPStart-$defaultPortRangeTCPStart"
defaultPortRangeUDP="$defaultPortRangeUDPStart-$defaultPortRangeUDPEnd"
defaultLogRotateBinFilename="logrotate"
defaultLogRotateConfigFile="/etc/logrotate.conf"
defaultLogRotatePath="/etc/logrotate.d"
defaultLogRotateLightningConf="/etc/logrotate.d/$defaultName"
Expand Down Expand Up @@ -214,17 +215,23 @@ EOF
}

setupLogrotate() {
if [[ ! -d "$defaultLogRotatePath" ]]; then
sudo mkdir -p "$defaultLogRotatePath"
else
echo "✅ The $defaultLogRotatePath exists!"
if ! hasCommand "$defaultLogRotateBinFilename"; then
printf "🤖 Install logrotate for log management\n"
sudo DEBIAN_FRONTEND=noninteractive apt-get install "$defaultLogRotateBinFilename" -yq
fi

if [[ ! -f "$defaultLogRotateLightningConf" ]]; then
sudo touch "$defaultLogRotateLightningConf"
if [[ -f "$defaultLogRotateConfigFile" ]]; then
if [[ ! -d "$defaultLogRotatePath" ]]; then
sudo mkdir -p "$defaultLogRotatePath"
else
echo "✅ The $defaultLogRotatePath exists!"
fi

if [[ ! -f "$defaultLogRotateLightningConf" ]]; then
sudo touch "$defaultLogRotateLightningConf"

# warning: the identation for `/var/log/lightning/*.log` is intentional, do not change
cat > "$defaultLogRotateLightningConf" <<EOF
# warning: the identation for `/var/log/lightning/*.log` is intentional, do not change
cat > "$defaultLogRotateLightningConf" <<EOF
$defaultLogRotateLightningLogsPath {
rotate 5
daily
Expand All @@ -233,11 +240,12 @@ $defaultLogRotateLightningLogsPath {
compress
}
EOF
else
if ! grep -q "$defaultLogRotateLightningLogsPath" "$defaultLogRotateLightningConf"; then
echo "⚠️ WARNING: The $defaultLogRotateLightningConf exists but doesn't seem valid. You should check it manually!"
else
echo "✅ The $defaultLogRotateLightningConf exists!"
if ! grep -q "$defaultLogRotateLightningLogsPath" "$defaultLogRotateLightningConf"; then
echo "⚠️ WARNING: The $defaultLogRotateLightningConf exists but doesn't seem valid. You should check it manually!"
else
echo "✅ The $defaultLogRotateLightningConf exists!"
fi
fi
fi
}
Expand Down

0 comments on commit 934378a

Please sign in to comment.