Skip to content

Commit 1d2ca09

Browse files
committed
1.0.2: Now moves existing mysl data to shared folder on provisioning
1 parent 168a72a commit 1d2ca09

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

config_php.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ config_php=(
66
'5.5.34 5.5 9005'
77
'5.6.20 5.6 9006'
88
'7.0.8 7 9007'
9-
'7.1.12 7.1 9008'
9+
# '7.1.12 7.1 9008'
1010
)

scripts/001-setup_users.sh

+19-20
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ function vagrant_groups() {
2121
# Change gid for any groups that are not assigned as expected, and remap any associated files and folders
2222
for i in "${config_groups[@]}"; do
2323
arr=(${i// / })
24-
group_newGID=${arr[0]}
25-
group_name=${arr[1]}
26-
group_name_padded={${arr[1]}' '}
24+
group_newGID="${arr[0]}"
25+
group_name="${arr[1]}"
26+
group_name_padded="${arr[1]}' '"
2727

2828
if [ ! $(getent group ${group_name}) ]; then
29-
echo "Creating new group ${group_name_padded:1:12} with gid ${group_newGID}"
29+
echo "Creating new group ${group_name_padded:0:10} with gid ${group_newGID}"
3030
groupadd -g ${group_newGID} ${group_name}
3131
fi
3232

3333
if [ $(getent group ${group_name} | cut -d':' -f3) != ${group_newGID} ]; then
3434
group_oldGID=$(getent group ${group_name} | cut -d':' -f3)
35-
echo "Remapping existing group ${group_name_padded:1:12} from GID ${group_oldGID} to GID ${group_newGID}"
35+
echo "Remapping existing group ${group_name_padded:0:10} from GID ${group_oldGID} to GID ${group_newGID}"
3636
groupmod -g ${group_newGID} ${group_name}
3737
echo "Reassigning files and folders associated with old group id to the new one"
3838
$(find / -gid ${group_oldGID} '!' -type l -exec chgrp ${group_newGID} '{}' ';' 2>&1 | grep -v 'No such file or directory') || true
@@ -63,37 +63,36 @@ function vagrant_users() {
6363
# Change uid and gid for any users that are not assigned as expected, and remap any associated files and folders
6464
for i in "${config_users[@]}"; do
6565
arr=(${i// / })
66-
user_newUID=${arr[0]}
67-
user_newGID=${arr[1]}
68-
user_name=${arr[2]}
69-
user_name_padded={${arr[2]}' '}
70-
user_homeDir=${arr[3]}
71-
user_shell=${arg[4]}
72-
user_comment=${arg[5]}
73-
74-
if [ ${user_homeDir} == '-' ]; then user_homeDir_arg='-M' ; else user_homeDir_arg="-d ${user_homeDir}" ; fi
75-
if [ ${user_shell} == '-' ]; then user_shell_arg=' ' ; else user_shell_arg="-s ${user_shell}" ; fi
76-
if [ ${user_comment} == '-' ]; then user_comment_arg=' ' ; else user_comment_arg="-c '${user_comment//-/ /}'" ; fi
66+
user_newUID="${arr[0]}"
67+
user_newGID="${arr[1]}"
68+
user_name="${arr[2]}"
69+
user_name_padded="${arr[2]}' '"
70+
user_homeDir="${arr[3]}"
71+
user_shell="${arg[4]}"
72+
user_comment="${arg[5]}"
73+
74+
if [ "${user_homeDir}" == '-' ]; then user_homeDir_arg='-M' ; else user_homeDir_arg="-d ${user_homeDir}" ; fi
75+
if [ "${user_shell}" == '-' ]; then user_shell_arg=' ' ; else user_shell_arg="-s ${user_shell}" ; fi
76+
if [ "${user_comment}" == '-' ]; then user_comment_arg=' ' ; else user_comment_arg="-c '${user_comment//-/ /}'" ; fi
7777

7878
if [ ! $(id -u ${user_name}) ]; then
79-
echo "Creating new user ${user_name_padded:1:12} with uid ${user_newUID} and gid ${user_newGID}"
79+
echo "Creating new user ${user_name_padded:0:10} with uid ${user_newUID} and gid ${user_newGID}"
8080
useradd -u ${user_newUID} -g ${user_newGID} ${user_homeDir_arg} ${user_comment_arg} ${user_shell_arg} ${user_name}
8181
fi
8282

8383
if [ $(id -u ${user_name}) != ${user_newUID} ]; then
8484
user_oldUID=$(id -u ${user_name})
85-
echo "Remapping existing user ${user_name_padded:1:12} from UID ${user_oldUID} to UID ${user_newUID}"
85+
echo "Remapping existing user ${user_name_padded:0:10} from UID ${user_oldUID} to UID ${user_newUID}"
8686
usermod -u ${user_newUID} ${user_name}
8787
echo "Reassigning files and folders associated with old user id to the new one"
8888
$(find / -uid ${user_oldUID} '!' -type l -exec chown ${user_newUID} '{}' ';' 2>&1 | grep -v 'No such file or directory') || true
8989
fi
9090

9191
if [ $(id -g ${user_name}) != ${user_newGID} ]; then
9292
user_oldGID=$(id -g ${user_name})
93-
echo "Remapping existing user ${user_name_padded:1:12} from GID ${user_oldGID} to UID ${user_newGID}"
93+
echo "Remapping existing user ${user_name_padded:0:10} from GID ${user_oldGID} to UID ${user_newGID}"
9494
usermod -g ${user_newGID} ${user_name}
9595
fi
96-
9796
done
9897
}
9998

scripts/400-setup_mysql.sh

+22-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,28 @@ echo "******************************"
66
# Enable trace printing and exit on the first error
77
set -ex
88

9-
# Setup Percona
9+
# If mysql is already here, move existing data to /srv/mysql/data and change my.cnf to point there
10+
if [ -f /etc/init.d/mysql* ]; then
11+
service mysql stop
12+
13+
sed -i "s/datadir.*/datadir = \/srv\/mysql\/data/" /etc/mysql/my.cnf
14+
if [ ! -d /srv/mysql/data/mysql ]; then
15+
echo "Moving mysql databases from /var/lib/mysql/ to /srv/mysql/data ..."
16+
mv /var/lib/mysql/* /srv/mysql/data
17+
else
18+
echo "Not moving mysql databases from /var/lib/mysql/ to /srv/mysql/data since data is already present there"
19+
fi
20+
service mysql start
21+
22+
# Get password for debian-sys-maintainer in case we have existing databases which need to have this set to a new value
23+
debian_sys_maint_pwd=`sudo grep password /etc/mysql/debian.cnf | head -n1 | cut -d' ' -f3`
24+
export MYSQL_PWD='root'
25+
echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root';" | mysql -u'root'
26+
echo "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '${debian_sys_maint_pwd}';" | mysql -u'root'
27+
export MYSQL_PWD=''
28+
fi
29+
30+
1031
if [ ! -f /etc/init.d/mysql* ]; then
1132
wget https://repo.percona.com/apt/percona-release_0.1-4.$(lsb_release -sc)_all.deb
1233
dpkg -i percona-release_0.1-4.$(lsb_release -sc)_all.deb
@@ -17,9 +38,6 @@ if [ ! -f /etc/init.d/mysql* ]; then
1738
apt-get install -y percona-server-server-5.6 percona-server-client-5.6 2>&1
1839
service mysql stop
1940

20-
# Get password for debian-sys-maintainer in case we have existing databases which need to have this set to a new value
21-
debian_sys_maint_pwd=`sudo grep password /etc/mysql/debian.cnf | head -n1 | cut -d' ' -f3`
22-
2341
sed -i "s/bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
2442
sed -i "s/max_allowed_packet.*/max_allowed_packet = 64M/" /etc/mysql/my.cnf
2543
sed -i "s/datadir.*/datadir = \/srv\/mysql\/data/" /etc/mysql/my.cnf
@@ -30,11 +48,6 @@ if [ ! -f /etc/init.d/mysql* ]; then
3048
echo "Not moving mysql databases from /var/lib/mysql/ to /srv/mysql/data since data is already present there"
3149
fi
3250
service mysql start
33-
export MYSQL_PWD='root'
34-
echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root';" | mysql -u'root'
35-
echo "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '${debian_sys_maint_pwd}';" | mysql -u'root'
36-
export MYSQL_PWD=''
37-
service mysql restart
3851
fi
3952

4053
# Make mysql's socket available to php - e.g.

0 commit comments

Comments
 (0)