
私は通常、以下のようにして CentOS ボックス上で Java サービスを実行しますnohup
。
nohup java -jar myapp-0.0.1-SNAPSHOT.jar server my-configure.yml > outfile &
ただし、サーバーを再起動しても、サービスは自動的に再起動しません。 CentOS で起動時にこの Java サービスを自動的に開始する方法はありますか?
答え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/ハローワールドシステムを再起動すると次のファイルが作成されます:
[vagrant@localhost ~]$ ls /tmp/
helloworld
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.