为什么关机脚本不会运行?

时间:2013-07-10 12:41:08

标签: ubuntu amazon-ec2

我在Ubuntu系统上安装了一个没有执行的关闭脚本。它是Amazon EC2实例。我不确定这与事实有关,只是想指出来。

脚本应该将一些日志文件推送到Amazon S3存储桶,因此必须在网络启动时执行。

以下是我安装脚本的方法:

1)使用所需命令在/etc/init.d/push-apache-logs-to-s3.sh中创建文件。

2)使用sudo chmod +x push-apache-logs-to-s3.sh

使其可执行

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

以上的输出是:

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

/etc/rc0.d/的内容现在是:

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

当我用sudo ./push-apache-logs-to-s3.sh手动执行脚本时,它会完成预期的工作。

这些脚本是否由root执行?我错过了什么?

2 个答案:

答案 0 :(得分:1)

我不确定该脚本是否已经完成这些要求,但我要尝试的第一件事是检查该脚本是否是一个有效的LSB脚本,但是您的脚本需要适应LSB友好的结构。 这意味着你需要:

包含用于日志记录和调试的init.d函数(例如log_success_msg或log_failure_msg)也是一个好主意,因为您需要在脚本中包含它: 。 / LIB / LSB / INIT-功能

无论如何,有很多关于LSB init脚本的文档。

我希望有所帮助。

问候。

答案 1 :(得分:1)

不兼容LSB的Init脚本仍应运行。我发现原因是s3cmd无法读取其配置文件。由于某些我不知道的原因,在运行级别更改(0)期间,当init执行init-scripts时,显然运行这些脚本的root用户不算作“真正的”用户,因此它不会没有s3cmd尝试读取配置的“home”目录。

使用--config=...命令行参数s3cmd明确指定配置文件的位置可以解决此问题。

相关问题