From c3443c5375f68bae07ebf52ad0b94af9d03d17f7 Mon Sep 17 00:00:00 2001 From: Darko Draskovic Date: Fri, 18 Aug 2023 13:14:39 +0200 Subject: [PATCH 1/3] Refactor README to simplify VM setup procedure Signed-off-by: Darko Draskovic --- alpine/cocos-agent.service | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/alpine/cocos-agent.service b/alpine/cocos-agent.service index 7717f24..92fb0a4 100644 --- a/alpine/cocos-agent.service +++ b/alpine/cocos-agent.service @@ -6,14 +6,15 @@ After=network.target StandardOutput=file:/var/log/cocos/agent.stdout StandardError=file:/var/log/cocos/agent.stderr -ExecStartPre=ip link set dev enp0s2 up -ExecStartPre=dhclient enp0s2 +Environment=NETWORK_INTERFACE=enp0s3 +Environment=AGENT_GRPC_ADDR=10.0.2.15:7002 +Environment=AGENT_LOG_LEVEL=info + +ExecStartPre=ip link set dev $NETWORK_INTERFACE up +ExecStartPre=dhclient $NETWORK_INTERFACE ExecStartPre=mkdir -p /var/log/cocos ExecStart=/cocos/agent -Environment=AGENT_LOG_LEVEL=info -Environment=AGENT_GRPC_ADDR=10.0.2.15:7002 - [Install] WantedBy=default.target From d70d9fe7e7f12babaa22d3d74d7dc75d0b5ef280 Mon Sep 17 00:00:00 2001 From: Darko Draskovic Date: Fri, 18 Aug 2023 13:37:13 +0200 Subject: [PATCH 2/3] Remove alpine and packer related files Signed-off-by: Darko Draskovic --- alpine/agent | 25 ---------- alpine/packer/script.sh | 8 --- alpine/packer/template.json | 66 ------------------------- {alpine => systemd}/cocos-agent.service | 3 +- 4 files changed, 2 insertions(+), 100 deletions(-) delete mode 100755 alpine/agent delete mode 100644 alpine/packer/script.sh delete mode 100644 alpine/packer/template.json rename {alpine => systemd}/cocos-agent.service (85%) diff --git a/alpine/agent b/alpine/agent deleted file mode 100755 index 8888f8b..0000000 --- a/alpine/agent +++ /dev/null @@ -1,25 +0,0 @@ -#!/sbin/openrc-run - -command="/cocos/agent" -command_args="" - -depend() { - need net -} - -start_pre() { - mkdir -p /run/cocos -} - -start() { - AGENT_GRPC_ADDR=$(ifconfig eth0 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1):7002 - ebegin "Starting cocos agent" - env AGENT_GRPC_ADDR="${AGENT_GRPC_ADDR}" start-stop-daemon -S -q -b -m -p /run/cocos/agent.pid -x $command -- $command_args - eend $? -} - -stop() { - ebegin "Stopping cocos agent" - start-stop-daemon -K -q -p /run/cocos/agent.pid - eend $? -} diff --git a/alpine/packer/script.sh b/alpine/packer/script.sh deleted file mode 100644 index 8a2a629..0000000 --- a/alpine/packer/script.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -# Update package repositories -apk update - -# Install curl -apk add curl - diff --git a/alpine/packer/template.json b/alpine/packer/template.json deleted file mode 100644 index cc27b5d..0000000 --- a/alpine/packer/template.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "builders": [ - { - "accelerator": "kvm", - "boot_command": [ - "root", - "setup-alpine", - "", - "asdf1234asdf1234", - "EuropeBelgrade", - "r", - "yes", - "vdasysyes" - ], - "boot_wait": "10s", - "disk_size": "768", - "format": "qcow2", - "headless": false, - "iso_checksum": "sha256:a28ec4931e2bd334b22423baac741c5a371046d0ad8da9650e6c4fcde09e4504", - "iso_url": "https://dl-cdn.alpinelinux.org/alpine/v3.18/releases/x86_64/alpine-virt-3.18.0-x86_64.iso", - "net_device": "virtio-net-pci", - "output_directory": "output-qemu", - "vm_name": "cocos-alpine.qcow2", - "qemuargs": [ - [ - "-m", - "1024" - ], - [ - "-smp", - "2" - ], - [ - "-machine", - "accel=kvm" - ], - [ - "-device", - "virtio-rng-pci" - ] - ], - "type": "qemu", - "ssh_username": "root", - "ssh_password": "asdf1234" - } - ], - "provisioners": [ - { - "execute_command": "echo 'packer' | {{.Vars}} ash '{{.Path}}'", - "scripts": [ - "script.sh" - ], - "type": "shell" - }, - { - "type": "file", - "source": "/home/darko/go/src/github.com/ultravioletrs/agent/bin/cocos-agent", - "destination": "/root/cocos-agent" - }, - { - "type": "file", - "source": "/home/darko/go/src/github.com/ultravioletrs/agent/alpine/agent", - "destination": "/etc/init.d/agent" - } - ] -} \ No newline at end of file diff --git a/alpine/cocos-agent.service b/systemd/cocos-agent.service similarity index 85% rename from alpine/cocos-agent.service rename to systemd/cocos-agent.service index 92fb0a4..e3cd9d7 100644 --- a/alpine/cocos-agent.service +++ b/systemd/cocos-agent.service @@ -7,7 +7,8 @@ StandardOutput=file:/var/log/cocos/agent.stdout StandardError=file:/var/log/cocos/agent.stderr Environment=NETWORK_INTERFACE=enp0s3 -Environment=AGENT_GRPC_ADDR=10.0.2.15:7002 +Environment=AGENT_GRPC_HOST=10.0.2.15 +Environment=AGENT_GRPC_PORT=7002 Environment=AGENT_LOG_LEVEL=info ExecStartPre=ip link set dev $NETWORK_INTERFACE up From 38558dbe53efff67c3883c53f232ebeee8b66d8e Mon Sep 17 00:00:00 2001 From: Darko Draskovic Date: Tue, 5 Sep 2023 14:58:07 +0200 Subject: [PATCH 3/3] Remove obsolete agent in VM configuration info Signed-off-by: Darko Draskovic --- README.md | 176 +----------------------------------- go.mod | 2 +- pkg/clients/grpc/connect.go | 4 +- 3 files changed, 7 insertions(+), 175 deletions(-) diff --git a/README.md b/README.md index 0c184fc..f6c3505 100644 --- a/README.md +++ b/README.md @@ -1,177 +1,9 @@ # Agent -## Build Agent +## Use Agent with Manager -To create a stand-alone `agent` executable, on the host machine, in the root of the `agent` repository run +To see how to use Agent with Manager, see (Manager's README)[https://github.com/ultravioletrs/manager]. -```sh -go build -o ./bin/agent -ldflags="-linkmode=external -extldflags=-static -s -w" cmd/agent/main.go -``` +## Use Agent with Cocos -## Copy files to virtual drive - -Log in the VM and create `/cocos` directory. Shut down `QEmu-alpine-standard-x86_64` virtual machine. - -On the host machine install [libguestfs-tools](https://libguestfs.org/). `libguestfs-tools` is "a set of tools for accessing and modifying virtual machine (VM) disk images". - -```sh -sudo apt-get install libguestfs-tools -``` - -Set path to the VM disk image: - -```sh -QCOW2_PATH=~/go/src/github.com/ultravioletrs/manager/cmd/manager/img/boot.img -``` - -Set path to the `agent` executable and its VM image path, and copy `agent` to the VM disk image. - -```sh -HOST_AGENT_BIN_PATH=~/go/src/github.com/ultravioletrs/agent/bin/agent; \ -GUEST_AGENT_BIN_PATH=/cocos/; \ -sudo virt-copy-in -a $QCOW2_PATH $HOST_AGENT_BIN_PATH $GUEST_AGENT_BIN_PATH -``` - -Copy [OpenRC](https://wiki.alpinelinux.org/wiki/OpenRC) init script to the VM disk image: - -```sh -HOST_AGENT_SCRIPT_PATH=~/go/src/github.com/ultravioletrs/agent/alpine/agent; \ -GUEST_AGENT_SCRIPT_PATH=/etc/init.d/; \ -sudo virt-copy-in -a $QCOW2_PATH $HOST_AGENT_SCRIPT_PATH $GUEST_AGENT_SCRIPT_PATH -``` - -OpenRC init script is used to start `agent` executable as a system service (daemon) on the Alpine Linux boot. - -### OpenRC - -Once the OpenRC `agent` script is copied into the `/etc/init.d/`, i.e. on the guest system, log into the guest system and run - -```sh -rc-update add agent default -``` - -and reboot. - -To see if the `agent` service (or deamon) is running, inside Alpine linux run - -```sh -ps aux | grep agent -``` - -To see if the ports are correctly configured, inside Alpine linux, i.e. _guest machine_, run - -```sh -netstat -tuln | grep 9031 -netstat -tuln | grep 7002 -``` - -In the _host machine_, you can check if the ports of the guest machine are open and reachable from the host machine with - -```sh -nc -zv 192.168.122.251 9031 -nc -zv 192.168.122.251 7002 -``` - -NB: to find out `192.168.122.251`, i.e. the concrete address of the guest machine, you need to - -```sh -ip addr show eth0 -``` - -in the host machine and - -```sh -ip addr show virbr0 -``` - -on the host machine. In both cases, you will get something like inet `192.168.122.x/24`, where `192.168.122` stands for the network part of the machine's virtual network interface address. - -### cURL - -To check if the `agent` deamon is responding to the requests, run on the host - -```sh -GUEST_ADDR=192.168.122.251:9031 -``` - -To run a computation - -```sh -curl -sSi -X POST ${GUEST_ADDR}/run -H "Content-Type: application/json" -d @- <