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.

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