以 nginx 为例

1. 保存文件到 /lib/systemd/system/nginx.service。

2. 文件内容:

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

3. 设置开机启动

systemctl enable nginx.service


php 环境包启动参考:

1,下载地址:

Debian: https://github.com/seffeng/xfdnmp

CentOS: https://github.com/seffeng/xfcnmp


2, service

sudo vi /usr/lib/systemd/system/websrv.service
[Unit]
Description=websrv
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/srv/websrv/config/start_websrv.sh
ExecReload=/srv/websrv/config/reload_websrv.sh
ExecStop=/srv/websrv/config/stop_websrv.sh
PrivateTmp=true

[Install]
WantedBy=multi-user.target


3、mysql

[Unit]
Description=MySQL Server
After=network.target syslog.target

[Service]
User=mysql
Group=mysql
Type=forking
PermissionsStartOnly=true
ExecStart=/usr/bin/mysqld --daemonize --user=mysql
TimeoutSec=600
Restart=always
PrivateTmp=false

[Install]
WantedBy=multi-user.target
Alias=mysqld.service