Skip to content

Commit

Permalink
NET-654: Docker Netclient AutoUpgrade Fixes (#608)
Browse files Browse the repository at this point in the history
* install netclient in docker and sleep infinte

* start daemon and then join

* add openrc to docker alpine

* enable openrc on docker

* set to older version to test

* testing commit

* hardrestart on pull to test openrc

* run in openrc in foreground with supervision

* set svc name

* revert version

* sigkill for openrc restart

* add daemon respawn args

* revert test changes

* remove debug changes

* rc status cmd
  • Loading branch information
abhishek9686 authored Oct 18, 2023
1 parent 10d6327 commit 71c007e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ FROM alpine:3.18.4

WORKDIR /root/

RUN apk add --no-cache --update bash libmnl gcompat openresolv iproute2
RUN apk add --no-cache --update bash libmnl gcompat openresolv iproute2 openrc \
&& mkdir -p /run/openrc \
&& touch /run/openrc/softlevel
RUN apk add iptables ip6tables \
&& mv -v /sbin/ip6tables /sbin/ip6tables-disabled \
&& cp -v /sbin/ip6tables-nft /sbin/ip6tables
Expand Down
10 changes: 7 additions & 3 deletions daemon/openrc_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package daemon
import (
"errors"
"os"
"syscall"

"github.com/gravitl/netclient/ncutils"
"golang.org/x/exp/slog"
Expand All @@ -14,16 +15,20 @@ func setupOpenRC() error {
description="netclient daemon"
pidfile="/var/run/netclient.pid"
RC_SVCNAME="netclient"
command="/sbin/netclient"
command_args="daemon"
command_background="true"
command_user="root"
supervisor="supervise-daemon"
respawn_max=3
respawn_period=10
output_log="/var/log/netclient.log"
error_log="/var/log/netclient.log"
depend() {
need net
after firewall
}
`
bytes := []byte(service)
if err := os.WriteFile("/etc/init.d/netclient", bytes, 0755); err != nil {
Expand All @@ -49,8 +54,7 @@ func stopOpenRC() error {

func restartOpenRC() error {
slog.Info("restarting netclient service")
_, err := ncutils.RunCmd("/sbin/rc-service netclient restart", false)
return err
return signalDaemon(syscall.SIGTERM)
}

func removeOpenRC() error {
Expand Down
12 changes: 6 additions & 6 deletions scripts/netclient.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

sh -c rc-status
#Define cleanup
cleanup() {
nets=($(wg show interfaces))
Expand Down Expand Up @@ -48,12 +49,11 @@ if [ "${IS_STATIC}" != "" ];then
STATIC_CMD="-i ${IS_STATIC}"
fi

/root/netclient join $TOKEN_CMD $PORT_CMD $ENDPOINT_CMD $MTU_CMD $HOSTNAME_CMD $STATIC_CMD
if [ $? -ne 0 ]; then { echo "Failed to join, quitting." ; exit 1; } fi

echo "[netclient] Starting netclient daemon"
/root/netclient install
wait $!

/root/netclient daemon &
/root/netclient join $TOKEN_CMD $PORT_CMD $ENDPOINT_CMD $MTU_CMD $HOSTNAME_CMD $STATIC_CMD
if [ $? -ne 0 ]; then { echo "Failed to join, quitting." ; exit 1; } fi

wait $!
echo "[netclient] exiting"
sleep infinity

0 comments on commit 71c007e

Please sign in to comment.