Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would a shutdown script NOT run?

I have installed a shutdown script on an Ubuntu system which doesn't get executed. It is an Amazon EC2 instance. I'm not sure it has to do with this fact just wanted to point it out.

The script should push some log files to an Amazon S3 bucket so it has to be executed while networking is up.

Here is how I installed the script:

1) Created the file in /etc/init.d/push-apache-logs-to-s3.sh with the required commands.

2) Made it executable with sudo chmod +x push-apache-logs-to-s3.sh

3) Executed sudo update-rc.d push-apache-logs-to-s3.sh start 0 0 .

Output from the above was:

update-rc.d: warning: /etc/init.d/push-apache-logs-to-s3.sh missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
 Adding system startup for /etc/init.d/push-apache-logs-to-s3.sh ...
   /etc/rc0.d/S00push-apache-logs-to-s3.sh -> ../init.d/push-apache-logs-to-s3.sh

The contents of /etc/rc0.d/ is now:

lrwxrwxrwx  1 root root   17 Jul 31  2012 K09apache2 -> ../init.d/apache2
lrwxrwxrwx  1 root root   29 Jun 16  2012 K10unattended-upgrades -> ../init.d/unattended-upgrades
lrwxrwxrwx  1 root root   26 Jun 16  2012 K15landscape-client -> ../init.d/landscape-client
lrwxrwxrwx  1 root root   19 Apr 10 11:11 K20memcached -> ../init.d/memcached
-rw-r--r--  1 root root  353 Jul 26  2012 README
lrwxrwxrwx  1 root root   35 Jul 10 12:01 S00push-apache-logs-to-s3.sh -> ../init.d/push-apache-logs-to-s3.sh
lrwxrwxrwx  1 root root   18 Jun 16  2012 S20sendsigs -> ../init.d/sendsigs
lrwxrwxrwx  1 root root   17 Jun 16  2012 S30urandom -> ../init.d/urandom
lrwxrwxrwx  1 root root   22 Jun 16  2012 S31umountnfs.sh -> ../init.d/umountnfs.sh
lrwxrwxrwx  1 root root   20 Jun 16  2012 S35networking -> ../init.d/networking
lrwxrwxrwx  1 root root   18 Jun 16  2012 S40umountfs -> ../init.d/umountfs
lrwxrwxrwx  1 root root   20 Jun 16  2012 S60umountroot -> ../init.d/umountroot
lrwxrwxrwx  1 root root   14 Jun 16  2012 S90halt -> ../init.d/halt

When I manually execute the script with sudo ./push-apache-logs-to-s3.sh, it does the intended job.

Are these scripts executed by root? What am I missing?

like image 634
marekful Avatar asked Jul 31 '26 14:07

marekful


1 Answers

I'm not sure if that script already accomplishes these requirements but the first thing i would try is to check if that script is a valid LSB script,afaik your script needs to be adapted to a LSB-friendly structure. This means that you need to:

  • include 'start, stop, restart, force-reload, and status' for the first ($1) argument, a case structure is a good idea
  • return correct exit codes for each of these cases
  • document run-time deps in a lsb-like structure (you can check: http://refspecs.linuxbase.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/initscrcomconv.html)

it is also a good idea to include init.d functions for logging and debugging, such as log_success_msg or log_failure_msg , for that you need to include this in your script: . /lib/lsb/init-functions

Anyway there is a lot of documentation about LSB init scripts.

I hope that helps.

regards.

like image 95
blu3g3 Avatar answered Aug 03 '26 06:08

blu3g3



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!