Commit 9732d59b authored by Miloš Diviš's avatar Miloš Diviš
Browse files

toggle maintanec separated in function, delete cache option added

parent c41b3daa
......@@ -12,14 +12,49 @@ user='k-architekt.cz'
remote_dir='/web'
key_path='/home/mario/.ssh/websupport_key'
rsync_exclude=('/www/images/uploads/*')
temp_dir='/temp'
# index.php excluded from project files sync and send last because of maintenance mode
common_exclude=('*.ssh' '/temp/*' '/log/*' '/nbproject' '/.git' 'deploy.sh' '*~'\
'.gitignore' 'composer.json' '/www/index.php' \
'config.local.neon' 'config.production.neon')
# download remote index.php to set maintenance mode
scp -q -i $key_path $user@$server:$remote_dir/www/index.php temp/
function downloadIndex {
scp -q -i $key_path $user@$server:$remote_dir/www/index.php ./$temp_dir/
}
function displayHelp {
echo 'Deploy script for Nette application'
echo '-----------------------------------'
echo '-d to delete remote logs and exceptions'
echo '--delete-cache deletes temp/cache contents WITHOUT DEPLOY'
echo '--toggle-maintenance turns on/off maintenance mode on remote server WITHOUT DEPLOY'
}
function toggleMaintenance {
downloadIndex
if [ -f ./$temp_dir/index.php ]
then
state=''
if grep -Eq "require '\.maintenance\.php'" ./$temp_dir/index.php
then
sed -ri "/require '\.maintenance\.php';/d" ./$temp_dir/index.php
state='disabled'
else
sed -ri "/^(<\?php|<\?)/a require '.maintenance.php';" ./$temp_dir/index.php
state='enabled'
fi
rsync -az \
./$temp_dir/index.php $user@$server:$remote_dir/www/
rm ./$temp_dir/index.php
echo "*** Maintenance mode $state"
else
echo "!!! No index on remote server ($user@$server:$remote_dir/www/index.php)"
exit 1
fi
}
# check options
delete_logs=0
......@@ -29,42 +64,28 @@ while getopts ":dh-:" opt; do
delete_logs=1
;;
h)
echo 'Deploy script for Nette application'
echo '-----------------------------------'
echo '-d to delete remote logs and exceptions'
echo '--toggle-maintenance to turn on/off maintenance mode on remote server'
displayHelp
exit 0
;;
-)
case $OPTARG in #case for long switches
"toggle-maintenance"*)
if [ -f temp/index.php ]
state=''
then
if grep -Eq "require '\.maintenance\.php'" temp/index.php
then
sed -ri "/require '\.maintenance\.php';/d" temp/index.php
state='disabled'
else
sed -ri "/^(<\?php|<\?)/a require '.maintenance.php';" temp/index.php
state='enabled'
fi
rsync -az \
temp/index.php $user@$server:$remote_dir/www/
rm temp/index.php
echo "*** Maintenance mode $state"
else
echo "!!! No index on remote server ($user@$server:$remote_dir/www/index.php)"
exit 1
fi
exit 0
toggleMaintenance
exit 0
;;
"help")
echo 'Deploy script for Nette application'
echo '-----------------------------------'
echo '-d to delete remote logs and exceptions'
echo '--toggle-maintenance to turn on/off maintenance mode on remote server'
exit 0
"delete-cache"*)
toggleMaintenance
mkdir ./$temp_dir/empty
rsync -az --delete \
./$temp_dir/empty/ $user@$server:$remote_dir/temp/cache/
toggleMaintenance
rmdir ./$temp_dir/empty
echo '*** cache deleted'
exit 0
;;
"help"*)
displayHelp
exit 0
;;
esac
;;
......@@ -79,13 +100,14 @@ cd $current_dir
echo '* setting maintenance mode on remote app'
# set maintance mode if app is on remote
if [ -f temp/index.php ]
if [ -f ./$temp_dir/index.php ]
then
sed -ri "/^(<\?php|<\?)/a require '.maintenance.php';" temp/index.php
rsync -az \
temp/index.php $user@$server:$remote_dir/www/
rm temp/index.php
if grep -Eq "require '\.maintenance\.php'" ./$temp_dir/index.php
then
toggleMaintenance
else
echo " i maintenance mode was already on"
fi
fi
# create exclude text file
......@@ -114,10 +136,10 @@ rm exclude.txt
if [ -f app/config/config.production.neon ]
then
echo ' * sending production config'
cp app/config/config.production.neon temp/config.local.neon
cp app/config/config.production.neon ./$temp_dir/config.local.neon
rsync -az \
temp/config.local.neon $user@$server:$remote_dir/app/config/
rm temp/config.local.neon
./$temp_dir/config.local.neon $user@$server:$remote_dir/app/config/
rm ./$temp_dir/config.local.neon
else
echo ' i Production config not found'
fi
......@@ -126,7 +148,7 @@ echo ' * sending index.php'
rsync -az \
www/index.php $user@$server:$remote_dir/www/
echo '* rsync completed, maitenance mode off.'
echo '* rsync completed'
if [ $delete_logs -eq 1 ]
then
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment