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.

130 lines
4.2 KiB

  1. #!/bin/sh
  2. # --- T2-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # T2 SDE: package/.../runit/stone_mod_runit.sh
  6. # Copyright (C) 2004 - 2006 The T2 SDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- T2-COPYRIGHT-NOTE-END ---
  15. # [MAIN] 30 runit Service Manager (runit)
  16. SYSCONFDIR=/etc
  17. SERVICEDIR=/service
  18. COMMANDDIR=/command
  19. declare -a runit_installed
  20. declare -a runit_available
  21. runit_audit() {
  22. local entry= available= count=
  23. entry=0
  24. while read service; do
  25. runit_available[$entry*3+0]="${service##*/}" # service name
  26. runit_available[$entry*3+1]="$service" # service's real location
  27. runit_available[$entry*3+2]= # installed
  28. (( entry++ ))
  29. done < <( find $SYSCONFDIR -type f -name run | sort | sed -e '/\/log\/run$/d;' -e 's,/run$,,g' )
  30. entry=0
  31. (( count=${#runit_available[@]}/3 ))
  32. while read service; do
  33. runit_installed[$entry*3+0]="${service##*/}" # service name
  34. runit_installed[$entry*3+1]="$( readlink -f "$service" )" # real location
  35. runit_installed[$entry*3+2]=
  36. available=0
  37. while [ $available -lt $count ]; do
  38. if [ ${runit_available[$available*3+1]} = ${runit_installed[$entry*3+1]} ]; then
  39. runit_available[$available*3+2]=$entry
  40. runit_installed[$entry*3+2]=$available
  41. break
  42. fi
  43. (( available++ ))
  44. done
  45. (( entry++ ))
  46. done < <( find $SERVICEDIR -maxdepth 1 -type l | sort )
  47. }
  48. # u|d|o|p|c|h|a|i|q|1|2|t|k|x|e
  49. runit_svc() {
  50. local service=$1 errno=0 name= dir=
  51. local prefix=${service%/*} location=$(readlink -f $service)
  52. while [ $errno -eq 0 ]; do
  53. local actions=
  54. for dir in $service/ $service/log/; do
  55. if [ -d $dir ]; then
  56. name=${dir#$prefix/}
  57. [ "$actions" ] && actions="$actions '' ''"
  58. actions="$actions 'service: $dir' '' \
  59. ' stats: $( $COMMANDDIR/sv status $dir/ 2> /dev/null | sed -e 's,;.*,,' -e 's,:.*:,,' -e 's,(.*) ,,' )' ''"
  60. actions="$actions 'sv up $name (up)' '$COMMANDDIR/sv up $dir; sleep 1'"
  61. actions="$actions 'sv down $name(down)' '$COMMANDDIR/sv down $dir; sleep 1'"
  62. actions="$actions 'sv hup $name (HUP)' '$COMMANDDIR/sv hup $dir; sleep 1'"
  63. fi
  64. done
  65. eval "gui_menu runit_sc_menu '$service -> $location' $actions"
  66. errno=$?
  67. done
  68. }
  69. runit_install() {
  70. local entry="$1" count=
  71. (( count=${#runit_installed[@]}/3 ))
  72. runit_installed[$count*3+0]="${runit_available[$entry*3+0]}"
  73. runit_installed[$count*3+1]="${runit_available[$entry*3+1]}"
  74. runit_installed[$count*3+2]=$entry
  75. runit_available[$entry*3+2]=$count
  76. ln -snf "${runit_available[$entry*3+1]}" $SERVICEDIR/"${runit_available[$entry*3+0]}"
  77. }
  78. main() {
  79. local errno=0
  80. local entry= count=
  81. runit_audit
  82. while [ $errno -eq 0 ]; do
  83. local available= installed=
  84. local text= action=
  85. local i= stats=
  86. declare -a stats
  87. (( count=${#runit_installed[@]}/3 )); entry=0
  88. while [ $entry -lt $count ]; do
  89. text="${runit_installed[$entry*3+0]}"
  90. action="runit_svc $SERVICEDIR/${runit_installed[$entry*3+0]} ${runit_installed[$entry*3+1]}"
  91. stats[0]=; stats[1]=; i=0
  92. while read stats[i++]; do :; done < <( \
  93. $COMMANDDIR/sv status \
  94. "${runit_installed[$entry*3+1]}" 2> /dev/null | \
  95. sed -e 's,; ,\n,' | sed -e 's,:.*:,,' -e 's,(.*) ,,' )
  96. [ "${stats[0]}" ] && text="$text [${stats[0]}]" || text="$text [ERROR]"
  97. [ "${stats[1]}" ] && text="$text log: [${stats[1]}]"
  98. [ "${runit_installed[$entry*3+2]}" ] || text="$text [FOREIGN]"
  99. installed="$installed '$text' '$action'"
  100. (( entry++ ))
  101. done
  102. (( count=${#runit_available[@]}/3 )); entry=0
  103. while [ $entry -lt $count ]; do
  104. if [ -z "${runit_available[$entry*3+2]}" ]; then
  105. text="${runit_available[$entry*3+0]} (${runit_available[$entry*3+1]})"
  106. if [ -e "$SERVICEDIR/${runit_available[$entry*3+0]}" ]; then
  107. text="$text [BLOCKED]"
  108. action=
  109. else
  110. action="runit_install $entry"
  111. fi
  112. available="$available '$text' '$action'"
  113. fi
  114. (( entry++ ))
  115. done
  116. eval "gui_menu runit 'Simple $SERVICEDIR Manager' $installed '' '' $available"
  117. errno=$?
  118. done
  119. }