http://wiki.linux-vserver.org/api.php?action=feedcontributions&user=90.152.0.27&feedformat=atom
Linux-VServer - User contributions [en]
2024-03-28T18:31:57Z
User contributions
MediaWiki 1.20.2
http://wiki.linux-vserver.org/Rename_vServer
Rename vServer
2009-07-20T12:23:19Z
<p>90.152.0.27: /* Sample vServer renaming bash script (wrote for Debian) */</p>
<hr />
<div>== General Administrative Tasks and System Tweaks ==<br />
=== Renaming a vServer ===<br />
<br />
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.<br />
<br />
1. Stop the vserver in question<br />
2. rename the /vservers/<server name> directory<br />
3. rename the /etc/vservers/<server name> directory<br />
4. update link: /etc/vservers/<server name>/run -> /var/run/vservers/<server name><br />
5. update link: /etc/vservers/<server name>/vdir -> /etc/vservers/.defaults/vdirbase/<server name><br />
6. update link: /etc/vservers/<server name>/cache -> /etc/vservers/.defaults/cachebase/<server name><br />
7. update link: /var/run/vservers.rev/<server XID> -> /etc/vservers/<server name><br />
8. Start the vserver in question. It should start properly.<br />
<br />
<br />
A script is provided below to help speed up the renaming process and reduce downtime by automating the sequence. Please make sure you verify the first 5 variables before running the script!<br />
<br />
=== Sample vServer renaming bash script (wrote for Debian) ===<br />
<br />
The script below does not create the dir/symlink for the cache dir - I will update it within the week.<br />
<br />
<pre><br />
#!/bin/sh<br />
<br />
data_path="/data/vservers"<br />
config_path="/etc/vservers"<br />
run_path="/var/run/vservers"<br />
run_rev_path="/var/run/vservers.rev"<br />
vserver_exec="/usr/sbin/vserver"<br />
<br />
### DO NOT CHANGE ANYTHING AFTER THIS LINE ###<br />
<br />
orig_dir=`pwd`<br />
<br />
function throwError {<br />
echo ""<br />
echo "-------------------------------"<br />
echo "Error: $error";<br />
echo "-------------------------------"<br />
cd $orig_dir<br />
exit 0<br />
}<br />
<br />
function checkExist {<br />
echo ""<br />
cd $data_path<br />
ls --color $data_path<br />
echo ""<br />
echo -n "What is the name of the vServer you wish to rename? : "<br />
read orig_name<br />
<br />
if [[ ! -d "$data_path/$orig_name" ]]; then<br />
checkExist<br />
fi<br />
}<br />
<br />
function newName {<br />
echo ""<br />
echo -n "What is the new name you would like? : "<br />
read new_name<br />
<br />
if [[ "$new_name" == "" ]]; then<br />
echo "Name supplied was empty"<br />
newName<br />
fi<br />
<br />
if [[ -d "$data_path/$new_name" ]]; then<br />
echo "Name already in use!"<br />
newName<br />
fi<br />
}<br />
<br />
function confirm {<br />
read u_confirm<br />
if [[ "$u_confirm" != "y" ]]; then<br />
error="Cancelled by user"<br />
throwError<br />
fi<br />
}<br />
<br />
echo ""<br />
echo "Data path: $data_path"<br />
echo "Config path: $config_path"<br />
echo "Run path: $run_path"<br />
echo "Run rev path: $run_rev_path"<br />
echo "vServer executable $vserver_exec"<br />
echo ""<br />
echo -n "Are these paths correct? y/N : "<br />
confirm<br />
<br />
checkExist<br />
newName<br />
<br />
# Check all the dirs and symlinks exist<br />
<br />
if [[ ! -d "$config_path/$orig_name" ]] || [[ "$orig_name" == "" ]]; then<br />
error="vServer config path doesn't exist"<br />
throwError<br />
fi<br />
<br />
# Grab the context for that vServer<br />
context=`cat $config_path/$orig_name/context`<br />
<br />
if [[ ! -d "$run_rev_path/$context" ]]; then<br />
error="vServer run rev path ($run_rev_path/$context) doesn't exist"<br />
throwError<br />
fi<br />
<br />
if [[ ! -f "$vserver_exec" ]]; then<br />
error="vServer exec file doesn't exist"<br />
throwError<br />
fi<br />
<br />
<br />
# Confirm before stopping vServer<br />
<br />
echo ""<br />
echo -n "Are you ready to start the renaming process? y/N : "<br />
confirm<br />
<br />
$vserver_exec $orig_name stop<br />
<br />
mv $data_path/$orig_name $data_path/$new_name<br />
<br />
mv $config_path/$orig_name $config_path/$new_name<br />
<br />
/bin/rm $config_path/$new_name/run<br />
ln -s $run_path/$new_name $config_path/$new_name/run<br />
<br />
/bin/rm $config_path/$new_name/vdir<br />
ln -s $config_path/.defaults/vdirbase/$new_name $config_path/$new_name/vdir<br />
<br />
/bin/rm $config_path/$new_name/cache<br />
ln -s $config_path/.defaults/cachebase/$new_name $config_path/$new_name/cache<br />
<br />
/bin/rm $run_rev_path/$context<br />
ln -s $config_path/$new_name $run_rev_path/$context<br />
<br />
$vserver_exec $new_name start<br />
<br />
cd $orig_dir<br />
</pre></div>
90.152.0.27