feat: setup logrotate for the $XDG_STATE_HOME/logs

- Add logrotate config for the new $XDG_STATE_HOME/logs directory.
- Run logrotate before starting DWM (logs are rotated if required by the
  configuration).
This commit is contained in:
Dan Anglin 2022-05-22 10:47:31 +01:00
parent 38f0cd97a9
commit 0feb20c906
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
4 changed files with 36 additions and 4 deletions

View file

@ -36,3 +36,7 @@ amfora_configs: check_xdg_settings
.PHONY: dunst_configs .PHONY: dunst_configs
dunst_configs: check_xdg_settings dunst_configs: check_xdg_settings
@./helpers/dunst/generate-dunst-config @./helpers/dunst/generate-dunst-config
.PHONY: logrotate_configs
logrotate_configs: check_xdg_settings
@./helpers/logrotate/generate-logrotate-config

View file

@ -2,12 +2,19 @@
[[ -f "${HOME}/.bashrc" ]] && source "${HOME}/.bashrc" [[ -f "${HOME}/.bashrc" ]] && source "${HOME}/.bashrc"
if [ -x "$( command -v polybar )" ]; then # Start dunst
"${XDG_CONFIG_HOME}/polybar/launch.sh" &
fi
if [ -x "$( command -v dunst )" ]; then if [ -x "$( command -v dunst )" ]; then
dunst & dunst &
fi fi
# Load the wallpaper
xwallpaper --stretch ~/.local/config/wallpaper/wallpaper.png &
# Rotate the home logs with logrotate
logrotate \
--state=${XDG_STATE_HOME}/logrotate/status \
--log=${LOG_HOME}/logrotate.log \
${XDG_CONFIG_HOME}/logrotate/logrotate.conf \
&
exec dwm exec dwm

View file

@ -0,0 +1,7 @@
${LOG_HOME}/*.log ${LOG_HOME}/nvim/*.log {
rotate 3
size 10M
nocompress
notifempty
copytruncate
}

View file

@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail
GIT_ROOT_DIR="$( cd "$( dirname $0 )/../.." && pwd )"
LF_DOTFILES_SOURCE_DIR="${GIT_ROOT_DIR}/config/logrotate"
LF_DOTFILES_DESTINATION_DIR="${XDG_CONFIG_HOME}/logrotate"
if ! [ -d ${LF_DOTFILES_DESTINATION_DIR} ]; then
echo "INFO: Creating directory ${LF_DOTFILES_DESTINATION_DIR}"
mkdir ${LF_DOTFILES_DESTINATION_DIR}
fi
rsync -avh ${LF_DOTFILES_SOURCE_DIR}/logrotate.conf ${LF_DOTFILES_DESTINATION_DIR}/logrotate.conf && chmod a-rwx,u+rw $_