cleanfs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/sh
  2. # Begin /etc/init.d/cleanfs
  3. ### BEGIN INIT INFO
  4. # Provides: cleanfs
  5. # Required-Start: $local_fs
  6. # Should-Start:
  7. # Required-Stop:
  8. # Should-Stop:
  9. # Default-Start: S
  10. # Default-Stop:
  11. # Short-Description: Cleans temporary directories early in the boot process.
  12. # Description: Cleans temporary directories /var/run, /var/lock, and
  13. # /tmp. cleanfs also creates /var/run/utmp and any files
  14. # defined in /etc/sysconfig/createfiles.
  15. # X-LFS-Default-Start: S50
  16. # X-LFS-Default-Stop:
  17. # X-LFS-Provided-By: LFS
  18. ### END INIT INFO
  19. . /lib/lsb/init-functions
  20. # Function to create files/directory on boot.
  21. create_files()
  22. {
  23. # Read in the configuration file.
  24. exec 9>&0 < /etc/sysconfig/createfiles
  25. while read name type perm usr grp dtype maj min junk
  26. do
  27. # Ignore comments and blank lines.
  28. case "${name}" in
  29. ""|\#*) continue ;;
  30. esac
  31. # Ignore existing files.
  32. if [ ! -e "${name}" ]
  33. then
  34. # Create stuff based on its type.
  35. case "${type}" in
  36. dir)
  37. mkdir "${name}"
  38. ;;
  39. file)
  40. :> "${name}"
  41. ;;
  42. dev)
  43. case "${dtype}" in
  44. char)
  45. mknod "${name}" c ${maj} ${min}
  46. ;;
  47. block)
  48. mknod "${name}" b ${maj} ${min}
  49. ;;
  50. pipe)
  51. mknod "${name}" p
  52. ;;
  53. *)
  54. echo -n "\n${WARNING}Unknown device type: ${dtype}"
  55. echo "${NORMAL}"
  56. ;;
  57. esac
  58. ;;
  59. *)
  60. echo "\n${WARNING}Unknown type: ${type}${NORMAL}"
  61. continue
  62. ;;
  63. esac
  64. # Set up the permissions, too.
  65. chown ${usr}:${grp} "${name}"
  66. chmod ${perm} "${name}"
  67. fi
  68. done
  69. exec 0>&9 9>&-
  70. }
  71. case "${1}" in
  72. start)
  73. message="Cleaning file systems: "
  74. message="${message}${INFO} /tmp"
  75. find /tmp -xdev -mindepth 1 ! -name lost+found \
  76. -delete || failed=1
  77. message="${message} /var/lock"
  78. find /var/lock -type f -exec rm -f {} \; || failed=1
  79. message="${message} /var/run${NORMAL}"
  80. find /var/run ! -type d ! -name utmp -exec rm -f {} \; || failed=1
  81. > /var/run/utmp
  82. if grep -q '^utmp:' /etc/group ; then
  83. chmod 664 /var/run/utmp
  84. chgrp utmp /var/run/utmp
  85. fi
  86. (exit ${failed})
  87. evaluate_retval standard
  88. if egrep -qv '^(#|$)' /etc/sysconfig/createfiles 2>/dev/null
  89. then
  90. message="Creating files and directories..."
  91. create_files
  92. evaluate_retval standard
  93. fi
  94. ;;
  95. *)
  96. echo "Usage: ${0} {start}"
  97. exit 1
  98. ;;
  99. esac
  100. # End /etc/init.d/cleanfs