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.

124 lines
3.3 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../stone/stone_mod_runlevel.sh
  5. # Copyright (C) 2008 The OpenSDE Project
  6. # Copyright (C) 2004 - 2006 The T2 SDE Project
  7. # Copyright (C) 1998 - 2003 Clifford Wolf
  8. #
  9. # More information can be found in the files COPYING and README.
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; version 2 of the License. A copy of the
  14. # GNU General Public License can be found in the file COPYING.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. #
  17. # [MAIN] 80 runlevel Runlevel Configuration (Services)
  18. # Remove dead symlinks
  19. for x in /etc/rc.d/rc[0-6].d/* ; do
  20. [ -L "$x" -a ! -e "$x" ] && rm -f "$x"
  21. done
  22. chrlv() {
  23. local srv=$1 rl=$2 pri=$3
  24. if [ ! -e /etc/rc.d/rc$rl.d/S??$srv ]
  25. then
  26. ln -sf ../init.d/$srv /etc/rc.d/rc$rl.d/S$pri$srv
  27. kpr=`printf "%02d" $(( 100 - $pri ))`
  28. ln -sf ../init.d/$srv /etc/rc.d/rc$rl.d/K$kpr$srv
  29. else
  30. rm -f /etc/rc.d/rc$rl.d/[SK]??$srv
  31. fi
  32. }
  33. chpri() {
  34. local srv=$1 pri=$2
  35. gui_input "Changing priority for service $1" "$pri" pri
  36. if [ ! -z "${pri#[0-9][0-9]}" ]
  37. then
  38. gui_message "The value you entered is not valid."
  39. return
  40. fi
  41. rm -f /etc/rc.d/rcX.d/X??$srv
  42. echo "The script '$srv' has the priority $pri." \
  43. > /etc/rc.d/rcX.d/X$pri$srv
  44. for x in 0 1 2 3 4 5 6 ; do
  45. if [ -e /etc/rc.d/rc$x.d/S??$srv ] ; then
  46. rm -f /etc/rc.d/rc$x.d/[SK]??$srv
  47. ln -sf ../init.d/$srv /etc/rc.d/rc$x.d/S$pri$srv
  48. kpr=`printf "%02d" $(( 100 - $pri ))`
  49. ln -sf ../init.d/$srv /etc/rc.d/rc$x.d/K$kpr$srv
  50. fi
  51. done
  52. }
  53. edit_srv() {
  54. local srv=$1 id="runlevel_$RANDOM" cmd=
  55. while
  56. cmd="gui_menu $id 'Runlevel Editor - $srv'"
  57. pri=`ls /etc/rc.d/rc?.d/[SX]??$srv 2> /dev/null | \
  58. cut -c18-19 | head -n 1`
  59. [ -z "$pri" ] && pri=99
  60. for rl in 1 2 3 4 5 ; do
  61. if [ -e /etc/rc.d/rc$rl.d/S??$srv ]
  62. then cmd="$cmd '[*] " ; else cmd="$cmd '[ ] " ; fi
  63. cmd="$cmd Run this script in runlevel $rl'"
  64. cmd="$cmd 'chrlv $srv $rl $pri'"
  65. done
  66. cmd="$cmd '$pri This scripts priority (01-99)'"
  67. cmd="$cmd 'chpri $srv $pri' '' ''"
  68. cmd="$cmd 'Edit /etc/rc.d/init.d/$srv script'"
  69. cmd="$cmd \"gui_edit 'SysV Init Script $srv'"
  70. cmd="$cmd /etc/rc.d/init.d/$srv\""
  71. cmd="$cmd \"(Re-)Start the '$srv' system service\""
  72. cmd="$cmd '$STONE runlevel restart $srv'"
  73. eval "$cmd"
  74. do : ; done
  75. }
  76. restart() {
  77. gui_cmd "(Re-)Starting System Service '$1'" \
  78. "/sbin/rc $1 stop ; /sbin/rc $1 start"
  79. }
  80. main() {
  81. while
  82. cmd="gui_menu runlevel 'Runlevel Editor - Select an"
  83. cmd="$cmd item to change the priority or runlevels'"
  84. x=`mktemp`
  85. for srv in $( ls /etc/rc.d/init.d/ )
  86. do
  87. [ -f /etc/rc.d/init.d/$srv ] || continue
  88. pri=`ls /etc/rc.d/rc?.d/[SX]??$srv \
  89. 2> /dev/null | cut -c18-19 | head -n 1`
  90. [ -z "$pri" ] && pri=99
  91. rlv=
  92. for x in 1 2 3 4 5 ; do
  93. if [ -e /etc/rc.d/rc$x.d/S??$srv ]
  94. then rlv="${rlv}$x" ; else rlv="${rlv}-" ; fi
  95. done
  96. desc=`grep '# *Desc:' /etc/rc.d/init.d/$srv | \
  97. cut -f2- -d: | tr -d "'" | cut -c1-45`
  98. desc="$( printf "%-10s %s" "$srv" "$desc" )"
  99. echo "$pri$srv '$pri $rlv $desc' 'edit_srv $srv'"
  100. done | sort > $x
  101. cmd="$cmd $(cut -f2- -d' ' < $x | tr '\n' ' ')"
  102. rm -f $x ; eval "$cmd"
  103. do : ; done
  104. }