将.net core 控制台程序注册成为Linux服务

时间:2020-06-11 22:52   作者:ChenReal    阅读:166

应用弄好了,怎么部署到LINUX服务器上让它以一个服务的形式跑起来呢?下面我来详细说说。

  • 首先,当然是upload到服务器并解压
  • 然后,生成一个systemctl配置脚本

sudo touch /etc/systemd/system/hostdemo.service

写入配置信息如下:

[Unit]
Description=Generic Host Demo

[Service]
#应用根目录
WorkingDirectory=/var/service/hostdemo
#执行脚本
ExecStart=/usr/bin/dotnet /var/service/hostdemo/HostService.dll --environment Production
KillSignal=SIGINT
#服务日至标识
SyslogIdentifier=host-demo-service

[Install]
WantedBy=multi-user.target
  • 最后,启动服务
#启动服务
systemctl start hostdemo.service

#设置开机启动服务
systemctl enable hostdemo.service

#取消开机启动服务
systemctl disenable hostdemo.service

#重启服务
systemctl restart hostdemo.service 

#关闭服务
systemctl stop hostdemo.service

#查看服务运行状态
systemctl status hostdemo.service

嗯,就是这么简单~

 

评论
0/200