Rename vServer
From Linux-VServer
Revision as of 17:09, 16 July 2009 by 90.152.0.28 (Talk)
General Administrative Tasks and System Tweaks
Renaming a vServer
Suppose you want to rename your vserver (the directories not the hostname). This can be accomplished by renaming the config directory and the root for the vserver in question, then modifying 3 symlinks to match.
1. Stop the vserver in question 2. rename the /vservers/<server name> directory 3. rename the /etc/vservers/<server name> directory 4. update link: /etc/vservers/<server name>/run -> /var/run/vservers/<server name> 5. update link: /etc/vservers/<server name>/vdir -> /etc/vservers/.defaults/vdirbase/<server name> 6. update link: /etc/vservers/<server name>/cache -> /etc/vservers/.defaults/cachebase/<server name> 7. update link: /var/run/vservers.rev/<server XID> -> /etc/vservers/<server name> 8. Start the vserver in question. It should start properly.
Sample vServer renaming bash script (wrote for Debian)
#!/bin/sh data_path="/data/vservers" config_path="/etc/vservers" run_path="/var/run/vservers" run_rev_path="/var/run/vservers.rev" vserver_exec="/usr/sbin/vserver" orig_dir=`pwd` function throwError { echo "" echo "-------------------------------" echo "Error: $error"; echo "-------------------------------" cd $orig_dir exit 0 } function checkExist { echo "" cd $data_path ls --color $data_path echo "" echo -n "What is the name of the vServer you wish to rename? : " read orig_name if [[ ! -d "$data_path/$orig_name" ]]; then checkExist fi } function newName { echo "" echo -n "What is the new name you would like? : " read new_name if [[ "$new_name" == "" ]]; then echo "Name supplied was empty" newName fi if [[ -d "$data_path/$new_name" ]]; then echo "Name already in use!" newName fi } function confirm { read u_confirm if [[ "$u_confirm" != "y" ]]; then error="Cancelled by user" throwError fi } echo "" echo "Data path: $data_path" echo "Config path: $config_path" echo "Run path: $run_path" echo "Run rev path: $run_rev_path" echo "vServer executable $vserver_exec" echo "" echo -n "Are these paths correct? y/N : " confirm checkExist newName # Check all the dirs and symlinks exist if [[ ! -d "$config_path/$orig_name" ]] || [[ "$orig_name" == "" ]]; then error="vServer config path doesn't exist" throwError fi # Grab the context for that vServer context=`cat $config_path/$orig_name/context` if [[ ! -d "$run_rev_path/$context" ]]; then error="vServer run rev path ($run_rev_path/$context) doesn't exist" throwError fi if [[ ! -f "$vserver_exec" ]]; then error="vServer exec file doesn't exist" throwError fi # Confirm before stopping vServer echo "" echo -n "Are you ready to start the renaming process? y/N : " confirm $vserver_exec $orig_name stop mv $data_path/$orig_name $data_path/$new_name mv $config_path/$orig_name $config_path/$new_name /bin/rm $config_path/$new_name/run ln -s $run_path/$new_name $config_path/$new_name/run /bin/rm $config_path/$new_name/vdir ln -s $config_path/.defaults/vdirbase/$new_name $config_path/$new_name/vdir /bin/rm $config_path/$new_name/cache ln -s $config_path/.defaults/cachebase/$new_name $config_path/$new_name/cache /bin/rm $run_rev_path/$context ln -s $config_path/$new_name $run_rev_path/$context $vserver_exec $new_name start cd $orig_dir