在linux上裸奔kestrel時,遇到一個問題.
遠程連接到linux,啟動kestrel服務器,退出遠程后,這個kestrel也關閉了
這時,要以服務的方式啟動程序
實驗環境:
ubuntu 20.04 LTS
systemd
具體是使用systemd這個linux系統管理工具實現的.
systemd介紹文檔 http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html
示例文檔: https://www.raspberrypi.org/documentation/linux/usage/systemd.md
配置文件字段解說: https://www.freedesktop.org/software/systemd/man/systemd.unit.html
總的來說,就是給程序加個配置文件,就可以用systemctl start 服務名字 這個命令以服務方式啟動程序.
配置文件可以如下
[Unit] Description=my httpserver [Service] ExecStart=/home/myhttp/myhttpserver.exe
注意: = 兩邊不要空格(我沒有驗證)
黃色部分是自己填寫的,Description是程序說明,ExecStart這個就是程序的啟動路徑
配置文件好了以后,取一個名字: myhttpserver.service,放到這個目錄
/usr/lib/systemd/system
配置文件的名字就是服務名字,.service擴展命是固定的(我沒有驗證)
最后,使用命令啟動程序
systemctl start myhttpserver
