So automatisieren Sie den Start eines Java-Dienstes bei einem Serverneustart

So automatisieren Sie den Start eines Java-Dienstes bei einem Serverneustart

Normalerweise führe ich meinen Java-Dienst auf einer CentOS-Box nohupwie folgt aus:

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

Wenn der Server jedoch neu gestartet wird, wird der Dienst nicht von selbst neu gestartet. Gibt es in CentOS eine automatisierte Möglichkeit, diesen Java-Dienst beim Booten zu starten?

Antwort1

Kopieren Sie das Skript nach /etc/rc.d/rc.local, starten Sie neu und es wird beim Booten ausgeführt. Beispiel:

[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

schafft die/tmp/halloweltDatei, nachdem das System neugestartet wurde:

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

30.3. Zusätzliche Programme beim Booten ausführen

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. 

verwandte Informationen