Commit 62f30bb2 authored by Miloš Diviš's avatar Miloš Diviš
Browse files

added toggle maintance mode option and help

parent aa90a121
......@@ -3,7 +3,6 @@
# Deploy script for Nette application
#
# -d to delete logs and html exceptions on server
# config.local.neon replaced by config.production.neon on production server
#
......@@ -19,18 +18,55 @@ 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/
# check options
delete_logs=0
while getopts ":d" opt; do
while getopts ":dh-:" opt; do
case $opt in
d)
delete_logs=1
;;
\?)
echo 'Invalid option!'
h)
echo 'Deploy script for Nette application'
echo '-----------------------------------'
echo '-d to delete remote logs and exceptions'
echo 'exiting with no action'
exit 1
echo '--toggle-maintenance to turn on/off maintenance mode on remote server'
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
;;
"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
;;
esac
;;
esac
done
......@@ -42,8 +78,6 @@ cd $current_dir
# set maintenance mode
echo '* setting maintenance mode on remote app'
scp -q -i $key_path $user@$server:$remote_dir/www/index.php temp/
# set maintance mode if app is on remote
if [ -f temp/index.php ]
then
......@@ -69,7 +103,7 @@ echo "* Starting rsync to $server:$remote_dir"
echo " * sendig project files"
rsync -az \
--delete \
--filter "P log/*.log" --filter "P log/*.html" \
--filter "P log/*.log" --filter "P log/*.html" --filter "P /.htaccess" \
--include ".htaccess" --exclude-from exclude.txt \
. $user@$server:$remote_dir/
......
#!/bin/bash
server='195.210.29.9'
user='k-architekt.cz'
remote_dir='/web'
key_path='/home/mario/.ssh/websupport_key'
while getopts ":d-" opt; do
case ${opt} in
d)
echo '1'
;;
-)
case ${OPTARG} in
"tm"*)
echo '2'
;;
esac
;;
esac
done
while getopts ":d" opt; do
case $opt in
d)
delete=1
echo '* remote logs removed'
;;
\?)
echo "Invalid option: -d to delete remote logs" >&2
;;
esac
if [ $delete -eq 1 ]
then
sftp -q -i $key_path $user@$server << SFTPDELIM
cd $remote_dir
rm log/*.log
rm log/*.html
bye
SFTPDELIM
fi
while getopts ":a-:" opt; do
case ${opt} in
a) echo "Do something"
;;
-)
case ${OPTARG} in
"word"*) echo "This works"
;;
esac
esac
done
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