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.

292 lines
11 KiB

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