1、创建nginx守护进程文件
①、vim /etc/systemd/system/nginx.service
②、添加配置
[Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx reload ExecStop=/usr/local/nginx/sbin/nginx quit PrivateTmp=true [Install] WantedBy=multi-user.target
③、设置开机自启
systemctl enable nginx.service
④、查看nginx运行状态
systemctl status nginx.service
⑤、启动服务
systemctl start nginx.service
⑥、停止服务
systemctl stop nginx.service
⑦、重启服务
system restart nginx.service
2、netcore 守护进程
①、创建进程服务
vim /etc/systemd/system/serviceName.service 【serviceName:服务名称】
②、编写配置
[Unit] Description=GreenUntiy.Fast.WebApi #服务描述,随便填就好 [Service] WorkingDirectory=/home/GreenUnity/Fast/ #工作目录,填你应用的绝对路径 ExecStart=/usr/bin/dotnet /home/GreenUnity/Fast/GreenUnity.Fast.WebAp.dll #启动:前半截是你dotnet的位置(一般都在这个位置),后半部分是你程序入口的dll,中间用空格隔开 Restart=always RestartSec=25 #如果服务出现问题会在25秒后重启,数值可自己设置 SyslogIdentifier=GreenUnity.Fast.WebApi #设置日志标识,此行可以没有 User=root #配置服务用户,越高越好 Environment=ASPNETCORE_ENVIRONMENT=Production [Install] WantedBy=multi-user.target
③、开启自启
systemctl enable serviceName.service
④、启动服务
systemctl start serviceName.service