Skip to content

Instantly share code, notes, and snippets.

@lvidarte
Created June 25, 2014 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lvidarte/7b859ddbeda2f8ce9945 to your computer and use it in GitHub Desktop.
Save lvidarte/7b859ddbeda2f8ce9945 to your computer and use it in GitHub Desktop.
#!/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