top of page

Stop Qlik Sense Services

Backup, Upgrade, and Recover Qlik Sense

Overview

In this lesson, you will learn how to write a script to stop Qlik Sense services in the right order. Here's the final version of the script that we will be creating.



We’ve done and learned a bunch of stuff so far in the course. This is a good point to look at the Backup Automation Map and see what we’ve completed and what’s left to do. So far, we have:

  • Picked and secured at least one backup storage location.

  • Installed PowerShell and VS Code.

  • Installed and configured Secret Management and Cred Man PowerShell Modules.

  • Saved PostgreSQL superuser password to Credential Manager.

  • Added path to PostgreSQL bin folder to PATH environment variable.

With these steps completed, you have the bottom half of the Backup Automation Map completed.



In this and the next six lessons we will be writing PowerShell scripts that will automatically and autonomously backup your Qlik Sense servers. We’ll start with a script to stop Qlik Sense services.

Stop Qlik Sense Services Script

Script to stop Qlik Sense services is among the simplest and most useful PowerShell scripts to have in your Qlik Sense automation toolbox. It’s simple because it mainly consists of only one primary command to stop Qlik Sense services along with couple of parameters. The command to stop a service is Stop-Service . We will use the -Name  parameter to specify which service we would like to stop. It’s as simple as that.

Proper Stopping Order of Services

The important thing to keep in mind as we will be creating the script is the stopping and starting order of services. Qlik Sense services have dependencies among themselves so it’s important to get services stopped and started in a proper order. As a quick reference, the proper stopping order is:

  1. Qlik Sense Engine Service

  2. Qlik Sense Printing Service

  3. Qlik Sense Proxy Service

  4. Qlik Sense Scheduler Service

  5. Qlik Sense Repository Service

  6. Qlik Sense Service Dispatcher

  7. Qlik Sense Logging Service (if available)

  8. Qlik Sense Repository Database

    1. Or postgresql-x64-## if your Qlik Sense server is running on a standalone PostgreSQL server.

Let’s get started and create the first Qlik Sense backup automation script!

14

STEPS

10

SCREENSHOTS

MED

COMPLEXITY

01. Create a Script File

Before we write an actual PowerShell script, we will need to create a script file. That is quite simple to do. Here are the steps:

Step 01.

Launch Visual Studio Code.

Step 02.

Go to the File menu.

Step 03.

Click the New File… option.

Step 04.

Enter a name of the script file along with .ps1  extension, something like stopQSServices.ps1, since we will be creating a script to stop Qlik Sense services first.


Step 05.

Hit the Enter key on your keyboard to bring up window where you will be able to select where you would like to save the scrip file.

Step 06.

Select a folder where you would like to save the script file.

Step 07.

Click the Create File button to create the script file.



02. Script to Stop Qlik Sense Services

Now that you have a script file created, let’s write the script to stop Qlik Sense services. The script will consist of:

  • Something that’s called a hashtable to hold common parameters for Stop-Service  command.

  • try-catch  block to handle errors in the script.

  • Write-Output  command for letting you know what script is doing.

  • Stop-Service  command to stop the services.

  • Write-Error  command for letting you know if script will encounter an error.

Let’s take a look at each piece of script one by one.

Hashtable

A hashtable in PowerShell is kind of like an Inline Load script in Qlik Sense. Here’s what it looks like:

If you’re following along, go ahead and copy and paste this hashtable into your script.

A hashtable is a way for you to create a table of key-value pairs. A hashtable is kind of like a data table that consists of a column and a value for that column. In this example, we have a “column” named PassThru that holds a Boolean value of TRUE  and another “column” named ErrorAction  with a value Stop  in it. Something like this:

In Qlik Sense, we can create a table like that using an inline LOAD statement, like this:

In PowerShell we do the same thing, but we store the results of a table in a variable ( $serviceParams ) instead of a table, we skip the LOAD *  and use =  sign instead, use symbol instead of INLINE  keyword, use {}  instead of [] , and set the value for column using sign. Same idea as Inline Load statement, just different syntax.

What Are PassThru  and ErrorAction ?

PassThru  and ErrorAction  are parameters that we will be using for Stop-Service  command. Each Stop-Service  command will have these two parameters. So, instead of typing these parameters over and over for each command, we’ll just save them to a hashtable and give the command the hashtable instead. This helps us eliminate the need to type the same parameters multiple times.

We will use the -PassThru  parameter to have the script show us, as a form of visual confirmation, which service was stopped. And -ErrorAction  parameter will be used to stop execution of script if one of the services will fail to stop. This way we will prevent the rest of the backup process from running if required services fail to stop. We need to make sure all Qlik Sense services are stopped in order to create a consistent and valid backup. If one of the services fails to stop, we want to stop execution of the backup process and we use -ErrorAction  parameter to do that.

try-catch  Block

try-catch  block can come off as a bit of a mysterious concept if you’ve never worked with a programing language, but the idea behind it is simple.

  • try  block is used to specify some code that you want PowerShell to run.

  • catch  block is used to house some code that you would like PowerShell to run only if the code in try  block ran into an issue.

