Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW

How to restart Central and Rim node of Sense with Powershell

No ratings
cancel
Showing results for 
Search instead for 
Did you mean: 
Sebastian_Linser

How to restart Central and Rim node of Sense with Powershell

Last Update:

Oct 27, 2021 8:15:07 AM

Updated By:

Sonja_Bauernfeind

Created date:

May 22, 2018 9:50:22 AM

Attachments

The script provided in this article is an example of how to build a PowerShell script that stops and starts Qlik Sense Enterprise on Windows. 

In our example, we assume that:

  • We want the output of this file to be written to C:\Scripts\ServiceOutput.csv
  • The central node is called Qlikserver1.domain.local
  • The rim node is called Qlikserver2.domain.local

You will need to modify these values to match your environment. 

 

The information in this article is provided as-is and to be used at own discretion. Depending on tool(s) used, customization(s), and/or other factors ongoing support on the solution below may not be provided by Qlik Support.

 

#provided as is, no support from QLIK on the script
#use at your own risk.

#startuporder according to
#https://help.qlik.com/en-US/sense-admin/August2021/Subsystems/DeployAdministerQSE/Content/Sense_DeployAdminister/QSEoW/Deploy_QSEoW/Services.htm
#file for documentation
$OutputFile = New-Item -type file -force "C:\Scripts\ServiceOutput.csv"
#get credentials of the service user
$Cred = Get-Credential
#name of the rimnode
$RimNodeName="Qlikserver2.domain.local"
#name of the central node
$CentralNodeName="Qlikserver1.domain.local"


Function pause ($message)
{
    # Check if running Powershell ISE
    if ($psISE)
    {
        Add-Type -AssemblyName System.Windows.Forms
        [System.Windows.Forms.MessageBox]::Show("$message")
    }
    else
    {
        Write-Host "$message" -ForegroundColor Yellow
        $x = $host.ui.RawUI.ReadKey("NoEcho,IncludeKeyDown")
    }
}
 
function StopServiceSense
 {
  param(
    [Parameter(Mandatory=$true, ValueFromPipeline=$true)]
    [string]
    $service,
    [string]
    $pcname,
    [System.Management.Automation.PSCredential]$Credential
   
  )
     write-host "$pcname -> trying to stop $service"
     $result = (gwmi win32_service -ComputerName $pcname -filter "name='$service'" -Credential $Credential).stopservice()
        If ($result.ReturnValue -eq "0") 
        {
            write-host "$pcname -> Service Stopped Successfully"
            "$pcname -> Service $service Stopped Successfully" | Out-File $OutputFile -encoding ASCII -append
            #$result.ReturnValue info: http://msdn.microsoft.com/en-us/library/aa393673(v=vs.85).aspx
        }
        else
        {
           #second attemp to stop if another service needed longer to drop
           
           DO
           {
              $result = (gwmi win32_service -ComputerName $pcname -filter "name='$service'" -Credential $Credential).stopservice()
              Start-Sleep -s 30 
              write-host "another attemp"
            } While ($result.ReturnValue -ne "0")
           
              "$pcname -> Service $service Stopped Successfully" | Out-File $OutputFile -encoding ASCII -append
           
        }
 }
 function StartServiceSense
 {
  param(
    [Parameter(Mandatory=$true, ValueFromPipeline=$true)]
    [string]
    $service,
    [string]
    $pcname,
    [System.Management.Automation.PSCredential]$Credential
   
  )
    write-host "$pcname -> trying to start $service"
  
    $result = (gwmi win32_service -ComputerName $pcname -filter "name='$service'" -Credential $Credential).startservice()
    Start-Sleep -s 20
        If ($result.ReturnValue -eq "0") 
        {
            write-host "$pcname -> Service Started Successfully"
            "$pcname -> Service $service Started Successfully" | Out-File $OutputFile -encoding ASCII -append
            #$result.ReturnValue info: http://msdn.microsoft.com/en-us/library/aa393673(v=vs.85).aspx
        }
 }

write-host "$RimNodeName -> Get overview of all Qlik Services"
Get-Service -ComputerName $RimNodeName -Name QlikLoggingService
Get-Service -ComputerName $RimNodeName -Name QlikSenseEngineService
Get-Service -ComputerName $RimNodeName -Name QlikSensePrintingService
Get-Service -ComputerName $RimNodeName -Name QlikSenseProxyService
Get-Service -ComputerName $RimNodeName -Name QlikSenseSchedulerService
Get-Service -ComputerName $RimNodeName -Name QlikSenseServiceDispatcher
Get-Service -ComputerName $RimNodeName -Name QlikSenseRepositoryService
write-host "$RimNodeName -> stopping all Qlik Services"
StopServiceSense -service "QlikLoggingService" -pcname $RimNodeName -Credential $cred
StopServiceSense -service "QlikSenseEngineService" -pcname $RimNodeName -Credential $cred 
StopServiceSense -service "QlikSensePrintingService" -pcname $RimNodeName -Credential $cred 
StopServiceSense -service "QlikSenseSchedulerService" -pcname $RimNodeName -Credential $cred 
StopServiceSense -service "QlikSenseProxyService" -pcname $RimNodeName -Credential $cred 
StopServiceSense -service "QlikSenseRepositoryService" -pcname $RimNodeName -Credential $cred 
StopServiceSense -service "QlikSenseServiceDispatcher" -pcname $RimNodeName -Credential $cred 

