Как автоматизировать сервис Java, чтобы запуститься, если сервер перезапускает

Я обычно выполняю свой сервис Java на использование поля CentOS nohup как ниже:

nohup java -jar myapp-0.0.1-SNAPSHOT.jar server my-configure.yml > outfile &

Однако, если перезапуски сервера сервис не перезапустят самостоятельно. Существует ли автоматизированный путь в CentOS для запуска этого сервиса Java при начальной загрузке?

-2
задан 15 February 2015 в 14:47
1 ответ

Скопируйте сценарий в /etc/rc.d/rc.local , перезагрузитесь, и он запустится при загрузке. Например,

[vagrant@localhost ~]$ cat /etc/rc.d/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

sudo touch /tmp/helloworld

создает файл / tmp / helloworld после перезагрузки системы:

[vagrant@localhost ~]$ ls /tmp/
helloworld 

30.3. Запуск дополнительных программ во время загрузки

The /etc/rc.d/rc.local script is executed by the init command at boot time or when changing runlevels. Adding commands to the bottom of this script is an easy way to perform necessary tasks like starting special services or initialize devices without writing complex initialization scripts in the /etc/rc.d/init.d/ directory and creating symbolic links.

The /etc/rc.serial script is used if serial ports must be setup at boot time. This script runs setserial commands to configure the system's serial ports. Refer to the setserial man page for more information. 
3
ответ дан 5 December 2019 в 21:12

Теги

Похожие вопросы