Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace supervisord with vpp-agent-init #1318

Merged
merged 5 commits into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.DefaultPlugin))
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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Script is missing old functionality provided by RETAIN_SUPERVISOR variable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, however, hook scripts are started in a dedicated environment so RETAIN_SUPERIVSOR set to the docker environment would not be passed to the script anyway. We would need it supported in the supervisor plugin I guess.

But we can live without it now, didn't we? The hook script takes care of the termination of the init. Remove the hook from the supervisor.conf and we have basically the same functionality the RETAIN_SUPERVISOR provides. What do you think?

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
ondrej-fabry marked this conversation as resolved.
Show resolved Hide resolved
fi

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

This file was deleted.

Loading