LSB Init script not executed

0

I've created an LSB compatible init script which I intend to use to push some log files to an Amazon S3 bucket when the system is going down but it doesn't get executed.

Here is the script contents in in file /etc/init.d/push-apache-logs-to-s3.sh (I replaced with my client's branding name with XXX):

#! /bin/sh
### BEGIN INIT INFO
# Provides:          push-apache-logs-to-s3
# Required-Start:    
# Required-Stop:     $local_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Push Apache log files to S3
# Description: 
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin

. /lib/lsb/init-functions

do_stop () {
    LOG_DIR=/var/log/apache2/
    BACKUP_DEST=s3://XXX-backups/api-logs
    EC2_ID=`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`

    echo -n "Entering log directory..."

    if cd $LOG_DIR
    then
      echo "OK"
    else
      echo
      echo "Cannot change directory... BACKUP ABORTED!"
      echo
      exit 3
    fi

    echo -n "Pushing log files to S3..."

    # push log files
    if s3cmd put XXX-api_access.log* $BACKUP_DEST/$EC2_ID/ >/dev/null
    then
      echo "OK"
    else
      echo
      echo "LOG FILES COULD NOT BE MOVED TO S3! BAKCUP NOT COMPLETE!"
      echo
      exit 5
    fi

    echo "*** Backup finished at " `date`
    echo "-----------------------------------------------"

    exit 0
}

case "$1" in
  start)
        # No-op
        ;;
  restart|reload|force-reload)
        echo "Error: argument '$1' not supported" >&2
        exit 3
        ;;
  stop)
        do_stop
        ;;
  *)
        echo "Usage: $0 start|stop" >&2
        exit 3
        ;;
esac

:

Here is the command I used to install it:

sudo update-rc.d push-apache-logs-to-s3.sh start 01 2 3 4 5 . stop 01 0 1 6 .

which provided output:

 Adding system startup for /etc/init.d/push-apache-logs-to-s3.sh ...
   /etc/rc0.d/K01push-apache-logs-to-s3.sh -> ../init.d/push-apache-logs-to-s3.sh
   /etc/rc1.d/K01push-apache-logs-to-s3.sh -> ../init.d/push-apache-logs-to-s3.sh
   /etc/rc6.d/K01push-apache-logs-to-s3.sh -> ../init.d/push-apache-logs-to-s3.sh
   /etc/rc2.d/S01push-apache-logs-to-s3.sh -> ../init.d/push-apache-logs-to-s3.sh
   /etc/rc3.d/S01push-apache-logs-to-s3.sh -> ../init.d/push-apache-logs-to-s3.sh
   /etc/rc4.d/S01push-apache-logs-to-s3.sh -> ../init.d/push-apache-logs-to-s3.sh
   /etc/rc5.d/S01push-apache-logs-to-s3.sh -> ../init.d/push-apache-logs-to-s3.sh

The script uses s3cmd which is installed and configured on the system. s3cmd is in /usr/bin/ which is defined as PATH in the script.

When I execute the script by sudo ./push-apache-logs-to-s3.sh stop, it does the job.

Any suggestions what's wrong?

marekful

Posted 2013-07-10T13:51:39.617

Reputation: 163

Question was closed 2013-07-23T19:17:43.087

Please don't repost, this is essentially the same question. Add the new information to your original question please, I will update my answer there with what (I think) is your problem here.

– terdon – 2013-07-10T14:10:46.223

1you could try redirecting all your output to a log file and see if anything gets written. It will give you a better insight of where it's failing. – GnP – 2013-07-10T14:12:14.073

@terdon I created a new post, because the situation has fully changed. Now I have an LSB script while when posted the prev. question I just had a "pure bash" script. – marekful – 2013-07-10T14:13:18.170

Also, none of the answers for the other post took me closer to a solution. – marekful – 2013-07-10T14:16:14.233

I know, it is just generally preferable not to add extra questions. See my updated answer to your original question, does that help? – terdon – 2013-07-10T14:17:58.683

No answers