Systemd

Systemd

创建服务

vim /etc/systemd/system/nginx.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

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

[Install]
WantedBy=multi-user.target

初始化时自动启动服务

1
ln -s /lib/systemd/system/nginx.service  /etc/systemd/system/multi-user.target.wants/nginx.service

或者

1
systemctl enable nginx

刷新配置

1
systemctl daemon-reload

启动、重启、停止

  1. 启动nginx

    1
    $ systemctl start nginx
  2. 重启nginx

    1
    $ systemctl restart nginx
  3. 停止nginx

    1
    $ systemctl stop nginx

开机启动

1
systemctl enable nginx

查看状态

1
systemctl status nginx

参考

本站采用「署名 4.0 国际」进行许可。