Skip to content

Commit

Permalink
add vpp-agent-init
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Lavor <[email protected]>
  • Loading branch information
VladoLavor committed May 29, 2019
1 parent c7890f3 commit 6c393b0
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 195 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ agent:
install:
@echo "=> installing ${VERSION}"
go install -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} ./cmd/vpp-agent
go install -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} ./cmd/vpp-agent-init
go install -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} ./cmd/agentctl

cmd:
@echo "=> building ${VERSION}"
cd cmd/vpp-agent && go build -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd cmd/vpp-agent-init && go build -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd cmd/agentctl && go build -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}

clean-cmd:
@echo "=> cleaning command binaries"
rm -f ./cmd/vpp-agent/vpp-agent
rm -f ./cmd/vpp-agent/vpp-agent-init
rm -f ./cmd/agentctl/agentctl

examples:
Expand Down
30 changes: 30 additions & 0 deletions cmd/vpp-agent-init/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2019 Cisco and/or its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package vpp-agent-init starts supervisor plugin managing other processes
// (VPP-Agent, VPP, ...)

package main

import (
"github.com/ligato/cn-infra/agent"
sv "github.com/ligato/cn-infra/exec/supervisor"
)

func main() {
a := agent.NewAgent(agent.AllPlugins(sv.NewPlugin()))
if err := a.Run(); err != nil {
panic(err)
}
}
10 changes: 5 additions & 5 deletions docker/dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ RUN apt-get update \
iputils-ping \
make \
patch \
python \
sudo \
supervisor \
unzip \
wget \
&& rm -rf /var/lib/apt/lists/*
Expand Down Expand Up @@ -71,11 +69,11 @@ COPY \
./docker/dev/etcd.conf \
./docker/dev/logs.conf \
./docker/dev/vpp-ifplugin.conf \
./docker/dev/supervisor.conf \
/opt/vpp-agent/dev/

COPY ./docker/dev/vpp.conf /etc/vpp/vpp.conf
COPY ./docker/dev/supervisord.conf /etc/supervisord/supervisord.conf
COPY ./docker/dev/supervisord_kill.py /usr/bin/
COPY ./docker/dev/init_hook.sh /usr/bin/

# Build agent
WORKDIR $GOPATH/src/github.com/ligato/vpp-agent
Expand All @@ -91,6 +89,8 @@ COPY . ./

RUN VERSION=$VERSION COMMIT=$COMMIT DATE=$DATE make install

ENV SUPERVISOR_CONFIG=/opt/vpp-agent/dev/supervisor.conf

# run supervisor as the default executable
CMD rm -f /dev/shm/db /dev/shm/global_vm /dev/shm/vpe-api && \
exec /usr/bin/supervisord -c /etc/supervisord/supervisord.conf
exec vpp-agent-init
17 changes: 17 additions & 0 deletions docker/dev/init_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

terminate_process () {
PID=$(pidof $1)
if [[ ${PID} != "" ]]; then
kill ${PID}
echo "process $1 terminated"
fi
}

if [[ "${SUPERVISOR_PROCESS_NAME}" = "agent" && "${SUPERVISOR_PROCESS_STATE}" = "terminated" ]]; then
terminate_process vpp-agent-init
fi

if [[ "${SUPERVISOR_PROCESS_NAME}" = "vpp" && "${SUPERVISOR_PROCESS_STATE}" = "terminated" ]]; then
terminate_process vpp-agent-init
fi
11 changes: 11 additions & 0 deletions docker/dev/supervisor.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
programs:
- name: "vpp"
executable-path: "/usr/bin/vpp"
executable-args: ["-c", "/etc/vpp/vpp.conf"]
logfile-path: "/var/log/supervisord.log"
- name: "agent"
executable-path: "/go/bin/vpp-agent"
executable-args: ["--config-dir=/opt/vpp-agent/dev"]
logfile-path: "/var/log/supervisord.log"
hooks:
- cmd: "/usr/bin/init_hook.sh"
26 changes: 0 additions & 26 deletions docker/dev/supervisord.conf

This file was deleted.

66 changes: 0 additions & 66 deletions docker/dev/supervisord_kill.py

This file was deleted.

12 changes: 6 additions & 6 deletions docker/prod/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ RUN apt-get update \
libmbedx509-0 \
libnuma1 \
openssl \
# other
python \
supervisor \
&& rm -rf /var/lib/apt/lists/*

# install vpp
Expand All @@ -42,15 +39,18 @@ COPY --from=base / /
COPY --from=devimg \
/go/bin/agentctl \
/go/bin/vpp-agent \
/go/bin/vpp-agent-init \
/bin/

# Copy configs
COPY etcd.conf /opt/vpp-agent/dev/
COPY supervisor.conf /opt/vpp-agent/dev/
COPY vpp.conf /etc/vpp/vpp.conf
COPY supervisord.conf /etc/supervisord/supervisord.conf
COPY supervisord_kill.py /usr/bin/
COPY init_hook.sh /usr/bin/

WORKDIR /root/

ENV SUPERVISOR_CONFIG=/opt/vpp-agent/dev/supervisor.conf

CMD rm -f /dev/shm/db /dev/shm/global_vm /dev/shm/vpe-api && \
exec /usr/bin/supervisord -c /etc/supervisord/supervisord.conf
exec vpp-agent-init
17 changes: 17 additions & 0 deletions docker/prod/init_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

terminate_process () {
PID=$(pidof $1)
if [[ ${PID} != "" ]]; then
kill ${PID}
echo "process $1 terminated"
fi
}

if [[ "${SUPERVISOR_PROCESS_NAME}" = "agent" && "${SUPERVISOR_PROCESS_STATE}" = "terminated" ]]; then
terminate_process vpp-agent-init
fi

if [[ "${SUPERVISOR_PROCESS_NAME}" = "vpp" && "${SUPERVISOR_PROCESS_STATE}" = "terminated" ]]; then
terminate_process vpp-agent-init
fi
11 changes: 11 additions & 0 deletions docker/prod/supervisor.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
programs:
- name: "vpp"
executable-path: "/usr/bin/vpp"
executable-args: ["-c", "/etc/vpp/vpp.conf"]
logfile-path: "/var/log/supervisord.log"
- name: "agent"
executable-path: "/bin/vpp-agent"
executable-args: ["--config-dir=/opt/vpp-agent/dev"]
logfile-path: "/var/log/supervisord.log"
hooks:
- cmd: "/usr/bin/init_hook.sh"
26 changes: 0 additions & 26 deletions docker/prod/supervisord.conf

This file was deleted.

66 changes: 0 additions & 66 deletions docker/prod/supervisord_kill.py

This file was deleted.

0 comments on commit 6c393b0

Please sign in to comment.