mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
Add Makefile targets for build and copy to VM agent
Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>
This commit is contained in:
@@ -0,0 +1 @@
|
||||
build
|
||||
@@ -1,5 +1,42 @@
|
||||
docker_mfxkit:
|
||||
docker build --no-cache --tag=mainflux/mfxkit -f docker/Dockerfile .
|
||||
BUILD_DIR = build
|
||||
SERVICES = agent
|
||||
CGO_ENABLED ?= 0
|
||||
GOARCH ?= amd64
|
||||
VERSION ?= $(shell git describe --abbrev=0 --tags)
|
||||
COMMIT ?= $(shell git rev-parse HEAD)
|
||||
TIME ?= $(shell date +%F_%T)
|
||||
|
||||
run:
|
||||
docker-compose -f docker/docker-compose.yml up
|
||||
define compile_service
|
||||
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) \
|
||||
go build -mod=vendor -ldflags "-s -w \
|
||||
-X 'github.com/ultravioletrs/cocos/internal/http.BuildTime=$(TIME)' \
|
||||
-X 'github.com/ultravioletrs/cocos/internal/http.Version=$(VERSION)' \
|
||||
-X 'github.com/ultravioletrs/cocos/internal/http.Commit=$(COMMIT)'" \
|
||||
-o ${BUILD_DIR}/cocos-$(1) cmd/$(1)/main.go
|
||||
endef
|
||||
|
||||
all: $(SERVICES)
|
||||
|
||||
$(SERVICES):
|
||||
$(call compile_service,$(@))
|
||||
|
||||
|
||||
QCOW2_PATH = ~/go/src/github.com/ultravioletrs/manager/cmd/manager/img/boot.img
|
||||
HOST_AGENT_PATH = ~/ultravioletrs/agent/build/cocos-agent
|
||||
GUEST_AGENT_PATH = /root/agent
|
||||
HOST_AGENT_SH_PATH = ~/go/src/github.com/ultravioletrs/agent/alpine/agent.sh
|
||||
GUEST_AGENT_SH_PATH = /root/agent/
|
||||
|
||||
# Copy the agent binary to the guest VM
|
||||
copy-agent:
|
||||
sudo virt-copy-in -a $(QCOW2_PATH) $(HOST_AGENT_PATH) $(GUEST_AGENT_PATH)
|
||||
|
||||
# Copy the agent init sh script to the guest VM
|
||||
copy-agent-sh:
|
||||
sudo virt-copy-in -a $(QCOW2_PATH) $(HOST_AGENT_SH_PATH) $(GUEST_AGENT_SH_PATH)
|
||||
|
||||
# docker_mfxkit:
|
||||
# docker build --no-cache --tag=mainflux/mfxkit -f docker/Dockerfile .
|
||||
|
||||
# run:
|
||||
# docker-compose -f docker/docker-compose.yml up
|
||||
|
||||
@@ -46,3 +46,21 @@ To see the change in action, run
|
||||
```
|
||||
curl -i -X POST -H "Content-Type: application/json" localhost:9022/mfxkit -d '{"secret":"secret2"}'
|
||||
```
|
||||
|
||||
## Alpine linux
|
||||
|
||||
To schedula a task _via_ `cron`
|
||||
|
||||
```sh
|
||||
crontab -e
|
||||
```
|
||||
|
||||
and enter this line in order to execute `agent.sh` script every minute (that's `cron`'s minimal repeating delay of execution):
|
||||
```
|
||||
* * * * * sh /root/agent/agent.sh
|
||||
```
|
||||
|
||||
To check whether the program is executing, run
|
||||
```sh
|
||||
cat /var/log/messages
|
||||
```
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
AGENT_NAME="cocos-agent"
|
||||
AGENT_PATH="$HOME/agent/$AGENT_NAME"
|
||||
|
||||
# find the process IDs of running processes based on their name
|
||||
if pgrep -x "$AGENT_NAME" >/dev/null; then
|
||||
echo "Executable $AGENT_NAME is already running."
|
||||
else
|
||||
if [ -x "$AGENT_PATH" ]; then
|
||||
echo "Executing $AGENT_NAME..."
|
||||
"$AGENT_PATH"
|
||||
else
|
||||
echo "Executable $AGENT_NAME not found at path $AGENT_PATH."
|
||||
fi
|
||||
fi
|
||||
Reference in New Issue
Block a user