简体   繁体   中英

Start java application after a crash or server restart

I have a few Java applications, mostly with Spring Boot, in different servers (Droplets) from Digital Ocean. Previously I upload each new release manually and with some shell scripts created I am able to start/stop the applications. These scripts contains environment variables when it's necessary for test or production environments. To check if the application is running I have a cronjob launched every 5 minutes, this cronjob execute a shell script to start the application if it's not running.

However I switched to automatic deployments using Bitbucket pipelines and now I won't have shell scripts anymore because all the configuration will provided by the Bitbucket pipeline and will be executed over SSH.

For instance cat environment.sh start.sh | ssh xxx@yyy cat environment.sh start.sh | ssh xxx@yyy where environment.sh is created on the fly by the pipeline with right configuration in that moment for each environment.

How can I do something to start the application automatically if it's not running? Should I upload the script files in each automatic deployment and use a cronjob?

You should use a wrapper. YAJSW is popular, free and works (in my experience) well in production systems. The wrapper will restart your process if it crashes and can easily be installed as a service over many different OSes without much effort.

NOTE: I am not affiliated or related in any way to YAJSW.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM