亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ExecStart 在 Golang webapp 的 systemd 服務中失敗

ExecStart 在 Golang webapp 的 systemd 服務中失敗

Go
楊魅力 2022-12-19 11:47:03
我是 golang 的新手,正在嘗試在我的服務器上托管一個簡單的網站。我在 Ubuntu 18.04我的域根目錄在/var/www/vhosts/mydomain.com/mydomain.com我有一個main.go文件,它在瀏覽器中呈現一個簡單的 Hello World。當我go run main.go離開這個目錄時,網頁工作正?!,F在我正在嘗試創建一項服務,以便在我關閉我的shell.為此,我創建了一個新service的golangweb.serviceat /etc/systemd/system。該文件的內容是:[Unit]Description = Go Server[Service]ExecStart=/var/www/vhosts/mydomain.com/mydomain.comType=simpleRestart=alwaysRestartSec=5[Install]WantedBy=multi-user.target保存文件后,我按順序插入以下命令:sudo systemctl daemon-reloadsudo systemctl enable golangweb.servicesudo systemctl start golangweb.servicesudo systemctl status golangweb.service當我嘗試獲取狀態時,出現以下錯誤(我在那里刪除了一些數據): golangweb.service - Go Server   Loaded: loaded (/etc/systemd/system/golangweb.service; enabled; vendor preset: enabl   Active: activating (auto-restart) (Result: exit-code) since Fri xx-xx-xx 23:43:52  **Process: xx ExecStart=/var/www/vhosts/mydomain.com/mydomain.com (code=exited, sta Main PID: xx (code=exited, status=203/EXEC)**Mai xx xx:xx:xx xxxxx.xxxx.xxxx.systemd[1]: golangweb.service: Failed with reWarning: Journal has been rotated since unit was started. Log output is incomplete or ulines 1-8/8 (END)● golangweb.service - Go Server   Loaded: loaded (/etc/systemd/system/golangweb.service; enabled; vendor preset: enabled)   Active: activating (auto-restart) (Result: exit-code) since Fri xx-xx-xx xx:xx:xx CEST; 3s ago  Process: xx ExecStart=/var/www/vhosts/mydomain.com/mydomain.com (code=exited, status=203/EXEC) Main PID: xx (code=exited, status=203/EXEC)Mai xx xx:xx:xx xxxx.xx.xx xx[1]: golangweb.service: Failed with result 'exit-code'.Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.有人知道為什么會這樣嗎?
查看完整描述

1 回答

?
慕虎7371278

TA貢獻1802條經驗 獲得超4個贊

第一個參數ExecStart需要是一個可執行文件??雌饋砟阋呀泴⑺O置為一個目錄。如果您嘗試/var/www/vhosts/mydomain.com/mydomain.com在 shell 提示符下鍵入,您會看到類似的行為:您無法運行目錄。

可以設置:

WorkingDirectory=/var/www/vhosts/mydomain.com/mydomain.com
ExecStart=/usr/bin/go run main.go

或者,您可以編譯代碼 ( go build),然后設置ExecStart為已編譯二進制文件的完整路徑:

ExecStart=/var/www/vhosts/mydomain.com/mydomain.com/compiledprogramname


查看完整回答
反對 回復 2022-12-19
  • 1 回答
  • 0 關注
  • 338 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號