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

相关推荐
九皇叔叔26 分钟前
Linux Shell 中的 $():命令替换的核心用法
linux·运维·chrome
半桔1 小时前
【网络编程】详解 IP 协议:报头字段、路由器功能、网段划分和分片传输
linux·网络·网络协议·tcp/ip
大聪明-PLUS1 小时前
TCP/IP 协议族—理论与实践(二)
linux·嵌入式·arm·smarc
liulilittle1 小时前
Linux内核网络优化:两个网络调优解决方案
linux·运维·服务器·网络·内核·信息与通信·通信
hweiyu001 小时前
Linux运维实战:系统及服务管理(视频教程)
linux·运维·服务器
风随心飞飞1 小时前
linux 环境下mysql 数据库自动备份和清库 通过crontab 创建定时任务实现mysql数据库备份
linux·数据库·mysql
止观止1 小时前
VS Code 二次开发:跨平台图标定制全攻略
linux·windows·vscode·macos
九皇叔叔2 小时前
Windows用Notepad++编辑Shell脚本:一招解决Linux执行报错问题
linux·windows·notepad++
@LetsTGBot搜索引擎机器人2 小时前
用 Python 打造一个 Telegram 二手交易商城机器人
开发语言·python·搜索引擎·机器人·.net·facebook·twitter
福如意如我心意2 小时前
ubuntu服务器重启,xinference自动加载模型脚本
服务器·ubuntu·ai