"Problem description"
Due to the recent use of the Spring Eureka Registry Service, and the office every night to power down, every morning after the need to manually start the Eureka service is very troublesome.
Need to implement: power on the function of the service automatically.
"Thinking Analysis"
The service command of the Linux system can be used to realize the start of the service + auto-start with the chkconfig command;
Specific ideas:
1) Write a shell script that launches the Eureka service and place it in the /etc/init.d directory;
2) Then, with service + script name + start to run;
3) Finally, use the Chkconfig command to add the service to the boot-up service list.
"Solutions"
1. Create a shell script file (named Eureka) in the /etc/init.d directory;
1) Enter the directory and execute the Touch Eureka command to create the file;
2) Then, use the VI command to open the file and add the following content:
The contents of the script are as follows:
# The program must start with the following line (must be placed in the first line of the file):
#!/bin/bash
# symbol #! Used to tell the Linux system that the parameters behind it are the programs used to execute the file. In this example we use/BIN/SH to execute the program.
# chkconfig:2345 10 90
# Description:eureka Service ...
Start () {
echo "-----------ready to start the Eureka service----------"
# Enter the installation directory to Eureka:
cd/opt/eureka/
# Set the Java environment variables for the Linux system:
Export java_home=/usr/lib/jvm/jdk1.8
Export path= $JAVA _home/bin: $PATH
Export classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar
# Start the Eureka service in the background:
nohup Java-jar Com.xxxx-xxx-xxxxxx-0.0.1-snapshot.jar &
echo "-----------Finish starting the Eureka service------------"
}
Case $ in
Start):
Start
;;
Stop):
echo "--------------------stop ...-------------------"
;;
Esac
Exit 0
2. Execute under the /etc/init.d directory:service Eureka start command, verify that the script can execute normally;
3. Use the ps-ef|grep java command to see if the Eureka service is started: If you discover the jar package process that you have published, the description succeeds.
4. Use the chkconfig command to add the service to the boot auto-start list, as long as you start it can self-start, restart after the permanent effect is:
Chkconfig--add Eureka #把服务加到开机自动启动列表里
chkconfig Eureka on # permanently active after reboot
How to implement on Linux: Eureka service boot-up?