write-host "$CentralNodeName -> Get overview of all Qlik Services"
Get-Service  -ComputerName $CentralNodeName -Name QlikLoggingService
Get-Service  -ComputerName $CentralNodeName -Name QlikSenseEngineService
Get-Service  -ComputerName $CentralNodeName -Name QlikSensePrintingService
Get-Service  -ComputerName $CentralNodeName -Name QlikSenseProxyService
Get-Service  -ComputerName $CentralNodeName -Name QlikSenseSchedulerService
Get-Service  -ComputerName $CentralNodeName -Name QlikSenseServiceDispatcher
Get-Service  -ComputerName $CentralNodeName -Name QlikSenseRepositoryService
Get-Service  -ComputerName $CentralNodeName -Name QlikSenseRepositoryDatabase
write-host "$CentralNodeName -> stopping all Qlik Services"
StopServiceSense -service "QlikLoggingService" -pcname $CentralNodeName -Credential $cred
StopServiceSense -service "QlikSenseEngineService" -pcname $CentralNodeName -Credential $cred
StopServiceSense -service "QlikSensePrintingService" -pcname $CentralNodeName -Credential $cred
StopServiceSense -service "QlikSenseProxyService" -pcname $CentralNodeName -Credential $cred
StopServiceSense -service "QlikSenseSchedulerService" -pcname $CentralNodeName -Credential $cred
StopServiceSense -service "QlikSenseRepositoryService" -pcname $CentralNodeName -Credential $cred
StopServiceSense -service "QlikSenseServiceDispatcher" -pcname $CentralNodeName -Credential $cred
StopServiceSense -service "QlikSenseRepositoryDatabase" -pcname $CentralNodeName -Credential $cred

##
pause "press a key to continue, sense is now down"
## do what you need to do/ patching etc
##
write-host "$CentralNodeName -> Get overview of all Qlik Services"
Get-Service  -ComputerName $CentralNodeName -Name QlikLoggingService
Get-Service  -ComputerName $CentralNodeName -Name QlikSenseEngineService
Get-Service  -ComputerName $CentralNodeName -Name QlikSensePrintingService
Get-Service  -ComputerName $CentralNodeName -Name QlikSenseProxyService
Get-Service  -ComputerName $CentralNodeName -Name QlikSenseSchedulerService
Get-Service  -ComputerName $CentralNodeName -Name QlikSenseServiceDispatcher
Get-Service  -ComputerName $CentralNodeName -Name QlikSenseRepositoryService
Get-Service  -ComputerName $CentralNodeName -Name QlikSenseRepositoryDatabase
write-host "$CentralNodeName -> Start all Qlik Services"
StartServiceSense -service "QlikSenseRepositoryDatabase" -pcname $CentralNodeName -Credential $cred
StartServiceSense -service "QlikLoggingService" -pcname $CentralNodeName -Credential $cred
StartServiceSense -service "QlikSenseServiceDispatcher" -pcname $CentralNodeName -Credential $cred
StartServiceSense -service "QlikSenseRepositoryService" -pcname $CentralNodeName -Credential $cred
StartServiceSense -service "QlikSenseEngineService" -pcname $CentralNodeName -Credential $cred
StartServiceSense -service "QlikSensePrintingService" -pcname $CentralNodeName -Credential $cred
StartServiceSense -service "QlikSenseProxyService" -pcname $CentralNodeName -Credential $cred
StartServiceSense -service "QlikSenseSchedulerService" -pcname $CentralNodeName -Credential $cred


