Created
August 18, 2013 14:12
-
-
Save aurelijusb/6261858 to your computer and use it in GitHub Desktop.
Small scripts to move mysql to other location and add new VirtualHost.
Designed for Apache and Ubuntu.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Adds new virtual host to Apache and hosts file. | |
if [ "$#" -ne 2 ] | |
then | |
echo "Usage: addVHost.sh directory domain" | |
echo "Example: www/myProject myproject.local" | |
exit 1 | |
fi | |
ApacheConf="/etc/apache2" | |
SitesAvailable="$ApacheConf/sites-available" | |
SitesEnabled="$ApacheConf/sites-enabled" | |
HostsFile="/etc/hosts" | |
CurrentDir=`pwd` | |
DocumentRoot="$CurrentDir/$1" | |
Domain=$2 | |
ServerName=$Domain | |
VHostTmp="/tmp/vhost" | |
HostsTmp="/tmp/hosts" | |
VHostText=" | |
<VirtualHost *:80> | |
DocumentRoot $DocumentRoot | |
ServerName $ServerName | |
</VirtualHost>" | |
HostsText="127.0.0.1 $Domain" | |
echo "${VHostText}" > $VHostTmp | |
sudo mv $VHostTmp "$SitesAvailable/$Domain" | |
sudo ln -s "$SitesAvailable/$Domain" "$SitesEnabled/$Domain" | |
cp $HostsFile $HostsTmp | |
echo "${HostsText}" >> $HostsTmp | |
sudo rm $HostsFile | |
sudo mv $HostsTmp $HostsFile | |
sudo service apache2 reload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Change Apache and MySql configuration to point to copies in home. | |
# Useful after distro reinstall. hard coded paths for Ubuntu system. | |
# Adapted from http://article.my-addr.com/?show=linux_ubuntu_change_datadir-move_mysql_database_to_other_path | |
# Assumes, that there are /home/server/mysql | |
CurrentDirectrory=`pwd` | |
Date=`date +%F-%H%M%S` | |
MysqlDir="/var/lib/mysql" | |
NewDir="$CurrentDirectrory/mysql" | |
MySqlBackup=".local/my.cnf-$Date" | |
MysqlConfig="/etc/mysql/my.cnf" | |
MySqlConfigTmp="/tmp/my.cnf-new" | |
AppArmor="/etc/apparmor.d/usr.sbin.mysqld" | |
AppArmorBackup=".local/apparmor.d.usr.sbin.mysqld-$Date" | |
AppArmorTmp="/tmp/apparmor-mysql" | |
if grep -q $NewDir $MysqlConfig | |
then | |
echo "MySql config already changed" | |
else | |
sudo service mysql stop | |
echo "Enshuring owner of $NewDir" | |
sudo chown -R mysql:mysql $NewDir/ | |
echo "Backuping my.cnf to ~/$MySqlBackup" | |
cp $MysqlConfig ~/$MySqlBackup | |
echo "Replacing path in my.cnf" | |
sed "s:$MysqlDir:$NewDir:g" $MysqlConfig > $MySqlConfigTmp | |
sudo rm $MysqlConfig | |
sudo cp $MySqlConfigTmp $MysqlConfig | |
rm $MySqlConfigTmp | |
echo "Backuping $AppArmor to ~/$AppArmorBackup" | |
cp $AppArmor ~/$AppArmorBackup | |
echo "Replacing path in usr.sbin.mysqld" | |
AppArmorText=" $NewDir r,\n $NewDir** rwk,\n $NewDir r,\n $NewDir* rw,\n}" | |
sed "s:}:$AppArmorText:g" $AppArmor > $AppArmorTmp | |
sudo rm $AppArmor | |
sudo cp $AppArmorTmp $AppArmor | |
rm $AppArmorTmp | |
sudo service apparmor reload | |
sudo service mysql start | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment