Spring Boot uses Linux services to start, stop, and restart

1. First configure the plugin in pom.xml
<plugin>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-maven-plugin</artifactId>
     <configuration>
          <executable>true</executable>
     </configuration>
</plugin>


Pay special attention to <executable>true</executable>

2. Then use mvn clean package -Dmaven.test.skip=true normally to make the project into a jar package

3. Upload the jar package to the server, assuming the deployment path is /var/apps/ myapp.jar, use the command to make a soft link to the /etc/init.d directory, the command:
quote

ln -s /var/apps/myapp.jar /etc/init.d/myapp


The myapp at the end of /etc/init.d/myapp can be another name, this is the service name, we will use service [service name] start to start later (described below).

4. Grant executable permission to the jar file, command:
quote

chmod +x myapp.jar


5. Next, you can use the familiar service myapp start|stop|restart|status to start and stop the application.

After executing the command, you will get the result feedback in the form of Started|Stopped [PID].
Default PID file path: /var/run/appname/appname.pid
Default service log file path: /var/log/appname.log (LOG_FOLDER can be modified by the following .conf)

6. Use a custom .conf file to To change the default configuration, the method is as follows:
create a .conf file in the same path as the jar package, the name should be the same as the name of the .jar, such as myapp.conf (if the jar file we packaged is myapp-1.0.0.jar then here The conf file should also be myapp-1.0.0.conf), its content configuration can be as follows:
quote

JAVA_HOME=/usr/local/jdk
JAVA_OPTS=-Xmx1024M
LOG_FOLDER=/data/logs/myapp

Note: The folder directory corresponding to LOG_FOLDER must exist. If the directory does not exist, the service will not automatically create the directory.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326139515&siteId=291194637