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 @- <", - "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/go.mod b/go.mod index bbb6670..d7da793 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/mainflux/mainflux v0.0.0-20230726142711-2b78902e0170 github.com/prometheus/client_golang v1.16.0 github.com/spf13/cobra v1.7.0 + github.com/spf13/pflag v1.0.5 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0 go.opentelemetry.io/contrib/propagators/jaeger v1.17.0 @@ -37,7 +38,6 @@ require ( github.com/prometheus/client_model v0.4.0 // indirect github.com/prometheus/common v0.44.0 // indirect github.com/prometheus/procfs v0.11.1 // indirect - github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.4.2 // indirect go.opentelemetry.io/otel/metric v1.16.0 // indirect golang.org/x/net v0.12.0 // indirect diff --git a/pkg/clients/grpc/connect.go b/pkg/clients/grpc/connect.go index 3a49ec1..14835ef 100644 --- a/pkg/clients/grpc/connect.go +++ b/pkg/clients/grpc/connect.go @@ -18,8 +18,8 @@ var ( type Config struct { ClientTLS bool `env:"CLIENT_TLS" envDefault:"false"` CACerts string `env:"CA_CERTS" envDefault:""` - URL string `env:"URL" envDefault:"localhost:7002"` - Timeout time.Duration `env:"TIMEOUT" envDefault:"1s"` + URL string `env:"URL" envDefault:"localhost:7020"` + Timeout time.Duration `env:"TIMEOUT" envDefault:"60s"` } type Client interface { diff --git a/alpine/cocos-agent.service b/systemd/cocos-agent.service similarity index 59% rename from alpine/cocos-agent.service rename to systemd/cocos-agent.service index 7717f24..e3cd9d7 100644 --- a/alpine/cocos-agent.service +++ b/systemd/cocos-agent.service @@ -6,14 +6,16 @@ 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_HOST=10.0.2.15 +Environment=AGENT_GRPC_PORT=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