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.

141 lines
4.3 KiB

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