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

相关推荐
VirusVIP2 小时前
Windows CMD通过adb检查触摸屏Linux驱动是否被编译
linux·运维·adb
chennalC#c.h.JA Ptho2 小时前
ubuntu studio 系统详解
linux·运维·服务器·经验分享·ubuntu·系统安全
Vone_668 小时前
node.js 邮箱验证服务器搭建
运维·服务器·node.js
丢丢丢丢丢丢~9 小时前
apache2的默认html修改
linux·运维·服务器
wusam9 小时前
Linux系统管理与编程20:Apache
linux·运维·服务器·apache·shell编程
我不想当小卡拉米9 小时前
【Linux】操作系统入门:冯诺依曼体系结构
linux·开发语言·网络·c++
ChironW9 小时前
Ubuntu 24.04 LTS系统上配置国内时间同步
linux·运维·服务器·ubuntu
TPBoreas9 小时前
排查服务器内存空间预警思路
运维·服务器
yayaer210 小时前
GOOSE 协议中MAC配置
服务器·网络·goose
苏生要努力10 小时前
第九届御网杯网络安全大赛初赛WP
linux·python·网络安全