ubuntu 新建 service

此心光明 / 2023-08-23 / 原文

1、
cd  /etc/systemd/system

 

 2、

vim rtgapi.service

 

 

[Unit]
Description=rtgapi

[Service]
WorkingDirectory=/home/rtgweb/api/
ExecStart=/usr/bin/dotnet /home/rtgweb/api/rtgapi.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=douyin and kuaishou
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=ASPNETCORE_URLS=http://0.0.0.0:8081       

[Install]
WantedBy=multi-user.target

 3、systemctl  服务管理

服务开启:
systemctl start rtgapi.service
状态:
systemctl status rtgapi.service

systemctl restart rtgapi.service

systemctl stop rtgapi.service

查看日志
journalctl -fu rtgapi.service