-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevolistrano.sh
executable file
·172 lines (130 loc) · 6.1 KB
/
evolistrano.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/sh
set -e
set -u
export LC_ALL=C
full_path=`echo $(dirname $(readlink -f $0))`
. $full_path/evolistrano.conf
tmp_dir=`mktemp -p $tmpdir -d`
dir_export=$tmp_dir/export
time_stamp=`date +%s`
usage() {
cat <<EOT
Usage: $0 [OPTION] REVNUM
Sans option : Mise en preproduction
-P : Mise en production
EOT
exit 1
}
read_confirm() {
read ok
if [ "$ok" != "y" ]; then
exit 1
fi
}
[ $# -lt 1 ] && usage
if [ $1 == "-P" ]; then
prod=1
shift
else
prod=0
fi
[ $# -lt 1 ] && usage
revnum=$1
if [ $prod -eq 1 ]; then
log_file=$logdir/prod.log
opname="PRODUCTION"
destdir="prod"
sshuser=$deployproduser
staticdestdir="prod/static"
confdir=$confproddir
else
log_file=$logdir/preprod.log
opname="preprod"
destdir="preprod"
sshuser=$deploypreproduser
staticdestdir="preprod/static"
confdir=$confpreproddir
fi
# Display infos about deployement
echo
svn info $svnpath -r $revnum
echo -n "Confirmer la mise en $opname de la révision $revnum ? [y/N] "
read_confirm
# Warning if it's not the last revision
last_commited_rev=`svn info $svnpath | grep ^Revision | sed 's/.*: \([0-9]\+\)$/\1/'`
if [ $revnum -ne $last_commited_rev ]; then
echo -n "Attention, la révision $revnum n'est pas la plus récente. Continuer ? [y/N] "
read_confirm
fi
tmpfile=`mktemp -p $tmpdir`
cat <<EOT >$tmpfile
Date : `date`
User : $LOGNAME
Revision : $revnum
EOT
# Send email notification
[ $prod -eq 1 ] && [ "$mailnotif" != "" ] && ( cat $tmpfile | mail -s "[Evolistrano] Mise en prod" $mailnotif )
cat $tmpfile >>$log_file
rm $tmpfile
#
umask 022
svn export -r $revnum -q $svnpath $dir_export
echo
echo "SVN export to $dir_export"
echo
#set +e
local_space=`du -sm $dir_export/ | sed 's/^\([0-9]\+\)\t.*$/\1/'`
# Deploy on WWW servers
for remote in $wwwlist; do
# Be sure to have space for deploying
remote_space=`ssh -p $sshport -o UserKnownHostsFile=$full_path/known_hosts -i $full_path/$sshkey $sshuser@$remote df -lPm $subdocroot | grep ^/ | tr -s " " | cut -d" " -f4`
if [ $local_space -ge $remote_space ]; then echo "WARNING... $remote has only $remote_space Mo while you want upload $local_space Mo. Do you want stop ? [y/N]"; read_confirm; fi
echo "sending code on $remote"
if [ "$usehardlinks" = "true" ]; then
rsync -rlptq --link-dest=../current -e "ssh -p $sshport -o UserKnownHostsFile=$full_path/known_hosts -i $full_path/$sshkey" $dir_export/ --delete $excludelist $sshuser@$remote:$subdocroot/$destdir/$time_stamp
else
rsync -rlptq -e "ssh -p $sshport -o UserKnownHostsFile=$full_path/known_hosts -i $full_path/$sshkey" $dir_export/ --delete $excludelist $sshuser@$remote:$subdocroot/$destdir/$time_stamp
fi
# Deploy conf files => UNCOMMENT AND ADJUST LINES
#scp -q -P $sshport -o UserKnownHostsFile=$full_path/known_hosts -i $full_path/$sshkey $full_path/conf-$destdir/foo-global.ini $sshuser@$remote:$subdocroot/$destdir/$time_stamp/config/config/foo/global.ini
#scp -q -P $sshport -o UserKnownHostsFile=$full_path/known_hosts -i $full_path/$sshkey $full_path/conf-$destdir/foo-database.ini $sshuser@$remote:$subdocroot/$destdir/$time_stamp/config/config/foo/database.ini
#scp -q -P $sshport -o UserKnownHostsFile=$full_path/known_hosts -i $full_path/$sshkey $full_path/conf-$destdir/bar-config.ini $sshuser@$remote:$subdocroot/$destdir/$time_stamp/config/config/bar/config.ini
# UNIX rights => ADJUST ALL RIGHTS, PARTICULARLY FOR ADDING WRITE PERMISSIONS
ssh -p $sshport -o UserKnownHostsFile=$full_path/known_hosts -i $full_path/$sshkey $sshuser@$remote chmod -R g+rX,o+rX $subdocroot/$destdir/$time_stamp
#ssh -p $sshport -o UserKnownHostsFile=$full_path/known_hosts -i $full_path/$sshkey $sshuser@$remote chmod -R g+w $subdocroot/$destdir/$time_stamp/cache
# ADD SPECIFIC ACTIONS ON WWW SERVERS
done
local_space=`du -sm $dir_export/$staticfilesdir | sed 's/^\([0-9]\+\)\t.*$/\1/'`
for remote in $staticlist; do
# Be sure to have space for deploying
remote_space=`ssh -p $sshport -o UserKnownHostsFile=$full_path/known_hosts -i $full_path/$sshkey $sshuser@$remote df -lPm $subdocroot | grep ^/ | tr -s " " | cut -d" " -f4`
if [ $local_s -ge $remote_s ]; then echo "WARNING... $remote has only $remote_s Mo while you want upload $local_s Mo : stop deploy now with Ctrl+C"; read enter; fi
echo "sending static on $remote"
rsync -rlptq -e "ssh -o UserKnownHostsFile=$full_path/known_hosts -i $full_path/$sshkey" $dir_export/$staticfilesdir --delete $excludelist $sshuser@$remote:$subdocroot/static
ssh -o UserKnownHostsFile=$full_path/known_hosts -i $full_path/$sshkey $sshuser@$remote chmod -R g+rX,o+rX $subdocroot/static
done
# Enable new code
last_frontal=`echo -n $wwwlist | sed 's/.* \+\([^ ]\+ *\)$/\1/'`
for remote in `echo -n $wwwlist | sed "s/$last_frontal//"`; do
if [ $prod -eq 1 ]; then
echo "stopping Apache on $remote"
ssh -o UserKnownHostsFile=$full_path/known_hosts -i $full_path/$sshkey $sshuser@$remote sudo /etc/init.d/apache2 stop
fi
# Change symlink current to new code
ssh -o UserKnownHostsFile=$full_path/known_hosts -i $full_path/$sshkey $sshuser@$remote "rm $subdocroot/$destdir/current && cd $subdocroot/$destdir && ln -s $time_stamp current"
if [ $prod -eq 1 ] && [ "$veryhighcritical" != "true" ]; then
echo "starting Apache on $remote"
sleep 3 && ssh -o UserKnownHostsFile=$full_path/known_hosts -i $full_path/$sshkey $sshuser@$remote sudo /etc/init.d/apache2 start
fi
done
for remote in $last_frontal; do
ssh -o UserKnownHostsFile=$full_path/known_hosts -i $full_path/$sshkey $sshuser@$remote "rm $subdocroot/$destdir/current && cd $subdocroot/$destdir && ln -s $time_stamp current"
done
if [ "$veryhighcritical" = "true" ]; then
for remote in `echo -n $wwwlist | sed "s/$last_frontal//"`; do
echo "starting Apache on $remote"
ssh -o UserKnownHostsFile=$full_path/known_hosts -i $full_path/$sshkey $sshuser@$remote sudo /etc/init.d/apache2 start
done
fi
# ADD SPECIFIC ACTIONS (SQL DEPLOYMENT, etc.)
rm -rf $tmp_dir