简体   繁体   English

linux 上的 powercli 脚本无法作为 systemctl 服务运行

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

I'm trying to create a powercli script (ps1) to run on linux as a systemctl service.我正在尝试创建一个 powercli 脚本 (ps1) 作为 systemctl 服务在 linux 上运行。 The script is working fine when running with pwsh.使用 pwsh 运行时脚本运行良好。 But when I turn it into a service it fails as if not recognizing the pwsh commands that I'm using in the script.但是,当我将它变成一项服务时,它会失败,就好像无法识别我在脚本中使用的 pwsh 命令一样。

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

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

[Install]
WantedBy=multi-user.target

The error I see in journalctl:我在 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.

Why does this pwsh script runs fine normally but fails when executed as a systemctl service?为什么这个 pwsh 脚本可以正常运行,但作为 systemctl 服务执行时却失败了?

I manage to solve it.我设法解决它。 Apparently, the issue was with this line: user=root in the service definition file.显然,问题出在这一行:服务定义文件中的user=root user should be with capital: User . user应该大写: User So it didn't run it as root and therefore couldn't access the modules.所以它没有以 root 身份运行它,因此无法访问模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM