Highlighted
Enthusiast
Enthusiast

Need powercli script to stop smartd daemon service on morethan 50 ESXi6.0 hosts

Jump to solution

Issue Discription:

================

  • ESXi hosts appear as Not Responding in vCenter Server.
  • Running esxcli commands on the ESXi host fail with the error:

    Error interacting with configuration file /etc/vmware/lunTimestamps.log: Timeout while waiting for lock, /etc/vmware/lunTimestamps.log.LOCK, to be released. Another process has kept this file locked for more than 30 seconds. The process currently holding the lock is smartd(PID). This is likely a temporary condition. Please try your operation again.

    Note: PID is the process ID for the smartd service.

  • In the /var/log/hostd.log file, you see entries similar to:

    Error interacting with configuration file /etc/vmware/lunTimestamps.log: Timeout while waiting for lock, /etc/vmware/lunTimestamps.log.LOCK, to be released. Another process has kept this file locked for more than 30 seconds. The process currently holding the lock is smartd(PID). This is likely a temporary condition. Please try your operation again.

Workaround:

===========

Need to stop smartd daemon service on ESXi 6.0 host

0 Kudos
1 Solution

Accepted Solutions
Highlighted
User Moderator
User Moderator

You will need to use the plink.exe command from the PuTTY Suite

The script will check if the SSH service is running, if not, it will start it, and also stop it after the smartd service has been stopped.

.

Something like this

$user = <user>

$pswd = <password>

$plink = "<PuTTY dir>\plink.exe"

$plinkoptions = " -batch -pw $pswd"

$cmd = 'etc/init.d/smartd stop'

$remoteCommand = '"' + $cmd + '"'

Get-VMHost | %{

    $ssh =Get-VMHostService -VMHost $_ | where{$_.Key -eq 'TSM-SSH'}

    if(!$ssh.Running){

        Start-VMHostService -HostService $ssh -Confirm:$false > $null

    }

   

    $command = $plink + " " + $plinkoptions + " " + $User + "@" + $_.Name + " " + $remoteCommand

   

    Invoke-Expression -command $command

   

    if(!$ssh.Running){

        Stop-VMHostService -HostService $ssh -Confirm:$false > $null

    }

}


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

View solution in original post

0 Kudos
4 Replies
Highlighted
User Moderator
User Moderator

You will need to use the plink.exe command from the PuTTY Suite

The script will check if the SSH service is running, if not, it will start it, and also stop it after the smartd service has been stopped.

.

Something like this

$user = <user>

$pswd = <password>

$plink = "<PuTTY dir>\plink.exe"

$plinkoptions = " -batch -pw $pswd"

$cmd = 'etc/init.d/smartd stop'

$remoteCommand = '"' + $cmd + '"'

Get-VMHost | %{

    $ssh =Get-VMHostService -VMHost $_ | where{$_.Key -eq 'TSM-SSH'}

    if(!$ssh.Running){

        Start-VMHostService -HostService $ssh -Confirm:$false > $null

    }

   

    $command = $plink + " " + $plinkoptions + " " + $User + "@" + $_.Name + " " + $remoteCommand

   

    Invoke-Expression -command $command

   

    if(!$ssh.Running){

        Stop-VMHostService -HostService $ssh -Confirm:$false > $null

    }

}


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

View solution in original post

0 Kudos
Highlighted
Enthusiast
Enthusiast

‌thanks a lot Luc for prompt respons. I'll execute below script and let u know the status.

POst this change wanna pull the host report in orderto make sure that   Smartd service status should be in stop. Could u pls help on this as well.

Thanks in Advance!!!

Best Regards,

SWamy Naveen.

0 Kudos
Highlighted
User Moderator
User Moderator

The smartd service is not included in the ones returned by Get-VMHostService, so you will have to use the plink.exe again.

Replace the command by

$cmd = 'etc/init.d/smartd status'


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

0 Kudos
Highlighted
Enthusiast
Enthusiast

Here's a script that logs in to your hosts in the specified cluster, disabled the smartd service and stops the service from starting again on next reboot (as per ESXi 6.0 host is disconnected from vCenter Server (2145106) | VMware KB)

Loosely based on LucD's script:

$user = 'yourlogin'
$pswd = 'yourpassword'

$cmd = 'etc/init.d/smartd stop'
$cmd2 = 'chkconfig smartd off'

Get-Cluster -Name yourclustername | Get-VMHost | %{

    $ssh =Get-VMHostService -VMHost $_ | where{$_.Key -eq 'TSM-SSH'}
    if(!$ssh.Running){
        Start-VMHostService -HostService $ssh -Confirm:$false > $null
    }

    Write-host "Running remote SSH commands on $($_.Name)." -ForegroundColor Yellow
    Echo Y | ./plink.exe $_.Name -pw $pswd -l $user $cmd
    Echo Y | ./plink.exe $_.Name -pw $pswd -l $user $cmd2

    if(!$ssh.Running){
        Stop-VMHostService -HostService $ssh -Confirm:$false > $null
    }
}

0 Kudos