spring boot run on both windows and linux - spring-boot

I need to run my app on both windows and linux. I started with linux and used spring boot.
I run it simply with:
nohup java -jar ..... &
and I can easily tail the nohup log file.
I can find and kill the process easily too.
How can I do that in windows?
Thanks,
id

Spring Boot 1.3 (about to be released) has many improvements in that area; there is a service support for Unix and Windows.
Check the updated documentation

Related

Tomcat runs different application

I am developing a spring boot app with embeded tomcat server. When I start the project from spring and run it, I see the application which I ran on Virtual machine(windows)'s localhost while I should see my application which I am developing. It's strange that I see the application from virtual machine even when VM is shut down. Does it mean the tomcat has stored it in cache? How do I delete that data? I am using mac OS catalina.
Once run the below command in your terminal to kill your localhost then try
kill -9 $(lsof -t -i:8080)

Gradle > How to stop a Spring Boot application launched with gradle bootRun?

I started a spring boot application using gradle bootRun.
Doing ctrl-c in the terminal where I launched the command does not stop the application.
What is then the correct way of stopping it?
You can use the command gradle -stop to stop the Spring Boot application.
Not sure what operating system you are using but I am on a mac and was having the same problem, command + C wasn't working (on a mac the command key is equal to the Windows control key) but I used control+C and it did work. If you're on a Windows machine this doesn't help you but thought this might help others who are new to a mac.

Is there elegant way to terminate running instance of spring boot stand alone application?

I've been playing with spring boot version 1.5.8 release lately. I was able to stand it up as rest web service to handle incoming request.
This is how I activate the service. Note: linux environment.
nohup java -jar fooservice.jar &
Then I tail the nohup.outfile to monitor the start up process, any incoming request, any exception thrown and etc.
My question is how to terminate the instance of the program? I run ps -ef | grep command to find pid of the running instance then run kill -9 command to terminate it.
Is there elegant way to stop the service?
You can shutdown spring boot application by enabling actuator shutdown end point /actuator/shutdown, first we need to enable it here
management.endpoint.shutdown.enabled=true
endpoints.shutdown.enabled=true
And then invoke it
localhost:port/actuator/shutdown

How to install Spring boot app on Ubuntu server?

I have Ubuntu server on Digital Ocean and I wrote Spring web app and now I want to put it in production.
I upload it via FTP to the server and I open my console via Putty and I use this command:
java -jar name.jar
Spring is started after that and when I open my web app everything is working fine, but when I close my Putty session my Spring web app does not work anymore. It seems like when I close my Putty session that also Spring web app is closed.
How to solve this?
While what KLHauser suggested will work, but if the vm is restarted in the cloud (which happens) your application will not automatically restart. Also stopping your application with kill -9 is error prone and dangerous, because you accidentally may kill the wrong process.
See running as Linux service section of Spring Boot documentation on how to do that.
If you’ve configured Spring Boot’s Maven or Gradle plugin to generate
a fully executable jar, and you’re not using a custom
embeddedLaunchScript, then your application can be used as an init.d
service. Simply symlink the jar to init.d to support the standard
start, stop, restart and status commands.
The script supports the following features:
Starts the services as the user that owns the jar file
Tracks
application’s PID using /var/run//.pid
Writes
console logs to /var/log/.log
Assuming that you have a Spring Boot application installed in
/var/myapp, to install a Spring Boot application as an init.d service
simply create a symlink:
$ sudo ln -s /var/myapp/myapp.jar /etc/init.d/myapp Once installed,
you can start and stop the service in the usual way. For example, on a
Debian based system:
$ service myapp start
Just use java -jar name.jar & and the application is started in new process thread.
by adding also > log.txt directly at the end you would also have a log.

Start ruby app as service on CentOS 7

I have a ruby script (actually an example script from the Oxidized project), which is written in Ruby and opens a UDP port (514) listening for syslog messages and executing some code in the background.
The system runs on CentOS 7. I want to start this script as "service" automatically when the OS boots. The script however needs to run as a specific user (oxidized) and should be controllable using normal "service ... [start|stop|status|...|" behaviour. What would be the best way to achieve this?
Startup services can be managed by 2 different boot systems.
CentOS6 uses System V (Old Boot System)
CentOS7 uses Systemd (New Boot System) (Systemd does support System V scripts.)
Here is a link "How to write startup script for systemd"
https://unix.stackexchange.com/questions/47695/how-to-write-startup-script-for-systemd
Here is a link "How to write a System V init script to start, stop, and restart my own application or service"
https://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html

Resources