You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.3 KiB

  1. #!/bin/sh
  2. source /etc/log2ram.conf
  3. HDD_LOG=/var/log.hdd/
  4. RAM_LOG=/var/log/
  5. LOG2RAM_LOG="${HDD_LOG}log2ram.log"
  6. LOG_OUTPUT="tee -a $LOG2RAM_LOG"
  7. isSafe () {
  8. [ -d $HDD_LOG ] || echo "ERROR: $HDD_LOG doesn't exist! Can't sync."
  9. [ -d $HDD_LOG ] || exit 1
  10. }
  11. syncToDisk () {
  12. isSafe
  13. if [ "$USE_RSYNC" = true ]; then
  14. rsync -aXWv --delete --exclude log2ram.log --links $RAM_LOG $HDD_LOG 2>&1 | $LOG_OUTPUT
  15. else
  16. cp -rfup $RAM_LOG -T $HDD_LOG 2>&1 | $LOG_OUTPUT
  17. fi
  18. }
  19. syncFromDisk () {
  20. isSafe
  21. if [ ! -z `du -sh -t $SIZE $HDD_LOG | cut -f1` ]; then
  22. echo "ERROR: RAM disk too small. Can't sync."
  23. exit 1
  24. fi
  25. if [ "$USE_RSYNC" = true ]; then
  26. rsync -aXWv --delete --exclude log2ram.log --links $HDD_LOG $RAM_LOG 2>&1 | $LOG_OUTPUT
  27. else
  28. cp -rfup $HDD_LOG -T $RAM_LOG 2>&1 | $LOG_OUTPUT
  29. fi
  30. }
  31. case "$1" in
  32. start)
  33. [ -d $HDD_LOG ] || mkdir $HDD_LOG
  34. rm $LOG2RAM_LOG
  35. mount --bind $RAM_LOG $HDD_LOG
  36. mount --make-private $HDD_LOG
  37. mount -t tmpfs -o nosuid,noexec,nodev,mode=0755,size=$SIZE log2ram $RAM_LOG
  38. syncFromDisk
  39. ;;
  40. stop)
  41. syncToDisk
  42. umount -l $RAM_LOG
  43. umount -l $HDD_LOG
  44. ;;
  45. write)
  46. syncToDisk
  47. ;;
  48. *)
  49. echo "Usage: log2ram {start|stop|write}" >&2
  50. exit 1
  51. ;;
  52. esac