Running Butler SOS as a Windows Service
On Windows, Butler SOS usually runs as a service, so that it starts with the server and is restarted if it stops. Butler SOS sets that service up, and removes it again, by itself:
.\butler-sos.exe --install-service -c C:\ButlerSOS\config\production.yaml --on-invalid-config wait
.\butler-sos.exe --uninstall-serviceOne server can also run several Butler SOS services, for example one per Qlik Sense environment, each with its own name. See Several Butler SOS services on one server.
Versions
--install-service and --uninstall-service are new in Butler SOS 15.4.0. Installing several services on one server, with --service-name, --service-display-name and --service-description, is new in 15.5.0.
On earlier versions, use a third-party service wrapper such as NSSM. A step-by-step tutorial is at ptarmiganlabs.com. To move such a service over, see Moving from NSSM.
Both options are for Windows only. On Linux, run Butler SOS as a systemd service, and on macOS as a launchd service.
Before you start
- Use the Windows release of Butler SOS. It carries the service wrapper (see What the service is).
- Open an elevated prompt. Right-click PowerShell or the Command Prompt and choose Run as administrator. Installing or removing a service needs one, and Butler SOS says so if the prompt is not elevated.
- Have a working config file. Butler SOS checks it before it installs anything.
- Put the certificate paths in the config file as full paths, such as
C:\ButlerSOS\config\certificate\client.pem. A service does not run in the folder you installed it from, so a path relative to "here" would point somewhere else. - A relative
Butler-SOS.logDirectory, such aslog, is a folder besidebutler-sos.exe, as it always is. An absolute one is used as it is.
The wrapper needs .NET Framework 4.6.1 or later, which every supported Windows Server has.
Installing the service
From an elevated prompt, in the folder where butler-sos.exe is:
.\butler-sos.exe --install-service -c C:\ButlerSOS\config\production.yaml --on-invalid-config waitGive --install-service the same options you want the service to run Butler SOS with. They are kept, except the service options themselves. A relative config file path is fine: it is turned into a full path for the service.
What it checks first
Butler SOS stops, and installs nothing, when:
- it is not on Windows;
- the service name, display name or description cannot be used (see Several Butler SOS services on one server);
- the prompt is not elevated;
- a service of that name exists already:
butler-sos, or the name given with--service-name. Remove it first, with--uninstall-serviceif Butler SOS installed it, or the way it was set up if not. Or install this one under another name; - the config file does not pass the same checks Butler SOS runs when it starts (the same as
--check-config). The problems are listed, as at a normal start. This way a service that could not start is never installed; - the command line has a secret on it (see Options that are not accepted).
What it writes
In a folder called service, beside the config file:
C:\ButlerSOS\config\
├── production.yaml
└── service\
├── butler-sos-service.exe the service wrapper
├── butler-sos-service.xml its settings: what to run, and how
└── logs\ the service's outputA service installed with a name of its own, using --service-name, gets a folder called service-<name> instead, so that two services never share one.
Then it registers the service, starts it, and says what it did:
Installed the Windows service butler-sos, and started it.
It runs: C:\ButlerSOS\butler-sos.exe --configfile C:\ButlerSOS\config\production.yaml --on-invalid-config wait
In the folder: C:\ButlerSOS\config
Its output goes: C:\ButlerSOS\config\service\logs
It starts by itself when Windows starts, and is restarted when it fails.
It runs as LocalSystem. To use another account, change it in services.msc. That account needs to read the config file, the certificates and the log folder.
To remove it, from an elevated prompt: C:\ButlerSOS\butler-sos.exe --uninstall-serviceIf Windows refuses to register the service, Butler SOS removes the two files again, and the service folder if it made it and it is empty, and exits with code 1. If the service is registered but does not start, Butler SOS says so and exits with code 1. The service's output, in the logs folder, says why.
Use --on-invalid-config wait for a service
If the config file later develops a problem, by default Butler SOS exits at its next start, and Windows restarts it: after 30 seconds, then 60 seconds, then every 5 minutes. With --on-invalid-config wait Butler SOS stays up instead, starts none of its services, and reports the problem in its log until you fix the file and restart the service. Butler SOS suggests this when you install without it.
Options that are not accepted
The service's command line is written to butler-sos-service.xml in plain text, where anyone who can read the folder can read it. So --install-service refuses:
--new-relic-account-name,--new-relic-api-keyand--new-relic-account-id. Put the New Relic accounts in the config file instead, underButler-SOS.thirdPartyToolsCredentials.newRelic;- any other option whose name says it holds a secret, such as a key, token or password.
The service's command line is written to its XML file in plain text, so --install-service does not take these options:
--new-relic-api-key: put the New Relic accounts in the config file instead, under Butler-SOS.thirdPartyToolsCredentials.newRelic.
No service was installed.A path with a % in it is refused too: the service wrapper would read it as an environment variable.
What the service is
A Windows service must answer the Windows service control manager, which a Node.js program such as Butler SOS cannot do. So the service runs a small, widely used wrapper, WinSW v2.12.0 (MIT licence), which starts Butler SOS, watches it and stops it. butler-sos-service.exe is WinSW under a name that finds its settings file beside it. Its licence notice is in THIRD-PARTY-NOTICES.md in the release.
| Setting | Value |
|---|---|
| Name | butler-sos, or the name given with --service-name |
| Display name | The service name, or the one given with --service-display-name |
| Runs | butler-sos.exe by its full path, with the options it was installed with |
| Working folder | The config file's folder |
| Start type | Automatic (delayed start) |
| Account | LocalSystem |
| When it fails | Restart after 30 s, then 60 s, then every 5 min; the count resets after 1 hour without a failure |
| When it is stopped | Butler SOS gets Ctrl+C and 15 s to stop, then it is ended |
| Its output | service\logs (service-<name>\logs), in files rolled at 10 MB, 8 of each kept |
Where the logs are
service\logs\butler-sos-service.out.log: everything Butler SOS prints, as you would see it in a console.service\logs\butler-sos-service.err.log: what it prints as errors, such as a config file report.service\logs\butler-sos-service.wrapper.log: what the wrapper itself did: start, stop, restart.- Butler SOS's own log files, when
Butler-SOS.fileLoggingistrue, are whereButler-SOS.logDirectorysays, as before.
The service also writes start and stop events to the Windows Application event log, with the service's name as the source: butler-sos, unless you gave it another name.
Stopping
When the service is stopped, the wrapper sends Butler SOS Ctrl+C. Butler SOS logs that it is stopping and that it stopped, and exits, which takes well under a second:
2026-11-29T08:39:17.626Z info: MAIN: Received SIGINT. Butler SOS is stopping.
2026-11-29T08:39:17.627Z info: MAIN: Butler SOS stopped cleanly.If it has not exited after 15 seconds, the wrapper ends it. See Stopping Butler SOS for the exit codes and what a stop does not do yet.
Running it as another account
The service runs as LocalSystem. To run it as another account, change it in services.msc: open the service, go to the Log On tab, and choose This account. Then restart the service. That account needs to be able to:
- read the config file and the certificate files;
- write to the service's
logsfolder and to Butler SOS's own log folder; - run
butler-sos.exeand the service'sbutler-sos-service.exe.
Removing the service
From an elevated prompt:
.\butler-sos.exe --uninstall-serviceTo remove a service you installed with a name of its own, add that name:
.\butler-sos.exe --uninstall-service --service-name butler-sos-prodIt finds the installed service from its entry in the Windows registry, so you can run it from any folder, and it needs no config file. It stops the service, waits for it to stop, removes it, and deletes butler-sos-service.exe and butler-sos-service.xml. The logs folder is kept.
Removed the Windows service butler-sos-prod.
Its logs are kept, in C:\ButlerSOS\prod\config\service-butler-sos-prod\logs.
If services.msc is open, Windows may list the service until it is closed.If
butler-sos-service.exeorbutler-sos-service.xmlwas deleted, Butler SOS writes it again first, as the wrapper needs both to remove the service, and says so.If the service does not stop, it is not removed: Windows would only mark a running service for deletion, and Butler SOS would keep running. Butler SOS says so and exits with code 1.
If no such service is installed, it says so and exits with code 0. Given the config file with
-c, it also removes any wrapper files a failed install left in that config file'sservicefolder (service-<name>for a service with a name of its own). Other services' folders are not touched.A service that Butler SOS did not install, for example one set up by hand with another wrapper, is left alone. Remove it the way it was set up, for example with
sc.exe delete butler-sos.The wrapper removes the service its
butler-sos-service.xmlnames. If that file names another service, for example because aservicefolder was copied from another instance, Butler SOS runs nothing and says so, rather than stop and remove the other service:textThe butler-sos-prod service runs the wrapper in C:\ButlerSOS\prod\config\service-butler-sos-prod, but that wrapper's XML file is for the service butler-sos-dev. Running it would stop and remove butler-sos-dev instead, so nothing was changed. Put back the XML file the butler-sos-prod service was installed with, or remove that service with: sc.exe delete butler-sos-prod
Several Butler SOS services on one server
A server dedicated to monitoring often runs one Butler SOS per Qlik Sense environment: for example development, test and production. Each needs a service of its own, with a name that you, the other administrators and your monitoring tools can tell apart.
New in 15.5.0
Earlier versions always name the service butler-sos, so one server can run only one.
Three options, used with --install-service, set that:
| Option | What it sets | When it is left out |
|---|---|---|
--service-name <name> | The service's name: what sc.exe, Get-Service, Stop-Service and service monitors use | butler-sos |
--service-display-name <text> | The name services.msc shows | The service name |
--service-description <text> | The description services.msc shows | Butler SOS: real-time operational metrics and events from Qlik Sense Enterprise on Windows. |
- The service name is 1 to 80 letters (A to Z), digits,
-,_and., with no spaces. It starts with a letter or a digit, and does not end with.. For example:butler-sos-prod. Windows allows longer names, but the name is also part of the service's folder, and the service wrapper cannot use paths longer than 260 characters. Windows does not tell upper and lower case apart, soButler-SOS-Prodis the same service asbutler-sos-prod. - The display name and description can be any text, with spaces, but no line breaks and no
%: the service wrapper would read%...%as an environment variable. Put them in double quotes on the command line. --uninstall-servicetakes--service-nametoo, to say which service to remove. It does not take the display name or description.- The three options are refused without
--install-serviceor--uninstall-service.
A good naming scheme starts every name with butler-sos-. Then Get-Service butler-sos* lists them all, and they sort together in services.msc and in your monitoring tools.
Example: one service per Qlik Sense environment
This example sets up three services on one monitoring server, for the DEV, TEST and PROD Qlik Sense environments. The steps are the same for two services, or for five.
1. Give each service a folder of its own
Butler SOS reads a relative Butler-SOS.logDirectory as a folder beside butler-sos.exe. Two services that run the same butler-sos.exe with a relative log folder would write their logs into the same folder. So give each service its own folder, with its own copy of butler-sos.exe, its config file and its logs:
C:\ButlerSOS\
├── dev\
│ ├── butler-sos.exe
│ ├── log\ Butler SOS's own logs
│ └── config\
│ ├── production.yaml
│ └── service-butler-sos-dev\ the service's wrapper, settings and output (written by the install)
├── test\
│ ├── butler-sos.exe
│ ├── log\
│ └── config\
│ ├── production.yaml
│ └── service-butler-sos-test\
└── prod\
├── butler-sos.exe
├── log\
└── config\
├── production.yaml
└── service-butler-sos-prod\This also lets you upgrade one environment's Butler SOS at a time, and try a new version on DEV first.
2. Give each service its own ports
Two programs cannot listen on the same port. Where the services run on one server, give each one's config file its own port for every feature it turns on:
| Setting | Port in the template |
|---|---|
Butler-SOS.userEvents.udpServerConfig.portUserActivityEvents | 9997 |
Butler-SOS.logEvents.udpServerConfig.portLogEvents | 9996 |
Butler-SOS.prometheus.port | 9842 |
Butler-SOS.prometheus.nodeMetricsPort | 9001, also when commented out |
Butler-SOS.configVisualisation.port | 3100 |
Butler SOS does not check the ports when it installs a service. A port that another service already uses shows up a few seconds after the service has started: Butler SOS logs the clash in the service's butler-sos-service.out.log and stops, and Windows keeps restarting it:
error: CONFIG VIS: Could not set up config visualisation server on null. listen EADDRINUSE: address already in use 127.0.0.1:3101From Butler SOS 15.5.0 the message names the host and port from the config file instead of null. See When the server cannot start.
nodeMetricsPort needs the most care. With Prometheus turned on, Butler SOS serves a second endpoint, for its own Node.js metrics, on port 9001, also when nodeMetricsPort is not in the config file at all: the template has it commented out. So with Prometheus on in more than one service, uncomment nodeMetricsPort and give each service its own.
One way to keep track is to give each environment its own block of ports. Here DEV keeps the template's ports, TEST adds 10 and PROD adds 20. Only the lines that differ between the three config files are shown:
Butler-SOS:
configVisualisation:
port: 3100
userEvents:
udpServerConfig:
portUserActivityEvents: 9997
logEvents:
udpServerConfig:
portLogEvents: 9996
prometheus:
port: 9842
nodeMetricsPort: 9001Butler-SOS:
configVisualisation:
port: 3110
userEvents:
udpServerConfig:
portUserActivityEvents: 10007
logEvents:
udpServerConfig:
portLogEvents: 10006
prometheus:
port: 9852
nodeMetricsPort: 9011Butler-SOS:
configVisualisation:
port: 3120
userEvents:
udpServerConfig:
portUserActivityEvents: 10017
logEvents:
udpServerConfig:
portLogEvents: 10016
prometheus:
port: 9862
nodeMetricsPort: 9021Then point each Qlik Sense environment's log appenders and user activity events at the ports of its own Butler SOS: the DEV environment at 9996 and 9997, TEST at 10006 and 10007, and PROD at 10016 and 10017. If Prometheus scrapes Butler SOS, give it one target per service.
Each config file also points at its own Qlik Sense environment's servers and certificates, as it would on a server of its own.
Check each config file first
--install-service checks the config file before it installs anything, but you can also check each one on its own:
C:\ButlerSOS\prod\butler-sos.exe -c C:\ButlerSOS\prod\config\production.yaml --check-config3. Install the services
From an elevated PowerShell prompt, one at a time:
C:\ButlerSOS\dev\butler-sos.exe --install-service -c C:\ButlerSOS\dev\config\production.yaml --on-invalid-config wait --service-name butler-sos-dev --service-display-name "Butler SOS (DEV)" --service-description "Butler SOS for the DEV Qlik Sense environment"
C:\ButlerSOS\test\butler-sos.exe --install-service -c C:\ButlerSOS\test\config\production.yaml --on-invalid-config wait --service-name butler-sos-test --service-display-name "Butler SOS (TEST)" --service-description "Butler SOS for the TEST Qlik Sense environment"
C:\ButlerSOS\prod\butler-sos.exe --install-service -c C:\ButlerSOS\prod\config\production.yaml --on-invalid-config wait --service-name butler-sos-prod --service-display-name "Butler SOS (PROD)" --service-description "Butler SOS for the PROD Qlik Sense environment"Or all three with a short script. It stops at the first install that fails:
$root = 'C:\ButlerSOS'
foreach ($environment in 'dev', 'test', 'prod') {
$label = $environment.ToUpper()
& "$root\$environment\butler-sos.exe" --install-service `
-c "$root\$environment\config\production.yaml" `
--on-invalid-config wait `
--service-name "butler-sos-$environment" `
--service-display-name "Butler SOS ($label)" `
--service-description "Butler SOS for the $label Qlik Sense environment"
if ($LASTEXITCODE -ne 0) {
Write-Warning "butler-sos-$environment was not installed. The output above says why."
break
}
}Each install says which service it installed, and how to remove it:
Installed the Windows service butler-sos-prod, and started it.
services.msc shows it as: Butler SOS (PROD)
It runs: C:\ButlerSOS\prod\butler-sos.exe --configfile C:\ButlerSOS\prod\config\production.yaml --on-invalid-config wait
In the folder: C:\ButlerSOS\prod\config
Its output goes: C:\ButlerSOS\prod\config\service-butler-sos-prod\logs
It starts by itself when Windows starts, and is restarted when it fails.
It runs as LocalSystem. To use another account, change it in services.msc. That account needs to read the config file, the certificates and the log folder.
To remove it, from an elevated prompt: C:\ButlerSOS\prod\butler-sos.exe --uninstall-service --service-name butler-sos-prod4. Check that they run
Get-Service butler-sos*Status Name DisplayName
------ ---- -----------
Running butler-sos-dev Butler SOS (DEV)
Running butler-sos-prod Butler SOS (PROD)
Running butler-sos-test Butler SOS (TEST)Each service's own output is in its service-<name>\logs folder, and its start and stop events are in the Windows Application event log under its own name.
5. Day to day
Stop, start and restart each service by its name:
Restart-Service butler-sos-testUpgrade one environment at a time. For example TEST, with the new butler-sos.exe in C:\Downloads:
Stop-Service butler-sos-test
Copy-Item C:\Downloads\butler-sos.exe C:\ButlerSOS\test\butler-sos.exe
Start-Service butler-sos-testRemoving one service leaves the others running:
C:\ButlerSOS\dev\butler-sos.exe --uninstall-service --service-name butler-sos-devWhat Butler SOS refuses
Names and texts it cannot use are refused before anything is installed:
PS> .\butler-sos.exe --install-service -c .\config\production.yaml --service-name "butler sos prod"
The service name "butler sos prod" cannot be used. A service name is 1 to 80 letters, digits, "-", "_" and ".", with no spaces, starts with a letter or digit, and does not end with ".". For example: butler-sos-prod
No service was installed.PS> .\butler-sos.exe --install-service -c .\config\production.yaml --service-name butler-sos-prod --service-display-name "Butler SOS 100%"
The display name contains "%", which the service wrapper would read as an environment variable: Butler SOS 100%
No service was installed.A name that is already taken, in any mix of upper and lower case:
A service named Butler-SOS-Prod exists already, and runs C:\ButlerSOS\prod\config\service-butler-sos-prod\butler-sos-service.exe. Remove it first, with --uninstall-service --service-name Butler-SOS-Prod if Butler SOS installed it, or install this one with another --service-name.A service installed with an earlier version
A service installed with Butler SOS 15.4 is called butler-sos, and its files are in the service folder. Nothing changes for it: --uninstall-service without --service-name still removes it, and it can stay beside services with names of their own. To give it a name of its own, remove it, and install it again with --service-name.
Moving from NSSM or another wrapper
A service set up by hand, for example with NSSM, is not touched by Butler SOS. If it is called butler-sos, a new install with that name is refused, and --uninstall-service says it was not installed by Butler SOS. Either remove the old service first, or give the new one another name.
To replace an NSSM service called butler-sos, from an elevated prompt:
nssm stop butler-sos
nssm remove butler-sos confirm
.\butler-sos.exe --install-service -c C:\ButlerSOS\config\production.yaml --on-invalid-config waitUse the same config file and options the NSSM service ran Butler SOS with. nssm get butler-sos AppParameters shows them.
Upgrading Butler SOS
The service runs butler-sos.exe from where it is, so an upgrade is a file swap:
- Stop the service:
Stop-Service butler-sos, or fromservices.msc. - Replace
butler-sos.exewith the new version, in the same folder. - Start the service:
Start-Service butler-sos.
For a service with a name of its own, use that name, such as Stop-Service butler-sos-prod. With several services, upgrade each one's copy of butler-sos.exe the same way.
There is no need to remove and install the service again, unless you want to change the options it runs Butler SOS with. To change those, run --uninstall-service, then --install-service with the new options.
Code signing and endpoint protection
butler-sos.exe is signed by Ptarmigan Labs. The service wrapper, butler-sos-service.exe, is WinSW exactly as its project releases it, and WinSW's releases are not code signed. Windows reports it as NotSigned.
Most Windows servers run it without a question. If your endpoint protection or application control (AppLocker, Windows Defender Application Control and the like) only allows signed programs, or programs from known publishers, a publisher rule for Ptarmigan Labs allows butler-sos.exe but not the wrapper. Allow the wrapper with a file hash rule, or by its path.
Create the hash rule from the installed wrapper. AppLocker and Windows Defender Application Control compute their own hash of a program, which is not the SHA-256 shown below, so that value does not work in a hash rule. For AppLocker, run this in PowerShell as an administrator, with the path to your service's folder:
Get-AppLockerFileInformation -Path 'C:\ButlerSOS\config\service\butler-sos-service.exe' |
New-AppLockerPolicy -RuleType Hash -User Everyone -Xml |
Out-File butler-sos-service-applocker.xmlThen merge butler-sos-service-applocker.xml into your AppLocker policy the way you manage it: for example with Set-AppLockerPolicy -XmlPolicy .\butler-sos-service-applocker.xml -Merge on a server that is not managed by Group Policy. For Windows Defender Application Control, add a rule at the Hash level for the same file.
The wrapper is the same file in every Butler SOS release that carries WinSW v2.12.0, so the rule keeps working when you upgrade Butler SOS. It is also the same file in every service's folder, so one hash rule allows the wrapper of every Butler SOS service on the server. A release that moves to another WinSW version says so in its release notes, and the rule then needs to be created again from the new file.
To check that a wrapper on disk is the genuine one, compare its SHA-256 with this value:
Get-FileHash 'C:\ButlerSOS\config\service\butler-sos-service.exe' -Algorithm SHA256B5066B7BBDFBA1293E5D15CDA3CAAEA88FBEAB35BD5B38C41C913D492AADFC4FButler SOS checks the same value itself before it writes the wrapper to disk, and refuses a wrapper that does not match.
Troubleshooting
| What you see | What it means |
|---|---|
--install-service needs an elevated prompt | Open PowerShell or the Command Prompt with Run as administrator. |
A service named ... exists already, and runs ... | Remove the existing service first, or install this one with another --service-name. |
The service name "..." cannot be used. | Use 1 to 80 letters A to Z, digits, -, _ and ., with no spaces. Start with a letter or digit, and do not end with .. |
The display name contains "%" (or The description) | Leave out the %. The service wrapper would read it as an environment variable. |
--service-name, --service-display-name and --service-description are only used with --install-service or --uninstall-service | Add --install-service or --uninstall-service. |
The config file did not pass the check, so no service was installed. | Fix the problems listed above that line, then install again. |
--install-service is for Windows only. | On Linux use systemd, on macOS launchd. |
This build of Butler SOS does not include the service wrapper, WinSW. | Use a Windows release of Butler SOS. |
The ... service was not installed by Butler SOS | Remove that service the way it was set up. See Moving from NSSM. |
... but that wrapper's XML file is for the service ... | The service's butler-sos-service.xml names another service, and running its wrapper would remove that one. Nothing was changed. Put back the XML file the service was installed with, or remove the service with sc.exe delete <name>. |
The service did not stop, so it was not removed. | Stop it from services.msc. If it will not stop, end the butler-sos-service.exe that runs from that service's folder in Task Manager (the Details tab can show each one's path), and run --uninstall-service again straight away: Windows starts the service again after 30 seconds. |
Could not check whether a ... service exists (or is installed) | Butler SOS reads the service's registry entry with PowerShell. The reason follows the message; often PowerShell is blocked by policy. |
These files could not be removed. Delete them by hand: | The service is removed, but a file was still in use. Delete the files listed once nothing uses them. |
The config check was interrupted, so no service was installed. | The check was stopped with Ctrl+C. Run --install-service again. |
A service installs and starts, then stops a few seconds later, again and again. Its butler-sos-service.out.log says EADDRINUSE: address already in use | Two services use the same port. Give one of them another port in its config file, and restart it. See Give each service its own ports. |
The service will not stop, and sc.exe stop butler-sos says The service cannot accept control messages at this time (error 1061) | Seen once in testing, when the service was stopped within a second of being installed. In Task Manager, end that service's butler-sos-service.exe; Windows starts the service again after 30 seconds, and it can then be stopped as usual. |