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

相关推荐
camellias_10 分钟前
ubuntu(二)ubuntu18.04安装mysql8
linux·ubuntu·adb
藤谷性能11 分钟前
Ubuntu 22.04:安装串口调试助手CoolTerm
linux·运维·ubuntu·串口·coolterm
路溪非溪24 分钟前
如何使用sysfs来排查驱动问题
linux·arm开发·驱动开发
丶伯爵式28 分钟前
Ubuntu 新装后常用设置
linux·运维·ubuntu
@LuckY BoY28 分钟前
deepin 系统的导航栏或任务栏不见了
运维·服务器
哼?~30 分钟前
Socket编程准备
linux·网络
羌俊恩37 分钟前
Vim modeline 命令执行漏洞(CVE-2026-34714)修复指导
linux·编辑器·vim·漏洞·cve-2026-34714
wang09071 小时前
Linux性能优化之中断
linux·运维·性能优化
bukeyiwanshui1 小时前
20260410 系统启动原理
linux
huanmieyaoseng10031 小时前
Linux 安装配置 Tomcat超详细2026新(附安装包)
linux·运维·tomcat