Set script to auto-start when Linux boots

498 Views Asked by At

I have used the Maven appassembler plugin to generate Linux wrapper scripts around a Java Spring application 'myapp'.

I then get the following directory structure:

/home/myapp/platform/bin/myapp       <== Script that I start manually

The myapp script has "-rwxr-xr-x" rights and the owner is set to "myapp:myapp" and the script is set to run as user "myapp" (set from the Maven settings when building).

Now from root I issued the following command:

$ sudo ln -s /home/myapp/platform/bin/myapp /etc/init.d/service_myapp

which creates a symbolic link with "lrwxrwxrwx" rights and "root:root" as owner and points to my myapp script. I thought that would be enough to have this script execute at startup. However it doesn't seem to run. If I run it manually like:

$ cd /etc/init.d/
$ ./service_myapp

then I'm prompted for a password before it executes.

Can anyone explain what is happening here and/or what I'm doing wrong?

I have also tried this:

$ cd /etc/init.d/
$ update-rc.d service_myapp defaults 20

but gets this:

update-rc.d: warning: /etc/init.d/service_myapp missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
 Adding system startup for /etc/init.d/service_myapp ...
   /etc/rc0.d/K20service_myapp -> ../init.d/service_myapp
update-rc.d: symlink: Permission denied
1

There are 1 best solutions below

2
svlasov On

You are prompted for the password because some commands in the script require root, probably.

Also, you need to be root when running update-rc.d:

sudo update-rc.d service_myapp defaults 20

Finally, your script must be in SysV format and support start, stop, restart, force-reload, and status commands.