> ## Content Index
> Fetch the complete content index at: https://note.xdq.me/llms.txt
> Use this file to discover other available public pages before exploring further.

# systemd服务创建
- URL: https://note.xdq.me/systemdfu-wu-chuang-jian/
- Published: 2014-11-07T00:14:30.000Z
- Updated: 2026-10-03T03:09:28.000Z
- Author: xud6
- Tags: centos, linux, #Import 2026-10-03 02:45

在`/etc/systemd/system`中新建servicename.service文件。  
按以下模板填入内容

```
[Unit]
Description=servicedescription
After=network.target

[Service]
Type=simple
WorkingDirectory=/path/to/service
User=http
Group=http
ExecStart=/usr/bin/service(startscript)
ExecStop=/usr/bin/service(stopscript)
Restart=always
SyslogIdentifier=servicename

[Install]
WantedBy=multi-user.target

```

之后修改启动脚本/程序的selinux属性

```
semanage fcontext -a -t unconfined_exec_t -f f /path/to/service/script

```

然后执行

```
systemctl daemon-reload

```

进行刷新。

之后执行

```
systemctl start serversname.service

```

启动服务并使用

```
systemctl status serversname.service

```

却认服务正常运行  
最后启动开机自动启动

```
systemctl enable serversname.service

```