3
votes

Spring Boot has a handy feature that it will embed an init.d starup script into an executable jar if you configure the maven plugin to do so: http://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html#deployment-install

So I am "installing" a Spring Boot app (executable fat jar) as a service in Centos 6.6 using the above method.

So far so good. I create a link to my jar and set the permissions:

sudo ln -s  /path/to/myapp.jar  /etc/init.d/my-service
sudo chmod 0755 /etc/init.d/my-service

And I can successfully start the application:

sudo service my-service start

However, I want the app to come up on startup, so I use the chkconfig utility:

sudo chkconfig --add my-service
sudo chkconfig my-service on

No errors with those commands, but when I reboot Centos the service does not auto-start. running:

sudo service my-service status

shows:

Not running

running:

chkconfig --list my-service

shows:

my-service      0:off   1:off   2:on    3:on    4:on    5:on    6:off

Everything looks good, but it's not starting. At this point I can manually start the service with "sudo service my-service start" and it comes back up, but it's not auto-starting on boot.

Any ideas? Thanks

2

2 Answers

2
votes

Problem solved. Turned out to be a path issue and my fault. The path where the application lived was a mounted directory that was not available at boot time.

0
votes

I have the similar issue, I got the following error message when I run service myapp start

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/springframework/boot/loader/JarLauncher : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: org.springframework.boot.loader.JarLauncher. Program will exit.

However I could make it work via directly run /etc/init.d/app start.

Finally I found the problem is the default jdk is 1.6 although the java is 1.8 in the current user. Then I changed the symbolic and it worked.

enter image description here