繁体   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