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.

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