Trouble running statrup script on Linux

652 Views Asked by At

I'm using the Amazon flavor of 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

and I want to run the following script upon system reboot ...

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

So I created this file,

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

with the lines

#!/bin/sh

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

However, when I reboot my system, this script isn't getting invoked. What steps have I left out? I can run the script fine at a command line when I'm logged in.

Edit: Also, I created this symlink in /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

Still no luck.

2

There are 2 best solutions below

7
On BEST ANSWER

You have to add the start-up script under init.d to your default runlevel.

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

Which should create symlinks to your script under the appropriate /etc/rc?.d folder(s).

0
On

This depends on which startup program is being used. Assuming you have privileges to do so, and if the star up program is the chkconfig program your etc/init.d/start script must follow suit in that you need such header fields like:

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

For other programs, like systemctl (redhat/fedora) you'll need to create a file with directives in it in the following folder:

  /etc/systemd/system/

You'd typically make a file called serviceName.service with the following entries:

[Unit]
Description=MyApp

[Service]

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

[Install]
WantedBy=multi-user.target

Then run:

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

If this is a LSB (Linux Standards Based) OS/Startup you should follow the tutorial below:

https://wiki.debian.org/LSBInitScripts