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

相关推荐
徐子元竟然被占了!!6 小时前
Linux-systemctl
linux·数据库·oracle
_w_z_j_9 小时前
Linux----mmap
linux
程序员zgh10 小时前
Linux系统常用命令集合
linux·运维·服务器·c语言·开发语言·c++
Bigan(安)10 小时前
【奶茶Beta专项】【LVGL9.4源码分析】09-core-obj_class对象类系统
linux·c语言·mcu·arm·unix
紫郢剑侠10 小时前
飞秋@Windows +iptux@Linux,打造内网跨平台IM环境
linux·运维·服务器·im·qq
保持低旋律节奏10 小时前
linux——调试
linux·运维·服务器
牛奶咖啡1310 小时前
Linux系统故障排查思路实践教程(下)
linux·运维·服务器·su命令切换用户问题解决·文件打开过多问题解决·linux网络故障问题解决·linux故障排查思路
coder4_11 小时前
Linux 数据同步全攻略:NFS 共享、inotify+rsync 与 sersync 实战指南
linux·rsync·文件共享·nfs·数据同步·inotify·实时备份
SEO-狼术11 小时前
FastReport .NET Mono 2026
.net