简体   繁体   English

崩溃或服务器重启后启动Java应用程序

[英]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. 我在Digital Ocean的不同服务器(Droplets)中有一些Java应用程序,主要是Spring Boot。 Previously I upload each new release manually and with some shell scripts created I am able to start/stop the applications. 以前,我手动上载每个新发行版,并创建了一些Shell脚本后就可以启动/停止应用程序。 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. 为了检查应用程序是否正在运行,我每5分钟启动一次cronjob,如果该应用程序未运行,则该cronjob执行一个shell脚本来启动该应用程序。

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. 但是,我切换到使用Bitbucket管道的自动部署,现在不再拥有Shell脚本,因为所有配置将由Bitbucket管道提供,并且将通过SSH执行。

For instance cat environment.sh start.sh | ssh xxx@yyy 例如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. cat environment.sh start.sh | ssh xxx@yyy ,其中environment.sh是在那一刻,每个环境权配置管线动态创建。

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? 我应该在每个自动部署中上载脚本文件并使用cronjob吗?

You should use a wrapper. 您应该使用包装器。 YAJSW is popular, free and works (in my experience) well in production systems. YAJSW非常流行,免费,并且在生产系统中(以我的经验)效果很好。 The wrapper will restart your process if it crashes and can easily be installed as a service over many different OSes without much effort. 如果包装程序崩溃,它将重新启动您的进程,并且可以很容易地将其作为服务安装在许多不同的OS上。

NOTE: I am not affiliated or related in any way to YAJSW. 注意:我与YAJSW没有任何关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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