Dockerによる起動
intdash Edge Agent 2は、Dockerイメージを使って起動することも可能です。 Amazon ECR Public Galleryで配布されているイメージ を使用してください。
使用方法は以下のとおりです。
準備: 設定ファイルを用意する
intdash Edge Agent 2のデフォルトの設定を書き出し、ホストマシンにファイルとして保存します。
$ docker run --rm public.ecr.aws/aptpod/intdash-edge-agent2 intdash-agentctl config-file show --default >/tmp/agent.yaml
設定を編集します。
$ vi /tmp/agent.yaml
設定の詳細については、intdash Edge Agent 2設定一覧 を参照してください。
ホストマシンがLinuxの場合は、ホストマシン側で以下のように agent.yaml
のパーミッションを変更します。
$ chmod 666 /tmp/agent.yaml
intdash Edge Agent 2を起動する
intdash Edge Agent 2を実行するため、2つのコンテナを起動します。 以下のいずれかの方法で起動してください:
docker runで起動する場合
intdash Edge Agent 2のデーモンとストリーマーをそれぞれ起動します。
デーモンを起動する
準備: 設定ファイルを用意する で作成した agent.yaml
をバインドマウントしてデーモンを起動します。
環境変数を使って接続先サーバーや認証に関する情報を上書きすることができます。
$ docker run \
--mount type=volume,src=intdash-edge-agent2-run,dst=/var/run/intdash \
--mount type=volume,src=intdash-edge-agent2-lib,dst=/var/lib/intdash \
--mount type=bind,src=/tmp/agent.yaml,dst=/var/lib/intdash/agent.yaml \
--network host \
--env AGENT_INTDASH_SERVER_URL=https://xxxxx.intdash.jp \
--env AGENT_INTDASH_PROJECT_UUID=00000000-0000-0000-0000-000000000000 \
--env AGENT_INTDASH_EDGE_UUID=03ace3b1-d208-4fc3-xxxx-xxxxxxxxxxxx \
--env AGENT_INTDASH_CLIENT_SECRET=sEh9ZHP..........................iBn5fn_eFM.EXAMPLE \
public.ecr.aws/aptpod/intdash-edge-agent2 intdash-agentd serve
設定を変更する(オプション)
デーモン起動後に設定を変更したい場合は、以下のようなコマンドで変更することができます。
アップストリームの設定:
$ docker run \
--mount type=volume,src=intdash-edge-agent2-run,dst=/var/run/intdash \
--mount type=volume,src=intdash-edge-agent2-lib,dst=/var/lib/intdash \
--mount type=bind,src=/tmp/agent.yaml,dst=/var/lib/intdash/agent.yaml \
--network host \
--rm public.ecr.aws/aptpod/intdash-edge-agent2 intdash-agentctl \
config upstream --create '
id: sample-upstream
'
デバイスコネクターIPCの設定:
$ docker run \
--mount type=volume,src=intdash-edge-agent2-run,dst=/var/run/intdash \
--mount type=volume,src=intdash-edge-agent2-lib,dst=/var/lib/intdash \
--mount type=bind,src=/tmp/agent.yaml,dst=/var/lib/intdash/agent.yaml \
--network host \
--rm public.ecr.aws/aptpod/intdash-edge-agent2 intdash-agentctl \
config device-connector upstream --create '
id: up-hello
data_name_prefix: v1/1/
dest_ids:
- sample-upstream
format: iscp-v2-compat
ipc:
type: fifo
path: /var/run/intdash/up-hello.fifo
'
ストリーマーを起動する
同様に、以下のコマンドでストリーマーも起動します。
$ docker run \
--name intdash-agentctl \
--mount type=volume,src=intdash-edge-agent2-run,dst=/var/run/intdash \
--mount type=volume,src=intdash-edge-agent2-lib,dst=/var/lib/intdash \
--mount type=bind,src=/tmp/agent.yaml,dst=/var/lib/intdash/agent.yaml \
--network host \
--rm public.ecr.aws/aptpod/intdash-edge-agent2 intdash-agentctl run
FIFO にデータを書き込む
ストリーマーの実行中にFIFOにデータを書き込むことで、サーバーにデータを送信できます。
以下は、FIFOにデータを書き込む例です(FIFOとして/var/run/intdash/up-hello.fifo
を使用する設定になっているものとします)。
$ docker exec -it $(docker ps -q --filter "name=intdash-agentctl") /bin/bash
$ echo -en \
"\xd2\x04\x00\x00\x15\xcd\x5b\x07\x06\x00\x02\x00\x05\x00\x00\x00\x73\x74\x72\x69\x6e\x67\x61\x62\x48\x65\x6c\x6c\x6f" \
>/var/run/intdash/up-hello.fifo
または、コンテナの外からFIFOにデータを書き込むこともできます。 以下の例では、別のコンテナで device-connector-intdash を実行して、そこからFIFOにデータを書き込んでいます。
$ docker run \
--mount type=volume,src=intdash-edge-agent2-run,dst=/var/run/intdash \
-e DC_REPEAT_PROCESS_SRC_CONF_COMMAND='echo "hello intdash!"' \
-e DC_REPEAT_PROCESS_SRC_CONF_INTERVAL_MS=1000 \
-e DC_ISCP_V2_COMPAT_FILTER_CONF_CONVERT_RULE_STRING_NAME=hello \
-e DC_PRINT_LOG_FILTER_CONF_TAG=hello \
-e DC_FILE_SINK_CONF_PATH=/var/run/intdash/up-hello.fifo \
--rm public.ecr.aws/aptpod/device-connector-intdash --config /etc/dc_conf/repeat_process_string.yml
docker composeで起動する場合
docker composeを使ってデーモンとストリーマーをまとめて起動します。
docker-compose.ymlを作成する
以下の例のようにdocker-compose.ymlを作成します。
ここでは、 準備: 設定ファイルを用意する で作成した設定ファイル agent.yaml
をバインドマウントしてデーモンとストリーマーを起動するよう設定しています。
$ cat << EOF > docker-compose.yml
version: '3'
services:
intdash-agentd:
image: public.ecr.aws/aptpod/intdash-edge-agent2
container_name: intdash-agentd
healthcheck:
test: intdash-agentd ping
interval: 1s
timeout: 5s
retries: 3
start_period: 60s
command: intdash-agentd serve
environment:
# You can override the credentials with environment variables
- AGENT_INTDASH_SERVER_URL=https://xxxxx.intdash.jp
- AGENT_INTDASH_PROJECT_UUID=00000000-0000-0000-0000-000000000000
- AGENT_INTDASH_EDGE_UUID=03ace3b1-d208-4fc3-xxxx-xxxxxxxxxxxx
- AGENT_INTDASH_CLIENT_SECRET=sEh9ZHP..........................iBn5fn_eFM.EXAMPLE
stop_grace_period: 60s
volumes:
- intdash-edge-agent2-run:/var/run/intdash
- intdash-edge-agent2-lib:/var/lib/intdash
- /tmp/agent.yaml:/var/lib/intdash/agent.yaml
networks:
- intdash
intdash-agentctl:
image: public.ecr.aws/aptpod/intdash-edge-agent2
container_name: intdash-agentctl
depends_on:
intdash-agentd:
condition: service_healthy
healthcheck:
test: pidof intdash-agent-streamer
interval: 1s
timeout: 1s
retries: 1
start_period: 10s
command: intdash-agentctl run --address intdash-agentd:50051
stop_grace_period: 30s
volumes:
- intdash-edge-agent2-run:/var/run/intdash
- intdash-edge-agent2-lib:/var/lib/intdash
- /tmp/agent.yaml:/var/lib/intdash/agent.yaml
networks:
- intdash
volumes:
intdash-edge-agent2-run:
name: intdash-edge-agent2-run
intdash-edge-agent2-lib:
name: intdash-edge-agent2-lib
networks:
intdash:
EOF
コンテナを起動する
以下のコマンドでコンテナを起動します。
$ docker compose up
FIFOにデータを書き込む
ストリーマーの実行中にFIFOにデータを書き込むことで、サーバーにデータを送信できます。 FIFO にデータを書き込む の例を参照してください。