VMware Cloud Community
fborges555
Enthusiast
Enthusiast
Jump to solution

service-control --start --all

HI .

The only post in this regard I found was in 2018, with no resolution, has this been possible after all these years? restart all services in vcenter using powercli.

Thanks

 

 

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Since the VCSA has the VMware Tools running, you can use Invoke-VMSCcipt.
You just have to set some environment variables for service-control to run (it is a phyton script).

$vcsaName = 'vcsa'
$user = 'root'

$cmd = @'
export VMWARE_PYTHON_PATH=/usr/lib/vmware/site-packages
export VMWARE_LOG_DIR=/var/log
export VMWARE_DATA_DIR=/storage
export VMWARE_CFG_DIR=/etc/vmware
service-control --start --all
'@

$vm = Get-VM -Name $vcsaName
$viCred = Get-VICredentialStoreItem -Host $vm.Guest.HostName -User $user
$cred = New-Object -TypeName PSCredential -ArgumentList $user,(ConvertTo-SecureString -String $viCred.Password -AsPlainText -Force)

Invoke-VMScript -VM $vm -ScriptText $cmd -ScriptType bash -GuestCredential $cred


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

Since the VCSA has the VMware Tools running, you can use Invoke-VMSCcipt.
You just have to set some environment variables for service-control to run (it is a phyton script).

$vcsaName = 'vcsa'
$user = 'root'

$cmd = @'
export VMWARE_PYTHON_PATH=/usr/lib/vmware/site-packages
export VMWARE_LOG_DIR=/var/log
export VMWARE_DATA_DIR=/storage
export VMWARE_CFG_DIR=/etc/vmware
service-control --start --all
'@

$vm = Get-VM -Name $vcsaName
$viCred = Get-VICredentialStoreItem -Host $vm.Guest.HostName -User $user
$cred = New-Object -TypeName PSCredential -ArgumentList $user,(ConvertTo-SecureString -String $viCred.Password -AsPlainText -Force)

Invoke-VMScript -VM $vm -ScriptText $cmd -ScriptType bash -GuestCredential $cred


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
kwhornlcs
Enthusiast
Enthusiast
Jump to solution

VCSA service restarts is one of the new features of PowerCLI 12.5 I believe - PowerCLI 12.5 - What's New - VMware PowerCLI Blog

I haven't tested this myself yet - so test first or use at your own risk - but I imagine a restart all would go something like:

Connect-VIServer vcenterservername
Get-VIApplianceService -State Started  | Restart-VIApplianceService

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That cmdlet returns all services running on the VCSA, not just the once covered with service-control.
For example ntpd, sendmail, and 12 others are included.

You should have tested that cmdlet :winking_face:


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
kwhornlcs
Enthusiast
Enthusiast
Jump to solution

You're correct...I did put a caveat though :winking_face:

Interestingly, unless I'm mistaken, there are also some covered by service-control missing now that I'm doing a side-by-side (vpxd among them) - guess those cmdlets are still a WIP.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, indeed.
That's why I suggested the Invoke-VMScript solution :face_with_tears_of_joy:

And yes, you did put a caveat.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference