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.

291 lines
11 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/.../utils-vserver/stone_mod_vserver.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] 40 vserver Linux VServer Manager
  16. CONFDIR=/etc/vservers
  17. oneliner() {
  18. [ -r $1 ] && head -n 1 $1 || echo "N/A"
  19. }
  20. gui_edit_oneliner() {
  21. local value=
  22. [ -f $2 ] && value="$( cat $2 )"
  23. if gui_input "Enter value for '$1' ($2):" "$value" value; then
  24. if [ "$value" ]; then
  25. echo "$value" > $2
  26. else
  27. rm -f $2
  28. fi
  29. fi
  30. }
  31. gui_edit_deleteable() {
  32. gui_edit $1 $2
  33. [ ! -s $2 ] && rm -f $2
  34. }
  35. flag_if_empty() {
  36. [ -s $1 ] || echo '[N/A]'
  37. }
  38. vserver_conf_manage() {
  39. local server="$1" errno=0
  40. local vdir=$CONFDIR/$server
  41. while [ $errno -eq 0 ]; do
  42. local options=
  43. options="$options 'Name ......: $( oneliner $vdir/name )' ''"
  44. options="$options 'Context ID.: $( oneliner $vdir/run )' ''"
  45. options="$options 'Directory .: $( readlink -f $vdir/vdir )' ''"
  46. options="$options 'Context ...: $( oneliner $vdir/context )' \
  47. 'gui_edit_oneliner context $vdir/context'"
  48. options="$options 'Namespace .: $( oneliner $vdir/namespace )' \
  49. 'gui_edit_oneliner namespace $vdir/namespace'"
  50. options="$options '' ''"
  51. case "`uname -r`" in
  52. 2.4*) options="$options 'System Capabilities $( flag_if_empty $vdir/capabilities )' \
  53. 'gui_edit_deleteable capabilities $vdir/capabilities'"
  54. ;;
  55. *) options="$options 'System Capabilities $( flag_if_empty $vdir/bcapabilities )' \
  56. 'gui_edit_deleteable bcapabilities $vdir/bcapabilities'"
  57. ;;
  58. esac
  59. options="$options 'Context Capabilities $( flag_if_empty $vdir/ccapabilities )' \
  60. 'gui_edit_deleteable ccapabilities $vdir/ccapabilities'"
  61. options="$options 'Flags $( flag_if_empty $vdir/flags )' \
  62. 'gui_edit_deleteable flags $vdir/flags'"
  63. options="$options 'Personalities $( flag_if_empty $vdir/personality )' \
  64. 'gui_edit_deleteable personality $vdir/personality'"
  65. options="$options 'Scheduler Parameters $( flag_if_empty $vdir/schedule )' \
  66. 'gui_edit_deleteable schedule $vdir/schedule'"
  67. options="$options '' ''"
  68. options="$options 'Nice Level ...: $( oneliner $vdir/nice )' \
  69. 'gui_edit_oneliner nice $vdir/nice'"
  70. options="$options 'Default Shell : $( oneliner $vdir/shell )' \
  71. 'gui_edit_oneliner shell $vdir/shell'"
  72. options="$options '' ''"
  73. options="$options '==> uname (uts)' 'vserver_conf_uts_manage $server'"
  74. case "`uname -r`" in
  75. 2.4*) options="$options '==> Resource Limits' 'vserver_conf_ul_manage $server'" ;;
  76. *) options="$options '==> Resource Limits' 'vserver_conf_rl_manage $server'" ;;
  77. esac
  78. options="$options '==> Network Interfaces' 'vserver_conf_if_manage $server'"
  79. options="$options '==> Applications' 'vserver_conf_apps_manage $server'"
  80. options="$options '==> Scripts' 'vserver_conf_sc_manage $server'"
  81. options="$options '' ''"
  82. options="$options 'mtab $( flag_if_empty $appsdir/init/mtab )' \
  83. 'gui_edit_deleteable init_mtab $vdir/apps/init/mtab'"
  84. options="$options 'fstab $( flag_if_empty $vdir/fstab )' \
  85. 'gui_edit fstab $vdir/fstab'"
  86. options="$options 'fstab.remote $( flag_if_empty $vdir/fstab.remote )' \
  87. 'gui_edit_deleteable fstab_remote $vdir/fstab.remote'"
  88. eval "gui_menu vserver_conf 'VServer \`$server\` Configuration' $options"
  89. errno=$?
  90. done
  91. }
  92. vserver_conf_uts_manage() {
  93. local server="$1" errno=0
  94. local utsdir=$CONFDIR/$server/uts
  95. while [ $errno -eq 0 ]; do
  96. local options=
  97. options="$options 'Context Name .: $( oneliner $utsdir/context )' 'gui_edit_oneliner context $utsdir/context'"
  98. options="$options 'Node Name ....: $( oneliner $utsdir/nodename )' 'gui_edit_oneliner machine $utsdir/nodename'"
  99. options="$options 'Domain Name ..: $( oneliner $utsdir/domainname )' 'gui_edit_oneliner domainname $utsdir/domainname'"
  100. options="$options 'Machine Type .: $( oneliner $utsdir/machine )' 'gui_edit_oneliner machine $utsdir/machine'"
  101. options="$options 'Sysname ......: $( oneliner $utsdir/sysname )' 'gui_edit_oneliner machine $utsdir/sysname'"
  102. options="$options 'OS Release ...: $( oneliner $utsdir/release )' 'gui_edit_oneliner machine $utsdir/release'"
  103. options="$options 'OS Version ...: $( oneliner $utsdir/version )' 'gui_edit_oneliner machine $utsdir/version'"
  104. eval "gui_menu vserver_conf_uts 'VServer \`$server\` uname Configuration' $options"
  105. errno=$?
  106. done
  107. }
  108. vserver_conf_apps_manage() {
  109. local server="$1" errno=0
  110. local appsdir=$CONFDIR/$server/apps
  111. while [ $errno -eq 0 ]; do
  112. local options=
  113. options="$options '$server/apps/init/' ''"
  114. options="$options ' - style ..........: $( oneliner $appsdir/init/style )' \
  115. 'gui_edit_oneliner init_style $appsdir/init/style'"
  116. options="$options ' - mark ...........: $( oneliner $appsdir/init/mark )' \
  117. 'gui_edit_oneliner init_mark $appsdir/init/mark'"
  118. options="$options ' - tty ............: $( readlink -f $appsdir/init/tty 2> /dev/null )' ''"
  119. options="$options ' - runlevel .......: $( oneliner $appsdir/init/runlevel )' \
  120. 'gui_edit_oneliner init_runlevel $appsdir/init/runlevel'"
  121. options="$options ' - runlevel.start .: $( oneliner $appsdir/init/runlevel.start )' \
  122. 'gui_edit_oneliner init_runlevel_start $appsdir/init/runlevel.start'"
  123. options="$options ' - runlevel.stop ..: $( oneliner $appsdir/init/runlevel.stop )' \
  124. 'gui_edit_oneliner init_runlevel_stop $appsdir/init/runlevel.stop'"
  125. options="$options '' ''"
  126. options="$options ' * depends $( flag_if_empty $appsdir/init/depends )' \
  127. 'gui_edit_deleteable init_depends $appsdir/init/depends'"
  128. options="$options ' * killseq $( flag_if_empty $appsdir/init/killseq )' \
  129. 'gui_edit_deleteable init_killseq $appsdir/init/killseq'"
  130. options="$options ' * cmd.prepare $( flag_if_empty $appsdir/init/cmd.prepare )' \
  131. 'gui_edit_deleteable init_prepare $appsdir/init/cmd.prepare'"
  132. options="$options ' * cmd.start $( flag_if_empty $appsdir/init/cmd.start )' \
  133. 'gui_edit_deleteable init_start $appsdir/init/cmd.start'"
  134. options="$options ' * cmd.stop $( flag_if_empty $appsdir/init/cmd.stop )' \
  135. 'gui_edit_deleteable init_stop $appsdir/init/cmd.stop'"
  136. if [ -e $appsdir/init/sync ]; then
  137. options="$options ' * cmd.start-sync $( flag_if_empty $appsdir/init/cmd.start-sync )' \
  138. 'gui_edit_deleteable init_start_sync $appsdir/init/cmd.start-sync'"
  139. options="$options ' * cmd.stop-sync $( flag_if_empty $appsdir/init/cmd.stop-sync )' \
  140. 'gui_edit_deleteable init_stop_sync $appsdir/init/cmd.stop-sync'"
  141. fi
  142. eval "gui_menu vserver_conf_uts 'VServer \`$server\` Applications Configuration' $options"
  143. errno=$?
  144. done
  145. }
  146. vserver_conf_rl_manage() {
  147. local server="$1" errno=0
  148. local rldir=$CONFDIR/$server/rlimits
  149. while [ $errno -eq 0 ]; do
  150. local options=
  151. options="$options 'resource $( flag_if_empty $rldir/resource )' \
  152. 'gui_edit_deleteable resource $rldir/resource'"
  153. options="$options 'resource.min $( flag_if_empty $rldir/resource.min )' \
  154. 'gui_edit_deleteable resource $rldir/resource.min'"
  155. options="$options 'resource.hard $( flag_if_empty $rldir/resource.hard )' \
  156. 'gui_edit_deleteable resource $rldir/resource.hard'"
  157. options="$options 'resource.soft $( flag_if_empty $rldir/resource.soft )' \
  158. 'gui_edit_deleteable resource $rldir/resource.soft'"
  159. eval "gui_menu vserver_conf_rl 'VServer \`$server\` (2.6) Resource Limits Configuration' $options"
  160. errno=$?
  161. done
  162. }
  163. vserver_conf_ul_manage() {
  164. local server="$1" errno=0
  165. local rldir=$CONFDIR/$server/ulimits
  166. while [ $errno -eq 0 ]; do
  167. local options=
  168. options="$options 'resource $( flag_if_empty $rldir/resource )' \
  169. 'gui_edit_deleteable resource $rldir/resource'"
  170. options="$options 'resource.hard $( flag_if_empty $rldir/resource.hard )' \
  171. 'gui_edit_deleteable resource $rldir/resource.hard'"
  172. options="$options 'resource.soft $( flag_if_empty $rldir/resource.soft )' \
  173. 'gui_edit_deleteable resource $rldir/resource.soft'"
  174. eval "gui_menu vserver_conf_ul 'VServer \`$server\` (2.4) Resource Limits Configuration' $options"
  175. errno=$?
  176. done
  177. }
  178. vserver_conf_sc_manage() {
  179. local server="$1" errno=0
  180. local scdir=$CONFDIR/$server/scripts
  181. while [ $errno -eq 0 ]; do
  182. local options=
  183. eval "gui_menu vserver_conf_uts 'VServer \`$server\` uname Configuration' $options"
  184. errno=$?
  185. done
  186. }
  187. vserver_conf_if_manage() {
  188. local server="$1" errno=0
  189. local ifdir=$CONFDIR/$server/interfaces
  190. while [ $errno -eq 0 ]; do
  191. local options= iface=
  192. options="$options 'default broadcast ..: $( oneliner $ifdir/bcast )' 'gui_edit_oneliner bcast $ifdir/bcast'"
  193. options="$options 'default device .....: $( oneliner $ifdir/dev )' 'gui_edit_oneliner device $ifdir/dev'"
  194. options="$options 'default netmask ....: $( oneliner $ifdir/prefix )' 'gui_edit_oneliner prefix $ifdir/prefix'"
  195. options="$options 'default scope ......: $( oneliner $ifdir/scope )' 'gui_edit_oneliner scope $ifdir/scope'"
  196. for iface in $( cd $ifdir; ls -1 ); do
  197. if [ -d $ifdir/$iface/ ]; then
  198. options="$options '' ''"
  199. if [ -e $ifdir/$iface/disabled ]; then
  200. options="$options 'interface/$iface: DISABLED' 'rm -f $ifdir/$iface/disabled'"
  201. else
  202. options="$options 'interface/$iface: ENABLED' 'touch $ifdir/$iface/disabled'"
  203. fi
  204. options="$options ' broadcast ..: $( oneliner $ifdir/$iface/bcast )' \
  205. 'gui_edit_oneliner bcast $ifdir/$iface/bcast'"
  206. options="$options ' device .....: $( oneliner $ifdir/$iface/dev )' \
  207. 'gui_edit_oneliner dev $ifdir/$iface/dev'"
  208. options="$options ' ip .........: $( oneliner $ifdir/$iface/ip )' \
  209. 'gui_edit_oneliner ip $ifdir/$iface/ip'"
  210. options="$options ' netmask ....: $( oneliner $ifdir/$iface/prefix )' \
  211. 'gui_edit_oneliner prefix $ifdir/$iface/prefix'"
  212. options="$options ' scope ......: $( oneliner $ifdir/$iface/scope )' \
  213. 'gui_edit_oneliner scope $ifdir/$iface/scope'"
  214. fi
  215. done
  216. options="$options '' ''"
  217. options="$options 'Add new interface' 'vserver_if_new $server'"
  218. eval "gui_menu vserver_conf_uts 'VServer \`$server\` Network Interfaces Configuration' $options"
  219. errno=$?
  220. done
  221. }
  222. vserver_if_new() {
  223. local server="$1"
  224. local iface=
  225. gui_input "Enter a name for the new interface" '' iface
  226. if [ "$iface" ]; then
  227. mkdir -p "$CONFDIR/$server/interfaces/$iface"
  228. fi
  229. }
  230. vserver_new() {
  231. local server= action= errno=
  232. gui_input "Enter a name for the new vserver" '' server
  233. if [ "$server" ]; then
  234. action="vserver '$server' build -m skeleton --initstyle plain"
  235. eval "$action"; errno=$?
  236. if [ $errno -eq 0 ]; then
  237. vserver_conf_manage "$server"
  238. else
  239. gui_message "\"$action\" failed."
  240. fi
  241. fi
  242. }
  243. main() {
  244. local errno=0
  245. local servers= server=
  246. while [ $errno -eq 0 ]; do
  247. servers=
  248. for server in $( ls -1 $CONFDIR); do
  249. [ -d $CONFDIR/$server ] && servers="$servers 'vserver: $server' 'vserver_conf_manage $server'"
  250. done
  251. [ "$servers" ] && servers="$servers '' ''"
  252. eval "gui_menu vserver 'Linux VServer Manager' $servers 'Create a new vserver' 'vserver_new'"
  253. errno=$?
  254. done
  255. }