In our case, we will put commands to stop Qlik Sense services inside of try  block. If PowerShell will run the commands to stop Qlik Sense services successfully, then PowerShell will simply skip the catch  block and be done.

However, if you run the script to stop Qlik Sense services and PowerShell encounters some issues stopping a service, it will stop execution of code that’s inside of try  block and will jump to the catch  block to instead run the code that’s inside of catch  block.

That’s all there is to try-catch  block. It’s just a method to try running a code and make sure to catch and report on any errors that script will encounter. It’s not any more complicated than that.

Write-Output  & Write-Error  Commands

Write-Output  command is used to log to the screen some text that you want to be able to see when script is running. The equivalent of Write-Output  command in Qlik Sense is the Trace statement. This is not anything critical and doesn’t need to be included in the script if you don’t want the script to give you any feedback.

However, I do like it when a script tells me what it is doing so I include the Write-Output  statements wherever I see fit. In this case, we’ll have this Write-Output  command before the first Stop-Service command:

This will generate a message in PowerShell terminal telling you that the process of stopping Qlik Sense services has begun.

We will also have a Write-Output  command at the end of the script telling us that the script finished running, if it did. If the script fails to stop any of Qlik Sense services, we will have a Write-Error  command inside of catch  block that will tell us what went wrong.

Stop-Service  Command

Lastly, and most importantly, the Stop-Service  command. This is the command that will actually stop the services that we will tell it to stop. Here’s the script with the Write-Output  and Write-Error  commands as well as try-catch  block to complete this script:

Again, if you’re following along, go ahead and copy and paste this script below the hashtable in your script file.

We will use the -Name  parameter for Stop-Service  command to specify which service or services we want to stop. We start by running the Stop-Service  to stop:

  • Qlik Sense Engine Service

  • Qlik Sense Printing Service

  • Qlik Sense Proxy Service

  • Qlik Sense Scheduler Service

We will also use the @serviceParams  hashtable that holds the -PassThru  and -ErrorAction  parameters with corresponding values for the Stop-Service  command.

Once the first four services have stopped, we stop the Qlik Sense Repository Service. Once Qlik Sense Repository Service is stopped, we stop Qlik Sense Service Dispatcher service. Lastly, the script will check to see if Qlik Logging Service is available and stop it if it is.

Complete Script & Script Comments

I like to also add notes to help myself and you remember what each block of script is doing. It’s a good practice and I highly recommend it. If you would like to write a comment in PowerShell script, use the #  symbol, like this:

Here’s the complete script to stop Qlik Sense services, along with comments:


03. Running the Script

Now that you have your script to stop Qlik Sense services ready, make sure to save it and let’s try running it. This is obvious, but I’ll say it anyway, make sure you’re not running this script on a server that needs to stay up right now. Executing this script will shut down Qlik Sense services.

With script saved and assuming you will be running it on a server that can be taken offline right now, let’s see how you can run this script that we just created.

Step 01.

Launch PowerShell as an Admin.

Step 02.

Click the Yes button in the User Account Control window.

Step 03.

Use the Set-Location  command to navigate to the folder where you saved the script file.

Step 04.

Type .\  followed by the name of the file that contains the script to stop Qlik Sense services.

Step 05.

Hit the Enter key on your keyboard to run the script and stop all Qlik Sense services except for Qlik Sense Repository Database service.

Step 06.

Wait for the script to finish running.

Step 07.

Launch the Services app to confirm that all except Qlik Sense Repository Database services have been stopped.


Guide

Summary

All Set!

There you go! You got your first PowerShell script ready. You now have an automated way to shut down Qlik Sense services in a proper order! No more remembering or looking up stopping order.

This lesson was a bit long, considering that the script is essentially a collection of Stop-Service commands, but I hope the details helped you understand what the script is doing if you’ve never worked with PowerShell before.

Next, we will create a script to start Qlik Sense services. I’ll see you in the next lesson!

Manual Start and Stop order of Qlik Sense services

QLIK SUPPORT ARTICLE

Qlik Support article detailing appropriate starting and stopping order of Qlik Sense services.

Trace

QLIK DOCUMENTATION

Qlik's documentation defining the TRACE script statement and providing few examples of how it can be used.

Understanding PowerShell Execution Policies

HOWDASH LESSON

Understand the different PowerShell execution policies, how they affect script execution, and what you need to do to safely run scripts on your Qlik Sense server.

References

Up Next

Start Qlik Sense Services

Copyright © 2023 howdash LLC

Guides

Enroll

01. Backup Automation

Introduction to Backups

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

Backup Automation Map

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

Stop Qlik Sense Services

01. Backup Automation

Start Qlik Sense Services

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

01. Backup Automation

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

02. Upgrade

03. Recover

03. Recover

03. Recover

03. Recover

03. Recover

03. Recover

03. Recover

03. Recover

03. Recover

03. Recover

03. Recover

03. Recover

03. Recover

03. Recover

04. Bonus

bottom of page