-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogrotate.sh
More file actions
46 lines (39 loc) · 1018 Bytes
/
logrotate.sh
File metadata and controls
46 lines (39 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh
echo "Running logrotate"
FORCE_ROTATE=0
for arg in "$@"; do
case "$arg" in
-f|--force)
FORCE_ROTATE=1
;;
*)
echo "Unknown argument: $arg"
echo "Usage: $0 [--force|-f]"
exit 1
;;
esac
done
TMP_LOGROTATE_CONF="/tmp/logrotate.conf"
trap 'rm -f "$TMP_LOGROTATE_CONF"' EXIT INT TERM
# Create a temporary logrotate configuration file that rotates hourly and keeps ( 3 days ) rotated logs
cat <<EOF > "$TMP_LOGROTATE_CONF"
"$LOG_PATH" {
hourly
rotate 72
compress
delaycompress
postrotate
/app/export.sh
endscript
}
EOF
cat "$TMP_LOGROTATE_CONF"
# Run logrotate with the temporary configuration file
if [ "$FORCE_ROTATE" = "1" ]; then
echo "Force mode enabled: rotating regardless of schedule."
/usr/sbin/logrotate -v -f "$TMP_LOGROTATE_CONF"
else
/usr/sbin/logrotate -v "$TMP_LOGROTATE_CONF"
fi
# Clean up the temporary configuration file
rm -f "$TMP_LOGROTATE_CONF"