-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
release.sh
executable file
·102 lines (85 loc) · 2.6 KB
/
release.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
#!/bin/bash
# Change these variables according to your environment.
SCRIPT_ROOT=/files
HTML_ROOT=/html/shop
HTML_URL=http://page.tld
[email protected]:username/repository.git
COMMIT_HASH=HEAD
N98_MAGERUN=${SCRIPT_ROOT}/n98-magerun.phar
MEDIA_ROOT=/html/media
# check the --nodbupdate command line option
dbupdate=true
if [ "$1" = '--nodbupdate' ]
then
dbupdate=false
fi
# check if all used commands are allowed in this environment (managed servers often block various commands)
commands="git rm cp ln mv php ${N98_MAGERUN}"
for command in ${commands}
do
if type -P "${command}" &>/dev/null
then
continue
else
echo "${command} command not found."
exit 1
fi
done
# check if all given directories exist
directories="${SCRIPT_ROOT} ${HTML_ROOT} ${MEDIA_ROOT}"
for directory in ${directories}
do
if ! test -e "${directory}"
then
echo "${directory} command not found."
exit 1
fi
done
# get a new, clean version from the repository
echo '... cloning git repository ...'
git clone ${GIT_URI} ${HTML_ROOT}-new
cd ${HTML_ROOT}-new
# checkout files from given commit
echo '... checking out given commit ...'
git checkout ${COMMIT_HASH}
rm -rf .git
cd ..
# put local.xml to new revision
cp ${SCRIPT_ROOT}/local.xml ${HTML_ROOT}-new/app/etc/local.xml
# symlink media directory
ln -s ${MEDIA_ROOT} ${HTML_ROOT}-new/media
# clear the cache before enabling the maintenance mode to reduce the down time
echo '... clearing the cache ...'
php ${N98_MAGERUN} cache:flush
# enable maintenance mode
echo '... enabling maintenance mode ...'
> ${HTML_ROOT}/maintenance.flag
> ${HTML_ROOT}-new/maintenance.flag
# copy session files if they are stored in the file system
echo '... copying session files ...'
if test -e ${HTML_ROOT}/var/session/
then
cp -R ${HTML_ROOT}/var/session/ ${HTML_ROOT}-new/var/session/
fi
# point directory to the new revision
# since removing can take too long, first move and delete later to increase performance
mv ${HTML_ROOT} ${HTML_ROOT}-old
mv ${HTML_ROOT}-new ${HTML_ROOT}
cd ${HTML_ROOT}
# clear the cache
echo '... clearing the cache ...'
php ${N98_MAGERUN} cache:flush
# clear the APC cache
php ${SCRIPT_ROOT}/apc_clear_call.php --url=${HTML_URL} --htmlroot=${HTML_ROOT} --scriptroot=${SCRIPT_ROOT}
# run install/upgrade scripts, so that they are executed only once
if [ "$dbupdate" = true ]
then
echo '... running setup scripts ...'
php ${N98_MAGERUN} sys:setup:run
fi
# disable maintenance mode
echo '... disabling maintenance mode ...'
rm maintenance.flag
# delete old HTML root
echo '... deleting old html root ...'
rm -rf ${HTML_ROOT}-old