1

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?

unknownrisk
  • 113
  • 3

1 Answers1

2

It's probably not running because it's unable to find the binary. Without any error log though, that's just an assumption I'm making.

Try adjusting the s3cmd part in your script to use its full path. I'm not sure how you installed s3cmd (either via yum or manually), but you can find out its full path by running which s3cmd.

jaseeey
  • 1,462
  • 16
  • 20
  • Yes the pathing was the problem. I also had to supply path info for the ec2-metadata tool (/opt/aws/bin), and explicitly tell s3cmd where the config file was to get all of it to work. – unknownrisk Feb 06 '14 at 23:04
  • Great, it's usually the issue. It won't have an issue for any binaries in /bin, because that's where bash is located. But anything outside of that you either need to specify manually or set the path environment variable. – jaseeey Feb 06 '14 at 23:06
  • My problem was similar, it counld find s3cmd in /bin, but not the config file in `/root/.s3cfg` – Ray Jul 09 '14 at 19:51