Skip to content

Commit

Permalink
* FIX force a syslog logrotate as part of the folder2ram mount logic
Browse files Browse the repository at this point in the history
  * the above ensures syslog logs are not still written to disk until next logrotate
  * FIX force a journald logrotate as part of the folder2ram mount logic
  * the above ensure no systemd logs are corrupted and lost when switching folders
  * ADD checking for necessary tools are installed and quit if missing
  • Loading branch information
bobafetthotmail committed Aug 4, 2024
1 parent 9089ebf commit d886c0f
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 8 deletions.
12 changes: 11 additions & 1 deletion debian_package/debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
folder2ram (0.4.0) stable; urgency=low

* FIX force a syslog logrotate as part of the folder2ram mount logic
* the above ensures syslog logs are not still written to disk until next logrotate
* FIX force a journald logrotate as part of the folder2ram mount logic
* the above ensure no systemd logs are corrupted and lost when switching folders
* ADD checking for necessary tools are installed and quit if missing

-- Alberto Bursi <[email protected]> Tue, 05 Aug 2024 10:00:00 +0200

folder2ram (0.3.9) stable; urgency=low

* ADD timestamps to sync command for logging/debugging
Expand All @@ -21,7 +31,7 @@ folder2ram (0.3.6) stable; urgency=low

folder2ram (0.3.5) stable; urgency=low

* fixed umount issue in OpenMediaVault
* fixed umount issue in OpenMediaVault
* added configurable timeout feature
* some better descriptions for -enablesystemd option

Expand Down
77 changes: 70 additions & 7 deletions debian_package/sbin/folder2ram
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,10 @@
# www.tremende.com/ramlog/index.htm

#This script is HEAVILY commented, for the sake of easy understanding and mainteneance
#Don't think I'm patronizing, it's first and foremost because I'm sure I will forget
#some of its arcane spells and I don't feel like wasting hours trying to understand what
#I wrote an unspecified amount of time ago. -Alberto Bursi

#If you edit it, please comment HEAVILY what you are doing, you will thank me later.
#If you edit it, please comment what you are doing

VERSION="0.3.9"
VERSION="0.4.0"

############### USER INTERFACE FUNCTIONS ########################

Expand Down Expand Up @@ -619,6 +616,35 @@ generate_folder_with_same_permission() {

} #### END generate_folder_with_same_permission

rsyslog_logrotate(){
#The following hack (forcing a logrotate) is done only for systemd's journald and rsyslog
#because they are system services and it's too complex to move the service priority around journald

#moving system logs from syslog while the files are open will mean logging will go on to the same log
#files until they are rotated.
#so we have to force the logrotate of this after the move is done
logrotate_test=$( logrotate --version > /dev/null 2>&1 ; echo $? )
if [ "$journalctl_test" -eq 0 ]; then
logrotate --force /etc/logrotate.conf
fi
}

journald_logrotate(){
#The following hack (forcing a logrotate) is done only for systemd's journald and rsyslog
#because they are system services and it's too complex to move the service priority around journald

#moving journald's log folders can break the binary log files in /var/log/journal
#so before we run the mount or unmount logic we force journald to logrotate
#the old logs to a static file that can be moved safely

journalctl_test=$( journalctl --version > /dev/null 2>&1 ; echo $? )

if [ "$journalctl_test" -eq 0 ]; then
journalctl --rotate
fi
}


########################## FILE AND MOUNT FUNCTIONS ################################

mount_umount_all() {
Expand Down Expand Up @@ -699,6 +725,9 @@ mount_umount_all() {

0)

#logrotate journald logs to preserve the current logged events
journald_logrotate

#switching mount operation depending on type of mount point
case $TYPE in

Expand Down Expand Up @@ -746,6 +775,9 @@ mount_umount_all() {

esac

#logrotate syslog logs to force the use of the new folder
rsyslog_logrotate

;;

1) # already mounted
Expand All @@ -763,6 +795,7 @@ mount_umount_all() {
#################

stop)

output_flag=0
# output_flag values:
# 0 if all went well
Expand All @@ -773,6 +806,10 @@ mount_umount_all() {
case $output_flag in

0)

#logrotate journald logs to preserve the current logged events
journald_logrotate

case $TYPE in

tmpfs)
Expand All @@ -790,11 +827,15 @@ mount_umount_all() {
;;

esac

#logrotate syslog logs to force the use of the new folder
rsyslog_logrotate

;;

1) # already unmounted
echo "$DIR already unmounted"
;;
;;
esac
;;
#################
Expand Down Expand Up @@ -886,6 +927,9 @@ sync_to_disk() {
# calling another function (above) to fill the options at this line number
options=$(read_options "$line_number")

#logrotate journald logs to preserve the current logged events
journald_logrotate

####:::::#### BEGIN MAIN sync_to_disk UNTIL LOOP ####:::::####

until [ "$mount_point" = "no_more_mount_points" ]; do
Expand Down Expand Up @@ -1148,6 +1192,8 @@ reset_config() {

#####################--START MAIN PROGRAM--################################

action="$1"

#doing a root check, because folder2ram must be run as root for obvious reasons
if [ "$(id -u)" -eq 0 ]; then
echo
Expand All @@ -1156,7 +1202,24 @@ else
exit
fi

action="$1"
#checking that crucial tools are installed

for tool in cp rsync mount umount rm chown chmod mkdir sed tr; do

tool_test=$( $tool --version > /dev/null 2>&1 ; echo $? )
if [ "$tool_test" -ne 0 ]; then
echo ERROR: $tool tool not found, please install it. Quitting
exit 1
fi

done

#awk is different so it gets its own checker
tool_test=$( awk -W version > /dev/null 2>&1 ; echo $? )
if [ "$tool_test" -ne 0 ]; then
echo ERROR: awk tool not found, please install it. Quitting
exit 1
fi

case "$action" in

Expand Down

0 comments on commit d886c0f

Please sign in to comment.