Linux 创建.NET 服务

文章目录

创建服务

  1. 将服务文件上传到 /home/mes/api-mes-dev, 其他服务修改对应的目录

  2. 在 /usr/lib/systemd/system/ 创建 mesapi-dev.service, 其他服务修改对应文件名

    [Unit]
    Description=mesapi-dev service

    [Service]
    WorkingDirectory=/home/mes/api-mes-dev
    ExecStart=/usr/bin/dotnet /home/mes/api-mes-dev/WebApi.dll --urls "http://*:10300"
    Restart=always

    Restart service after 10 seconds if the dotnet service crashes:

    RestartSec=10
    KillSignal=SIGINT
    SyslogIdentifier=mesapi-dev
    User=root

    Development开发环境,Production生产环境

    Environment=ASPNETCORE_ENVIRONMENT=Production
    Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

    [Install]
    WantedBy=multi-user.target

启用服务

复制代码
systemctl enable mesapi.service

启动 & 重启服务

复制代码
systemctl start mesapi.service
systemctl restart mesapi.service

查看服务状态

复制代码
// 查看服务状态
systemctl status mesapi.service

// 查看端口占用
netstat -tnpl|grep 10300

问题排查

复制代码
// 直接使用命令启动
 /usr/bin/dotnet /home/mes/api-mes-dev/JZ.IMS.WebApi.dll --urls "http://*:10300"

访问: http://xxxxxx:10300 查看swagger

相关推荐
sunxunyong2 小时前
CGroup配置
linux·运维·服务器
hy____1232 小时前
Linux_网络编程套接字
linux·运维·网络
若风的雨2 小时前
【deepseek】 Linux 调度延时分析
linux
2301_803554523 小时前
linux 以及 c++编程里对于进程,线程的操作
linux·运维·c++
LuDvei3 小时前
windows 中 vs code远程连接linux
linux·运维·服务器·windows
生活爱好者!3 小时前
NAS帮我找回童年的快乐!部署 小游戏
运维·服务器·docker·容器·娱乐
GDAL3 小时前
MANIFEST.in简介
linux·服务器·前端·python
点点滴滴的记录4 小时前
Redis部署在Linux上性能高于Windows
linux·数据库·redis
蜕变的小白4 小时前
基于Linux的天气查询项目
linux·运维·服务器
卤炖阑尾炎4 小时前
Linux firewalld 防火墙从入门到精通:原理与配置全解析
linux·运维·php