

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 執行 Amazon Kinesis Video Streams Edge 代理程式作為原生程序
<a name="gs-run"></a>

將 Amazon Kinesis Video Streams Edge Agent 設定為系統化服務。此為選用步驟。

`systemd` 是 Linux 裝置上的系統和服務管理員。 `systemd`是管理程序的建議方式，因為它會在應用程式發生錯誤或執行應用程式的裝置斷電時重新啟動 Amazon Kinesis Video Streams Edge Agent。

請執行下列操作：

**執行 Amazon Kinesis Video Streams Edge 代理程式作為原生程序**

1. 在 中建立新的檔案`/etc/systemd/system`，並將其命名為 `{{aws.kinesisvideo.edge-runtime-agent}}.service`。

   貼上下列項目：

   ```
   [Unit]
   Description=AWS Kinesis Video Streams edge agent
   After=network.target
   StartLimitBurst={{3}}
   StartLimitInterval={{30}}
   
   [Service]
   Type=simple
   Restart={{on-failure}}
   RestartSec={{10}}
   WorkingDirectory=/{{download-location}}/kvs-edge-agent/KvsEdgeComponent/artifacts/aws.kinesisvideo.KvsEdgeComponent/{{EdgeAgentVersion}}
   Environment="GST_PLUGIN_PATH=/{{download-location}}/kvs-edge-agent/KvsEdgeComponent/artifacts/aws.kinesisvideo.KvsEdgeComponent/{{EdgeAgentVersion}}"
   Environment="LD_LIBRARY_PATH=/{{download-location}}/kvs-edge-agent/KvsEdgeComponent/artifacts/aws.kinesisvideo.KvsEdgeComponent/{{EdgeAgentVersion}}/lib"
   {{...}}
   Environment="AWS_IOT_CORE_DATA_ATS_ENDPOINT={{data-account-specific-prefix}}.iot.{{aws-region}}.amazonaws.com"
   ExecStart=/usr/lib/jvm/{{java-11-amazon-corretto}}/bin/java --add-opens java.base/jdk.internal.misc=ALL-UNNAMED -Dio.netty.tryReflectionSetAccessible=true -cp kvs-edge-agent.jar:libs.jar com.amazonaws.kinesisvideo.edge.controller.ControllerApp
   
   [Install]
   WantedBy=multi-user.target
   ```

   如需`systemd`服務組態檔案接受之參數的詳細資訊，請參閱 [文件](https://www.freedesktop.org/software/systemd/man/systemd.unit.html#%5BUnit%5D%20Section%20Options)。
**注意**  
在`...`位置新增必要的環境變數，如 中所指定[建置 Amazon Kinesis Video Streams Edge 代理程式](gs-build-agent.md)。

1. 重新載入服務檔案以包含新服務。

   輸入 `sudo systemctl daemon-reload`。

1. 啟動 服務。

   輸入 `sudo systemctl start {{aws.kinesisvideo.edge-runtime-agent}}.service`。

1. 檢查 Amazon Kinesis Video Streams Edge Agent 服務的狀態，以確認是否正在執行。

   輸入 `sudo systemctl status {{aws.kinesisvideo.edge-runtime-agent}}.service`。

   以下是您將看到的輸出範例。

   ```
   aws.kinesisvideo.edge-runtime-agent.service - AWS Kinesis Video Streams edge agent
        Loaded: loaded (/etc/systemd/system/aws.kinesisvideo.edge-runtime-agent.service; disabled; vendor preset: enabled)
        Active: active (running) since Thu 2023-06-08 19:15:02 UTC; 6s ago
      Main PID: 506483 (java)
         Tasks: 23 (limit: 9518)
        Memory: 77.5M
           CPU: 4.214s
        CGroup: /system.slice/aws.kinesisvideo.edge-runtime-agent.service
                └─506483 /usr/lib/jvm/java-11-amazon-corretto/bin/java -cp kvs-edge-agent.jar:libs.jar com.amazonaws.kinesisvideo.edge.controller.ControllerApp
   ```

1. 檢查日誌是否有任何錯誤。

   輸入 `journalctl -e -u aws.kinesisvideo.edge-runtime-agent.service`。

1. `systemctl --help` 輸入 以取得使用 管理程序的完整選項清單`systemctl`。

   以下是一些管理 Amazon Kinesis Video Streams Edge Agent 的常見命令：
   + 若要重新啟動，請輸入 `sudo systemctl restart {{aws.kinesisvideo.edge-runtime-agent}}.service`。
   + 若要停止，請輸入 `sudo systemctl stop {{aws.kinesisvideo.edge-runtime-agent}}.service`。
   + 若要在每次裝置重新啟動時自動啟動，請輸入 `sudo systemctl enable {{aws.kinesisvideo.edge-runtime-agent}}.service`。