linux 创建自启动服务

话不多说直接上干货:

1. 创建service服务描述文件

下面描述一个netcore 网站的自启动服务,可执行文件目录:/www/xxx/xxxsite.dll,启动端口10000为 设置环境变量: Environment=ASPNETCORE_ENVIRONMENT=Production 保存文件名称:xxx-site.service

[Unit]
Description=xxxsite
[Service]
WorkingDirectory= /www/xxx
Type=simple
User=root
Group=root
ExecStart=/usr/bin/dotnet /www/xxx/xxxsite.dll --urls http://+:10000
Restart=always

# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
SyslogIdentifier=xxxsite
Environment=ASPNETCORE_ENVIRONMENT=Production

[Install] 
WantedBy=multi-user.target

2. 将文件拷贝到 /etc/systemd/system/xxx-site.service

然后通过bash命令进行操作

systemctl daemon-reload
systemctl start xxx-site.service

当然你如果不想把创建好的xxx-site.service 文件拷贝到系统目录中 /etc/systemd/system/xxx-site.service,可以通过如下命令,建立系统软连接进行操作:

systemctl enable xxx-site.service
systemctl disable xxx-site.service

系统的其他操作如下:

systemctl status xxx-site.service
systemctl stop xxx-site.service
systemctl restart xxx-site.service
systemctl reload xxx-site.service
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章