Created
June 25, 2014 20:17
-
-
Save lvidarte/7b859ddbeda2f8ce9945 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export LANG=en_US.UTF-8 | |
S3_LOG=/tmp/s3.log | |
S3_PID=/tmp/s3.pid | |
MMIN=30 # minutes to wait the process finish | |
function log() | |
{ | |
local MSG=$1 | |
echo "`date` - $MSG" >> $S3_LOG | |
} | |
log "START sync S3" | |
if [ -f "$S3_PID" ] | |
then | |
PID=`cat $S3_PID` | |
kill -0 $PID 2>/dev/null | |
if [ $? -eq 0 ] | |
then | |
if test `find "$S3_PID" -mmin +$MMIN` | |
then | |
log "The process $PID is taking more than $MMIN minutes.. killing" | |
kill $PID && rm -f $S3_PID | |
else | |
log "Process already running with PID $PID" | |
exit | |
fi | |
else | |
rm -f $S3_PID | |
fi | |
fi | |
nice -n 20 \ | |
/usr/local/bin/aws s3 sync \ | |
/var/www/www.coquelux.site/assets/ \ | |
s3://cdn3.coquelux.com.br/assets/ \ | |
--acl public-read \ | |
--quiet \ | |
>> $S3_LOG 2>&1 \ | |
& | |
PID=$! | |
echo $PID > $S3_PID | |
log "AWS process started with PID $PID" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment