0

我正在使用亚马逊的 Linux 风格

uname -a
Linux mydomain.org 3.19.25-82.99.amzn1.x86_64 #1 SMP Wed Dec 3 21:29:43 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

我想在系统重新启动时运行以下脚本...

ls -al /home/davea/install/apache-tomcat-6.0.35/bin/startup.sh
-rwxr-xr-x 1 davea mycompany 2023 Nov 28  2011 /home/davea/install/apache-tomcat-6.0.35/bin/startup.sh

所以我创建了这个文件,

-rwxr-xr-x 1 root root 73 Dec 10 19:29 /etc/init.d/start_tomcat

用线条

#!/bin/sh

sh /home/davea/install/apache-tomcat-6.0.35/bin/startup.sh

但是,当我重新启动系统时,不会调用此脚本。我遗漏了哪些步骤?登录后,我可以在命令行中正常运行脚本。

编辑:另外,我在 /etc/rc.d ...

ls -al /etc/rc.d/start_tomcat
lrwxrwxrwx 1 root root 24 Dec 10 19:29 /etc/rc.d/start_tomcat -> /etc/init.d/start_tomcat

仍然没有运气。

4

2 回答 2

0

您必须将启动脚本添加init.d到您的默认运行级别。

sudo update-rc.d /etc/init.d/start_tomcat defaults

哪个应该在适当的/etc/rc?.d文件夹下创建指向您的脚本的符号链接。

于 2014-12-10T19:52:07.337 回答
0

这取决于正在使用的启动程序。假设您有权限这样做,并且如果启动程序是 chkconfig 程序,则您的 etc/init.d/start 脚本必须遵循,因为您需要这样的标头字段:

   # chkconfig: <levels> <start> <stop>
   # description: <some description>

对于其他程序,例如 systemctl (redhat/fedora),您需要在以下文件夹中创建一个包含指令的文件:

  /etc/systemd/system/

您通常会创建一个名为 serviceName.service 的文件,其中包含以下条目:

[Unit]
Description=MyApp

[Service]

ExecStart=/path/to/myService/executable.sh

[Install]
WantedBy=multi-user.target

然后运行:

sudo systemctl enable /etc/systemd/system/hello.service
sudo systemctl start hello.service

如果这是 LSB(基于 Linux 标准)的操作系统/启动,您应该遵循以下教程:

https://wiki.debian.org/LSBInitScripts

于 2014-12-10T20:05:00.327 回答