0

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
KimHansen
  • 375
  • 2
  • 12
  • Writing an init script is one way and if you want to go down that route I suggest you look at an example script for your distro, as it seems you are using Debian or Ubuntu have a look at this: http://pastebin.com/N3XGD6us it should get you started. – tribeca Mar 17 '15 at 16:01
  • The /home/myapp/platform/bin/myapp script is auto-generated by appassembler Maven plugin, so I already have a script that I can call with fx. `./myapp start` and `./myapp stop` and `./myapp status` etc. – KimHansen Mar 17 '15 at 16:09
  • What kind of password you are prompted for? – svlasov Mar 17 '15 at 16:17
  • The `root` or `myapp` password (they are currently the same, and yes I know they shouldn't be) because if I enter it then the script works. – KimHansen Mar 17 '15 at 16:19
  • Doesn't make sense, if you say you are already logged as root. – svlasov Mar 17 '15 at 16:22

1 Answers1

0

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.

svlasov
  • 9,923
  • 2
  • 38
  • 39
  • I was already logged in as root, so I thought that no need to use `sudo`. As far as I can see the auto-generated script (by appassembler) supports `console`, `start`, `stop`, `restart`, `status` and `dump`. So the `force-reload` is not supported. Is there an option to appassembler to create SysV format? I'm using Ubuntu 14.04 server and it should be able to run there. – KimHansen Mar 17 '15 at 16:13
  • Try to copy the file under `init.d` instead of making a symlink. – svlasov Mar 17 '15 at 16:19