write-host "$CentralNodeName -> Get overview of all Qlik Services"
Get-Service  -ComputerName $CentralNodeName -Name QlikLoggingService
Get-Service  -ComputerName $CentralNodeName -Name QlikSenseEngineService
Get-Service  -ComputerName $CentralNodeName -Name QlikSensePrintingService
Get-Service  -ComputerName $CentralNodeName -Name QlikSenseProxyService
Get-Service  -ComputerName $CentralNodeName -Name QlikSenseSchedulerService
Get-Service  -ComputerName $CentralNodeName -Name QlikSenseServiceDispatcher
Get-Service  -ComputerName $CentralNodeName -Name QlikSenseRepositoryService
Get-Service  -ComputerName $CentralNodeName -Name QlikSenseRepositoryDatabase
write-host "$RimNodeName -> Get overview of all Qlik Services"
Get-Service  -ComputerName $RimNodeName -Name QlikLoggingService
Get-Service  -ComputerName $RimNodeName -Name QlikSenseEngineService
Get-Service  -ComputerName $RimNodeName -Name QlikSensePrintingService
Get-Service  -ComputerName $RimNodeName -Name QlikSenseProxyService
Get-Service  -ComputerName $RimNodeName -Name QlikSenseSchedulerService
Get-Service  -ComputerName $RimNodeName -Name QlikSenseServiceDispatcher
Get-Service  -ComputerName $RimNodeName -Name QlikSenseRepositoryService
write-host "$RimNodeName -> Start all Qlik Services"
StartServiceSense -service "QlikSenseServiceDispatcher" -pcname $RimNodeName -Credential $cred 
StartServiceSense -service "QlikLoggingService" -pcname $RimNodeName -Credential $cred
StartServiceSense -service "QlikSenseRepositoryService" -pcname $RimNodeName -Credential $cred 
StartServiceSense -service "QlikSenseEngineService" -pcname $RimNodeName -Credential $cred 
StartServiceSense -service "QlikSenseProxyService" -pcname $RimNodeName -Credential $cred 
StartServiceSense -service "QlikSensePrintingService" -pcname $RimNodeName -Credential $cred 
StartServiceSense -service "QlikSenseSchedulerService" -pcname $RimNodeName -Credential $cred 

write-host "$RimNodeName -> Get overview of all Qlik Services"
Get-Service  -ComputerName $RimNodeName -Name QlikLoggingService
Get-Service  -ComputerName $RimNodeName -Name QlikSenseEngineService
Get-Service  -ComputerName $RimNodeName -Name QlikSensePrintingService
Get-Service  -ComputerName $RimNodeName -Name QlikSenseProxyService
Get-Service  -ComputerName $RimNodeName -Name QlikSenseSchedulerService
Get-Service  -ComputerName $RimNodeName -Name QlikSenseServiceDispatcher
Get-Service  -ComputerName $RimNodeName -Name QlikSenseRepositoryService
pause "press a key to continue, sense is now up"

 

 

 

Labels (1)
Comments
jpjust
Specialist
Specialist

Hi Sebastian - Thank you for the script. I see you have posted this back in 2018, is this still valid?

Also, an additional question would be, how to avoid 

pause "press a key to continue, sense is now down"

I want to have this fully automated from stop to start and then send out an email to few people notifying that the stop / start is completed.

Thanks

Sebastian_Linser

@jpjust 

Hello, i had a look at my script and it need some minor adjustments basically making sure the QlikSenseServiceDispatcher Service is the first on RimNode and 2nd on Central node to start.

 

The pause line was just to give you the time to manually push the updates. 

You can simply comment it out with a HashTag (#) in front. If you wanted to fully automate the process you want to break down the script in two parts, a stop script and a start script.

I updated the attachment with the three versions mentioned, manual, start, stop. 

best regards

Sebastian

 

jpjust
Specialist
Specialist

Thanks Sebastian. 

Just curious how can I make use of the .7z attachment?

Sebastian_Linser

@jpjust  you just need to download the tool at https://www.7-zip.org/download.html

 

jpjust
Specialist
Specialist

Thanks Sebastien. I have an dev node as well in the cluster. I believe I can easily modify the script and add the dev node.

Is there a way that you can help me with adding the email part? As soon as the services are UP and running on al the 3 nodes, check and blast an email telling admins the services are UP.

Also, I can run this power shell on any one of the node using the windows task scheduler, correct?

Thanks

Sebastian_Linser

yes, you can the part with the Repository Database Service is for the Central node, the other without for the rim node so just copy  the most appropriate part from the script one time and adjust the server name.

You can also improve the script passing the server name as parameter with an additional switch for if its rim or central node. The Task Scheduler should be able to run the script as well.

Here the command for sending mails:

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/send-mailmessage?vie...

good examples in how to use it here, because I guess you have username and password on your SMTP:

https://stackoverflow.com/questions/12460950/how-to-pass-credentials-to-the-send-mailmessage-command...

best regards

Sebastian

jpjust
Specialist
Specialist

Thanks Sebastien, let me give it a try.

Since the start and stop script are separate, when should I run the start script? Should I give like 5 minutes time interval after I start the  stop script?

Thanks

Sebastian_Linser

If you want to push updates in between you want to wait until those are finished and then continue. So rather then setting a fixed time you want to watch how long your update script runs on all nodes once done on all nodes then starting all up again. You can of course always start up the central node after the upgrade on this one is done.  For a rim node you need to wait until the Database on the central node is back before starting  all up.  That is why I implemented  the pause switch in the initial script to wait for all to complete  and then proceed. There might also be reboots necessary at the end but that is another topic.

 

Regards Sebastian 

jpjust
Specialist
Specialist

Thanks Sebastian.

Version history
Last update:
‎2021-10-27 08:15 AM
Updated by: