OpenSDE Packages Database (without history before r20070)
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.

198 lines
6.3 KiB

  1. #!/bin/sh
  2. #
  3. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  4. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  5. #
  6. # Filename: package/.../sysvinit/system.init
  7. # Copyright (C) 2006 - 2008 The OpenSDE Project
  8. # Copyright (C) 2004 - 2006 The T2 SDE Project
  9. # Copyright (C) 1998 - 2003 Clifford Wolf
  10. #
  11. # More information can be found in the files COPYING and README.
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; version 2 of the License. A copy of the
  16. # GNU General Public License can be found in the file COPYING.
  17. # --- SDE-COPYRIGHT-NOTE-END ---
  18. #
  19. # Desc: System bootup and shutdown
  20. # Runlevel: 01 rcX rc1 rc2 rc3 rc4 rc5
  21. #
  22. export PATH="/sbin:$PATH"
  23. main_begin
  24. block_begin(start, `Mounting /dev/shm and /dev/pts.')
  25. mkdir -p /dev/shm
  26. check(`mount -n /dev/shm')
  27. mkdir -p /dev/pts
  28. mount -n /dev/pts 2> /dev/null
  29. dnl
  30. if [ -f /etc/conf/hardware ] ; then
  31. . /etc/conf/hardware
  32. fi
  33. dnl
  34. [ -x /bin/dmesg ] && /bin/dmesg -n 3
  35. dnl
  36. block_split(`Starting udevd ...')
  37. echo "" > /sys/kernel/uevent_helper
  38. check(`udevd --daemon')
  39. block_split(`Triggering coldplug ...')
  40. check(`udevtrigger')
  41. check(`udevsettle')
  42. dnl
  43. if [ -s /etc/lvmtab -o -s /etc/lvm/.cache ]; then
  44. block_split(`Activating Volume Groups...')
  45. modprobe dm-mod 2> /dev/null
  46. check(`/sbin/vgchange -ay --ignorelockingfailure 2> /dev/null')
  47. fi
  48. dnl
  49. block_split(`Checking file systems.')
  50. fsck -A -C -a ; fsckrc=$?
  51. if [ $(( $fsckrc & ~3 )) != 0 ] ; then
  52. echo " **"
  53. echo " ** Filesystem check failed (returncode=$fsckrc)."
  54. echo " ** Please repair the broken disk(s) manually."
  55. echo " **"
  56. sulogin -t 600 /dev/console
  57. umount -arv ; /sbin/reboot -d -f
  58. while true ; do sleep 1 ; done
  59. elif [ $(( $fsckrc & 2 )) != 0 ] ; then
  60. for x in 10 9 8 7 6 5 4 3 2 ; do
  61. echo -en "\rSystem reboot in $x seconds ... "
  62. sleep 1
  63. done ; echo -e "\rSystem reboot now! "
  64. umount -arv ; /sbin/reboot -d -f
  65. while true ; do sleep 1 ; done
  66. fi
  67. dnl
  68. block_split(`Mounting local file systems.')
  69. check(`mount -n -o remount,rw /')
  70. rm -f /etc/mtab~* # lingering lock files
  71. cat /proc/mounts > /etc/mtab
  72. check(`mount -a -t nocoda,nfs,devfs,proc,sysfs')
  73. dnl
  74. block_split(`Activating swap devices.')
  75. check(`swapon -a')
  76. dnl
  77. block_split(`Refresh utmp, delete lock and tmp files and other stuff.')
  78. find /var/lock /var/run /tmp -mindepth 1 -print0 2> /dev/null | xargs --null rm -rf
  79. rm -f /etc/nologin /nologin /fastboot ; touch /var/run/utmp
  80. chmod 664 /var/run/utmp ; chown root:tty /var/run/utmp
  81. mkdir /tmp/.ICE-unix && chmod 1777 /tmp/.ICE-unix
  82. dnl
  83. block_split(`Setting hostname to $(cat /etc/HOSTNAME).')
  84. check(`hostname "$(cat /etc/HOSTNAME)"')
  85. dnl
  86. block_split(`Configuring the kernel with /etc/conf/kernel.')
  87. check(`sh /etc/conf/kernel')
  88. dnl
  89. [ -f /etc/conf/clock ] && . /etc/conf/clock
  90. if [ "$clock_tz" = localtime ] ; then
  91. block_split(`Setting kernel clock to local time.')
  92. check(`hwclock --hctosys --localtime')
  93. fi
  94. if [ "$clock_rtc" ] ; then
  95. block_split(`Setting enhanced real time clock precision to $clock_rtc.')
  96. if [ -w /proc/sys/dev/rtc/max-user-freq ] ; then
  97. check(`echo $clock_rtc > /proc/sys/dev/rtc/max-user-freq')
  98. else
  99. echo "No /proc/sys/dev/rtc/max-user-freq found."
  100. fi
  101. fi
  102. dnl
  103. block_split(`Writing /var/log/boot.msg.')
  104. check(`dmesg > /var/log/boot.msg')
  105. dnl
  106. block_split(`Setting console screen font.')
  107. if [ -L /etc/default.vcfont ] ; then
  108. fontfile=$(ls -l /etc/default.vcfont | sed 's,.* -> ,,')
  109. check(`setfont $fontfile')
  110. elif [ -f /etc/default.vcfont ] ; then
  111. check(`setfont /etc/default.vcfont')
  112. else
  113. echo "No /etc/default.vcfont found."
  114. fi
  115. dnl
  116. block_split(`Setting console terminal type and blank interval.')
  117. con_term=linux; con_blank=0
  118. [ -f /etc/conf/console ] && . /etc/conf/console
  119. check(`D_prefix/bin/setterm -term $con_term -blank $con_blank > /dev/console')
  120. dnl
  121. block_split(`Setting up loopback networking.')
  122. check(`ip link set lo up')
  123. [[ "$(ip addr show lo)" = *127.0.0.1/8* ]] ||
  124. check(`ip addr add 127.0.0.1/8 dev lo')
  125. check(`ip route add 127/8 dev lo')
  126. dnl
  127. block_split(`Setting overflow UID and GID kernel parameters.')
  128. check(`sysctl -w kernel.overflowuid=$(id -u nobody) > /dev/null')
  129. check(`sysctl -w kernel.overflowgid=$(id -g nobody) > /dev/null')
  130. dnl
  131. block_split(`Reading /etc/sysctl.conf file.')
  132. check(`sysctl -p')
  133. dnl
  134. block_split(`Initializing kernel random number generator.')
  135. if [ -e /var/state/random-seed ] ; then
  136. check(`cat /var/state/random-seed >/dev/urandom')
  137. fi
  138. block_end
  139. block_begin(stop, `Saving /var/log/init.msg and /var/log/boot.msg.')
  140. check(`touch /var/log/init.msg /var/log/boot.msg')
  141. check(`mv /var/log/init.msg /var/log/init.old')
  142. check(`mv /var/log/boot.msg /var/log/boot.old')
  143. block_split(`Writing a wtmp record.')
  144. if [ "$RUNLEVEL" = 0 ] ; then check(`halt -w')
  145. else check(`reboot -w') ; fi
  146. block_split(`Saving kernel random seed.')
  147. dd if=/dev/urandom of=/var/state/random-seed count=1 2> /dev/null
  148. dnl
  149. block_split(`Sending all processes a SIGTERM (15).')
  150. check(`killall5 -15') ; sleep 5
  151. block_split(`Sending all processes a 2nd SIGTERM (15).')
  152. check(`killall5 -15') ; sleep 5
  153. block_split(`Sending all processes a SIGKILL (9).')
  154. check(`killall5 -9') ; sleep 5
  155. dnl
  156. block_split(`Turning off swap devices.')
  157. check(`swapoff -a')
  158. dnl
  159. block_split(`Remounting sync/ro and umount filesystems.')
  160. sync
  161. cut -d' ' -f-3 /etc/mtab /proc/mounts | sort -k2 -u -r |
  162. while read dev dir fs ; do
  163. case "$dir" in
  164. /|/dev|/proc|/sys|/tmp) continue ;;
  165. *) echo "Umounting $dev on $dir ($fs)."
  166. mount -o remount,sync $dir
  167. mount -o remount,ro $dir
  168. umount $dir ;;
  169. esac
  170. done
  171. dnl
  172. block_split(`Unmounting remaining file systems.')
  173. grep -v -e '^none /[a-z]\+' -e ' / ' /proc/mounts > /etc/mtab
  174. mount -vn -o remount,sync /
  175. sync
  176. umount -vran -t nodevfs,proc,sysfs
  177. mount -vn -o remount,ro /
  178. sync ; sleep 1
  179. dnl
  180. block_split()
  181. if [ "$INIT_DOES_REBOOTHALT" != "1" ]; then
  182. command=
  183. [ "$RUNLEVEL" = 0 ] && command=halt
  184. [ "$RUNLEVEL" = 6 ] && command=reboot
  185. if [ -n "$command" ] ; then
  186. echo "Going to $command the system ..."
  187. $command -d -f -i -p
  188. [ "$INIT_WAITS" != "1" ] && \
  189. while true ; do sleep 1 ; done
  190. fi
  191. fi
  192. block_end
  193. main_end