I have an auto-scaling group on Amazon Web Services (AWS). I want to preserve the logfiles on an instance (Amazon Linux AMI) when the group scales down. My current idea is to use the s3cmd tool in a script that runs when the instance is rebooted or shutdown. The script (sendlogtos3, in the /etc/init.d directory) runs fine from the command line. It also executes on reboot/shutdown (it logs its message in the /var/log/messages file), but the critical part, the s3cmd command, isn't executing. No s3cmd output is sent to the messages file on reboot, but it is when run from the command line.
This is the script:
#!/bin/bash
PATH=$PATH:/usr/sbin:/opt/aws/bin
start(){
touch /var/lock/subsys/0sendlogtos3
}
stop() {
S3_BUCKET=<<bucket_name>>
EC2_INSTANCE_STRING="`ec2-metadata -i`"
LOG_FILE_LOCATION=/var/log/httpd/
s3_dest=s3://$S3_BUCKET/${EC2_INSTANCE_STRING:13}/
s3cmd --config /root/.s3cfg put -r $LOG_FILE_LOCATION $s3_dest >> /var/log/messages 2>&1
wait
echo "`date`" - sendlogtos3 executed >> /var/log/messages
rm -f /var/lock/subsys/0sendlogtos3
}
case "$1" in
start)
start
;;
stop)
stop
;;
esac
########END#######
The file is linked (symbolically) in the rc0.d and rc6.d folders as K000sendlogtos3, and in the rc3.d folder as S99sendlogtos3. The permissions on the script look correct (rwxr-xr-x). I have tried explicitly stating the location of the config file, and to follow symbolic links, but neither of those had any effect.
I can't figure out why the s3cmd isn't running. Does anyone have any ideas? Or how to figure out the problem?