spring boot 配置成Linux服务
Create the log directory
sudo mkdir /var/log/hello
application-alpha.yml
logging:
path: /var/log/hello/
pom.xml
<build>
<finalName>hello-world</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
mvn clean install
sudo mv hello-world.jar /var/app/hello/
hello-world.service
[Unit]
Description=hello-world project for spring boot
After=syslog.target
[Service]
User=root
ExecStart=/var/app/hello/hello-world.jar --spring.profiles.active=alpha
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
ln -s /var/app/hello/hello-world.service /etc/systemd/system/hello-world.service
sevice manager
start service
sudo systemctl start hello-world
echo service status
sudo systemctl status hello-world
stop service
sudo systemctl stop hello-world
enable start on boot
sudo systemctl enable hello-world
disable start on boot
sudo systemctl disable hello-world