> For the complete documentation index, see [llms.txt](https://docs.keeper.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keeper.io/keeperpam/jp/endpoint-privilege-manager/policies/policy-examples/enable-and-start-the-watchdog-service.md).

# Watchdogサービスを有効化して起動する

<figure><img src="/files/zInCjot0bpyyCdn187Jz" alt=""><figcaption></figcaption></figure>

この例では、**ConfigurationUpdate**ポリシーを1本使い、Watchdogサービスの設定を構成し、OSサービスとして起動するジョブを展開する方法を示します。これらは1回のポリシー配信で完了します。

## 概要 <a href="#overview" id="overview"></a>

Watchdogは、`KeeperPrivilegeManager` の稼働状態を監視する独立したサービスです。別のOSサービスとして動作し、定期的に `/health` エンドポイントで状態を確認し、メインサービスが応答しなくなった場合は自動的に再起動します。

Watchdogを有効にする場合、通常は2本のポリシーが必要です。Watchdogの構成を `appsettings.json` に書き込む `SettingsUpdate` と、OSサービスを起動する `JobUpdate` です。`PolicyType` が `ConfigurationUpdate` のポリシーでは、これらを1本にまとめられます。設定とジョブの両方が含まれる場合、先に設定が適用され、その後ジョブが作成・実行されるため、Watchdogサービスが構成を読み取る時点では、設定はすでにディスク上に書き込まれています。

## ポリシー (JSON) <a href="#the-policy" id="the-policy"></a>

```json
{
  "PolicyId": "policy-enable-watchdog",
  "PolicyName": "Enable and Start Watchdog",
  "PolicyType": "ConfigurationUpdate",
  "Status": "enabled",
  "Operator": "And",
  "Actions": {
    "OnSuccess": { "Controls": [] },
    "OnFailure": { "Command": "deny" }
  },
  "Rules": [],
  "Extension": {
    "TargetFile": "appsettings.json",
    "Action": "Update",
    "SettingsJson": {
      "Watchdog": {
        "CheckIntervalSec": 10,
        "AutoRemediate": true,
        "StartupDelaySec": 90
      }
    },
    "JobId": "start-watchdog-service",
    "JobJson": {
      "id": "start-watchdog-service",
      "name": "Start Watchdog Service",
      "description": "Starts the KeeperWatchdog OS service on the endpoint.",
      "enabled": true,
      "asUser": false,
      "priority": 9,
      "events": [
        {
          "eventType": "Custom",
          "customEvent": "PolicyPreprocessingCompleted"
        }
      ],
      "parameters": [],
      "tasks": [
        {
          "id": "start-watchdog-windows",
          "name": "Start Watchdog on Windows",
          "command": "sc",
          "arguments": "start KeeperWatchdog",
          "expectedExitCode": 0,
          "timeoutSeconds": 30,
          "executionType": "Service",
          "onFailure": "start-watchdog-unix"
        },
        {
          "id": "start-watchdog-unix",
          "name": "Start Watchdog on Linux/macOS",
          "command": "systemctl",
          "arguments": "start keeper-watchdog",
          "expectedExitCode": 0,
          "timeoutSeconds": 30,
          "executionType": "Service"
        }
      ],
      "osFilter": {
        "windows": true,
        "linux": true,
        "macOS": true
      }
    }
  }
}
```

## 各要素の役割 <a href="#what-each-part-does" id="what-each-part-does"></a>

**設定部分:** `TargetFile` と `SettingsJson` は `appsettings.json` を対象とし、`Watchdog` 構成セクションをマージします。`Update` アクションはファイル内の既存キーをすべて保持し、`SettingsJson` に含まれるキーのみを追加または上書きします。

Watchdogセクションでは、以下の3つのキーを任意で指定できます。

| キー                 | 型    | デフォルト | 説明                                                     |
| ------------------ | ---- | ----- | ------------------------------------------------------ |
| `CheckIntervalSec` | int  | 10    | ヘルスチェックの間隔 (秒)。2～300の範囲に収められます                         |
| `AutoRemediate`    | bool | true  | `true` のとき、Watchdogは失敗時にサービスを再起動します。`false` のときは監視のみです |
| `StartupDelaySec`  | int  | 90    | Watchdog起動後、最初のヘルスチェックまで待つ秒数 (最小 30)                   |

**ジョブ部分:** `JobId` と `JobJson` はジョブファイルを `Jobs/start-watchdog-service.json` に書き込み、ジョブの再読み込みをトリガーします。ジョブは `PolicyPreprocessingCompleted` イベントで実行され、このポリシーを配信するのと同じ同期サイクル内で動作します。ジョブにはフォールバック付きの2つのタスクがあります。Windowsでは `sc start KeeperWatchdog` を実行し、最初のタスクが失敗した場合はLinuxおよびmacOS向けに `systemctl start keeper-watchdog` に切り替わります。

## エンドポイントで起きること <a href="#what-happens-on-the-endpoint" id="what-happens-on-the-endpoint"></a>

ポリシーを受信すると、以下の順序で処理されます。

```
Policy received on sync_down
  └─> Policy preprocessing runs
        └─> PolicyPreprocessingCompleted fires
              └─> Process Configuration Policies job triggers
                    ├─> Merges Watchdog section into appsettings.json
                    └─> Writes Jobs/start-watchdog-service.json
                          └─> Job fires
                                └─> sc start KeeperWatchdog          (Windows)
                                    or systemctl start keeper-watchdog (Linux/macOS)
                                          └─> Watchdog starts and reads appsettings.json
                                                └─> Monitoring loop begins
```

## バリエーション <a href="#variations" id="variations"></a>

**監視のみ (自動再起動なし):** `AutoRemediate` を `false` にします。Watchdogは障害を検知してログに記録しますが、サービスは再起動しません。

**ヘルスチェックを低頻度にする:** 負荷の高いハードウェアでは `CheckIntervalSec` を大きくします (最大 300)。障害検知を速くしたい場合は小さくします (最小 2)。

**エージェントの起動のたびにWatchdogを起動する:** イベントトリガーを `PolicyPreprocessingCompleted` から `Startup` に置き換えます。ポリシー同期時だけでなく、エージェントが起動するたびにWatchdogサービスが起動します。

**後からWatchdogを無効にする:** 2本目の `ConfigurationUpdate` ポリシーをプッシュし、`SettingsJson` 内で `AutoRemediate` を `false` にし、`JobId` に対して `Action` を `Delete` に設定してエンドポイントから起動ジョブを削除します。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.keeper.io/keeperpam/jp/endpoint-privilege-manager/policies/policy-examples/enable-and-start-the-watchdog-service.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
