簡體   English   中英

linux 上的 powercli 腳本無法作為 systemctl 服務運行

[英]powercli script on linux is failing to run as systemctl service

我正在嘗試創建一個 powercli 腳本 (ps1) 作為 systemctl 服務在 linux 上運行。 使用 pwsh 運行時腳本運行良好。 但是,當我將它變成一項服務時,它會失敗,就好像無法識別我在腳本中使用的 pwsh 命令一樣。

[Unit]
Description=test
After=network-online.target

[Service]
user=root
ExecStart=/usr/bin/pwsh /build/test/test.ps1

[Install]
WantedBy=multi-user.target

我在 journalctl 中看到的錯誤:

Connect-VIServer: /build/test.ps1:7
Line |
7 |  Connect-VIServer -Server $vc
|  ~~~~~~~~~~~~~~~~
| The term 'Connect-VIServer' is not recognized as a name of a
| cmdlet, function, script file, or executable program. Check
| the spelling of the name, or if a path was included, verify
| that the path is correct and try again.
get-vm: /build/self_healing/start_network_adapter.ps1:9
Line |
9 |  get-vm $node | get-networkadapter | where {$_.connectionstate.connect …
|  ~~~~~~
| The term 'get-vm' is not recognized as a name of a cmdlet,
| function, script file, or executable program. Check the
| spelling of the name, or if a path was included, verify that
| the path is correct and try again.
(7.2.4:A:80) [NamedPipeIPC_ServerListenerError:NamedPipe.Exception.Error] An error has occurred in PowerShell IPC listening thread on process: 61158 in AppDomain: None.  Error Message: Operation canceled.

為什么這個 pwsh 腳本可以正常運行,但作為 systemctl 服務執行時卻失敗了?

我設法解決它。 顯然,問題出在這一行:服務定義文件中的user=root user應該大寫: User 所以它沒有以 root 身份運行它,因此無法訪問模塊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM