> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/vi.-deploying-spring-boot-applications/61.-installing-spring-boot-applications/61.2-unix-and-linux-services/61.2.2-installation-as-a-systemd-service.md).

# 61.2.2 安装为Systemd服务

`systemd`是System V init系统的继任者，很多现代Linux分发版本都在使用。尽管你可以继续使用`init.d`脚本，但使用`systemd` ‘service’脚本启动Spring Boot应用是有可能的。

假设你在`/var/myapp`目录下安装一个Spring Boot应用，为了将它安装为一个`systemd`服务，你需要按照以下示例创建一个脚本，比如命名为`myapp.service`，然后将它放到`/etc/systemd/system`目录下：

```
[Unit]
Description=myapp
After=syslog.target

[Service]
User=myapp
ExecStart=/var/myapp/myapp.jar
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target
```

**提示** 记得根据你的应用改变`Description`，`User`和`ExecStart`字段。

**提示** 注意`ExecStart`字段没有声明脚本行动命令，也就是说会使用默认的`run`命令。

注意跟作为`init.d`服务运行不同，使用`systemd`这种方式运行应用，PID文件和控制台日志文件是由系统自己进行管理的，因此必须在‘service’脚本配置正确的字段，具体参考[service unit configuration man page](https://www.freedesktop.org/software/systemd/man/systemd.service.html)。

使用以下命令标识应用自动在系统boot上启动：

```
$ systemctl enable myapp.service
```

具体详情可参考`man systemctl`。
