Data Hub

Run as a Windows service

Install and operate the Data Hub watcher as a Windows service so it starts on boot, survives logouts, and can auto-update in the background.

ForLab operators

On a lab instrument PC, run the watcher as a Windows service. The service starts when the PC starts, keeps running after you sign out, restarts if it crashes, and installs automatic updates. Running data-hub-watcher watch in a terminal is for quick checks and for macOS or Linux.

Install the service extra

The service needs pywin32, which comes with the windows-service extra. The default install already includes it. If you installed without it, add it now:

uv tool install "data-hub-watcher[windows-service]"

Run data-hub-watcher init first if you haven’t configured the watcher yet. The service uses the same ~/.data-hub/config.yaml and per-environment .env file.

Install and start

From an Administrator terminal:

data-hub-watcher service install
data-hub-watcher service start

service install sets the service to start shortly after Windows boots, once the network is up. It also tells Windows to restart the service if it crashes, and adds the DataHubWatcherUpgrade Scheduled Task that automatic updates use.

Automatic updates on Windows need service install (or service reinstall) to have run at least once from an Administrator terminal. A PC whose service was installed before automatic updates existed needs one service reinstall to add the task.

Lifecycle commands

CommandWhat it does
data-hub-watcher service installRegister the service
data-hub-watcher service startStart the service
data-hub-watcher service stopStop the service
data-hub-watcher service statusShow whether the service is running
data-hub-watcher service uninstallRemove the service
data-hub-watcher service reinstallStop, uninstall, install, and start in one go

Run service reinstall after you update the watcher by hand, for example with uv tool install -U from an Administrator terminal. It carries on when the stop or the uninstall fails, so it works even if the service is already gone.

How long a stop takes

Once the watcher is running, service stop finishes within about 25 seconds, even when Data Hub doesn’t answer. After the stop begins, the watcher starts no new file or upload part, and gives a part already on its way up to 15 seconds to arrive. In the last 10 seconds, it sends its watcher_stopped event and a final heartbeat, so it shows as Stopped when Data Hub answers.

A stop takes longer in two cases:

  • While the watcher is starting: it sends its config and first heartbeat before it looks for a stop, and waits for Data Hub to answer each one, or for each to time out after 35 seconds. A stop during the first scan of a large folder ends at the next file, and the watcher scans the rest at its next start
  • While the watcher applies a settings change from Data Hub: it waits up to 2 minutes for its uploads to finish

Watchers before 1.4.2 can take longer to stop when Data Hub doesn’t answer, and watchers before 1.4.3 scan the whole watch folder before they stop, which takes minutes on a large folder.

A file cut off by a stop isn’t lost. In auto mode, the watcher uploads it again the next time it starts. A service stop cancels requests made with Upload, so request those files again. A PC restart or an automatic update keeps them requested; see When the PC restarts or shuts down.

To make the service load a different .env file from the default for its environment, such as ~/.data-hub/.env.production, pass --env-path to service install or service reinstall.

When the PC restarts or shuts down

Restarting or shutting down the PC stops the service cleanly. The watcher sends a final heartbeat, so it shows as Stopped on its page and the instrument reads Restarting. The service starts again when the PC boots.

To tell a restart from a service stop, look for one of these:

  • On the watcher’s Activity tab: “Service stopped because Windows is restarting or shutting down”
  • In the raw watcher_stopped event: “Service stopped: Windows is shutting down”
  • In watcher.log and the Windows Application log: Data Hub Watcher stopping: Windows is shutting down

An automatic update stops the service the same way. The watcher tells Data Hub the stop is for an update, so it shows as Stopped and the instrument reads Restarting while the new version installs.

Requested uploads across a restart

Files someone requested with Upload stay requested across a restart or an automatic update, and the watcher uploads them once the service is running again. Hover over the watcher’s Stopped badge to see how long Data Hub will wait. If the watcher hasn’t checked in 15 minutes after its last heartbeat, Data Hub cancels the requests, the watcher shows Unresponsive, and the instrument reads Offline.

Thirty minutes after the instrument reads Offline, its subscribers are notified; see When an instrument goes offline. A PC that is shut down every night therefore sends an alert each night.

Two stops cancel the requests at once: service stop, which leaves the instrument Offline with the notice “Uploads from this instrument are paused”, and an update you start by hand with data-hub-watcher self-update. Request uploads lists every case that cancels a request.

When the stop is cut short

At a restart, Windows gives a service 10 seconds to stop on Windows 10 version 1703 and later, and longer on older builds. The watcher keeps its own stop to about 8 seconds, which is enough for the final heartbeat when Data Hub answers. A file still uploading is cut off, and the watcher uploads it again after the restart; see An upload was cut off by a restart or an update.

If Data Hub can’t be reached, or the stop is cut short for another reason, the final heartbeat doesn’t arrive. If the PC then stays down for more than 5 minutes, the watcher shows as Unresponsive until the service starts again. The watcher_stopped event that didn’t get sent is recorded when the service starts again, with the time of the stop (watcher 1.4.3 and later).

Windows 10 and 11 turn on Fast Startup by default. With it, Shut down in the Start menu doesn’t stop the service: Windows saves its state and the service carries on from it at the next start, so no final heartbeat is sent and no watcher_stopped event is recorded. Restart always stops the service, and so does a shutdown with Fast Startup turned off.

Watchers before 1.4.1 don’t hear about a Windows restart, so a restart ends them with no final heartbeat and no watcher_stopped event. Updating the watcher is enough to fix that, with no service reinstall. Watchers before 1.4.2 don’t tell Data Hub that a stop is for an automatic update, so Data Hub cancels requested uploads when they update.

When the watcher is deregistered

The service stops about three minutes after someone deregisters its watcher or retires its instrument, and stays stopped. It exits cleanly, so Windows doesn’t restart it as it would after a crash. Watchers before 1.4.3 keep running instead and get errors from Data Hub until someone stops them.

The error is in watcher.log and in the Application event log: This watcher was deregistered on Data Hub, so its registration no longer exists. Run 'data-hub-watcher init' to register it again. The service sends no watcher_stopped event and no final heartbeat, because Data Hub would refuse both.

Starting the service again, including at boot, checks the registration first. If the watcher is still deregistered, the start logs the same error and the service stops with an error. Windows then retries twice, after about one minute and again after about two, and leaves the service stopped. A service that already failed in the last 24 hours gets fewer retries.

To use the PC again, run data-hub-watcher init on the PC. If the instrument was retired, an admin has to reactivate it first, because init is refused for a retired instrument (see Retire an instrument). Then run data-hub-watcher service start from an Administrator terminal. See Troubleshoot a watcher.

Don’t run watch while the service runs

Running data-hub-watcher watch in a terminal while the service is running isn’t supported, because both would write to the same log file and upload from the same watch folder. To debug in a terminal, stop the service first:

data-hub-watcher service stop
data-hub-watcher --verbose watch
data-hub-watcher service start

Where the service writes logs

The service and the CLI share one rotating log:

  • C:\ProgramData\DataHubWatcher\watcher.log

A separate service-bootstrap.log in the same folder records crashes that happen before the service has fully started, such as a missing pywin32, a moved Python environment, or a broken install. To turn on debug logging without a reinstall, add DATA_HUB_WATCHER_LOG_LEVEL=DEBUG to the env file the service loads and restart the service (watcher 1.4.2 and later).

On this page