Spring Boot Actuator application won't start on Ubuntu VPS
localhost-startStop-1
is trying to create a new instance of SecureRandom
and it's stuck trying to read data from an entropy source. This typically occurs because the source has been depleted. The default entropy source is /dev/random
. It's known as a blocking source as it will block when an attempt is made to read random data and none is available. Another source on Linux is /dev/urandom
. Its main benefit over /dev/random
is that it's non-blocking. There's some debate over whether or not using /dev/urandom
will make things less secure. This article may be of interest.
In summary, using /dev/urandom
will avoid the problem you're seeing, at the possible cost of decreased security. You can configure Spring Boot's embedded Tomcat instance to use /dev/urandom
via a system property:
-Djava.security.egd=file:/dev/./urandom
How to deploy my Spring Boot application in these circumstances?
This solution applied to my hostgator VPS.
Consider:
ACCOUNT_NAME to be your account name;
DOMAIN_NAME to be your domain name. It can also be a subdomain;
- Backup your apache settings:
cp -vp /etc/apache2/conf/httpd.conf{,-BKP}
- Uncomment the lines of include in the vhost of the domain. Do it for the HTTP(std) and for the HTTPS(ssl):
vim /etc/apache2/conf/httpd.conf
- Once you accessed the file, search the following lines and remove the #
Include
"/etc/apache2/conf.d/userdata/std/2_4/ACCOUNT_NAME/DOMAIN_NAME/.conf"
Include "/etc/apache2/conf.d/userdata/ssl/2_4/ACCOUNT_NAME/DOMAIN_NAME/.conf"
- Create the following directories:
mkdir -p /etc/apache2/conf.d/userdata/std/2_4/ACCOUNT_NAME/DOMAIN_NAME
mkdir -p /etc/apache2/conf.d/userdata/ssl/2_4/ACCOUNT_NAME/DOMAIN_NAME
- Create a .conf for std and ssl.
vim /etc/apache2/conf.d/userdata/std/2_4/ACCOUNT_NAME/DOMAIN_NAME/ACCOUNT_NAME.conf
vim /etc/apache2/conf.d/userdata/ssl/2_4/ACCOUNT_NAME/DOMAIN_NAME/ACCOUNT_NAME.conf
/etc/apache2/conf.d/userdata/std/2_4/ACCOUNT_NAME/DOMAIN_NAME/ACCOUNT_NAME.conf
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
ProxyPass "/" "http://DOMAIN_NAME:10002/"
/etc/apache2/conf.d/userdata/ssl/2_4/ACCOUNT_NAME/DOMAIN_NAME/ACCOUNT_NAME.conf
ProxyPass "/" "http://DOMAIN_NAME:10002/"
- Once you are done, restart the httpd service.
service httpd restart
Spring-boot application won't boot at startup inside docker
Got it! Once I installed haveged
on the host, the process immediately moved forward, and spring booted fine. I will post more once I do a bit more research into how docker interacts with haveged
on the host.
In summary the following command issued on the host will fix the the issue:
apt-get install haveged -y
If anyone has a detailed understanding of this, feel free to post!
The thing that I don't understand at the moment, is why the host machine needed extra code, and everything wasn't isolated within the docker container.
Spring Boot application as a Service
The following works for springboot 1.3 and above:
As init.d service
The executable jar has the usual start, stop, restart, and status commands. It will also set up a PID file in the usual /var/run directory and logging in the usual /var/log directory by default.
You just need to symlink your jar into /etc/init.d like so
sudo link -s /var/myapp/myapp.jar /etc/init.d/myapp
OR
sudo ln -s ~/myproject/build/libs/myapp-1.0.jar /etc/init.d/myapp_servicename
After that you can do the usual
/etc/init.d/myapp start
Then setup a link in whichever runlevel you want the app to start/stop in on boot if so desired.
As a systemd service
To run a Spring Boot application installed in var/myapp you can add the following script in /etc/systemd/system/myapp.service:
[Unit]
Description=myapp
After=syslog.target
[Service]
ExecStart=/var/myapp/myapp.jar
[Install]
WantedBy=multi-user.target
NB: in case you are using this method, do not forget to make the jar file itself executable (with chmod +x) otherwise it will fail with error "Permission denied".
Reference
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/html/deployment-install.html#deployment-service
Problem running basic Spring Boot application
I tried to follow below steps in command line and worked successfully:
git clone https://github.com/spring-guides/gs-spring-boot.git
after cloning completed a new directory gs-spring-boot will be created then change directory to gs-spring-boot/initial
cd gs-spring-boot/initial
then run following command
./mvnw spring-boot:run
if you already have installed maven and available in your path instead you can use following command
mvn spring-boot:run
then spring application start to run after spring boot application start up finished without pressing Ctrl+c and terminating application switch to postman and point to address:
localhost:8080
then you will see expected result as below
Related Topics
How to Set an Environment Variable at Runtime from Java
Efficient Way to Divide a List into Lists of N Size
How Are Constructors Called During Serialization and Deserialization
How to Attach Source or Javadoc in Eclipse for Any Jar File E.G. Javafx
How to Run All Tests Belonging to a Certain Category in Junit 4
Is Spring Default Scope Singleton or Not
Drag and Drop Custom Object from Jlist into Jlabel
How Does Double to Int Cast Work in Java
String S = New String("Xyz"). How Many Objects Has Been Made After This Line of Code Execute
How to Iterate Over a Priorityqueue
Reverse Hashmap Keys and Values in Java
Eclipse Autocomplete (Content Assist) with Facelets (Jsf) and Xhtml
404 Error Redirect in Spring with Java Config