Skip to content

Commit

Permalink
run vtun with s6
Browse files Browse the repository at this point in the history
  • Loading branch information
USA-RedDragon committed Apr 12, 2024
1 parent cc7a37e commit 1bfc80a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 80 deletions.
18 changes: 0 additions & 18 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ func runServer(cmd *cobra.Command, _ []string) error {

olsrdExitedChan := olsrd.Run(ctx)

vtunExitedChan := make(chan struct{})
if !config.DisableVTun {
vtunExitedChan = vtun.Run(ctx)
}

// Start the metrics server
go metrics.CreateMetricsServer(config, cmd.Root().Version)
log.Printf("Metrics server started")
Expand Down Expand Up @@ -147,19 +142,6 @@ func runServer(cmd *cobra.Command, _ []string) error {
}
})

if !config.DisableVTun {
errGrp.Go(func() error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
select {
case <-ctx.Done():
return fmt.Errorf("vtund did not exit in time")
case <-vtunExitedChan:
return nil
}
})
}

errGrp.Go(func() error {
return wireguardManager.Stop()
})
Expand Down
37 changes: 37 additions & 0 deletions internal/vtun/reload.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
package vtun

import (
"os"
"strconv"
"syscall"

"github.com/USA-RedDragon/aredn-manager/internal/db/models"
"gorm.io/gorm"
)

// This file will run vtund
const (
pidFile = "/usr/var/run/vtund.pid"
)

func Reload() error {
// Read the PID file
pidBytes, err := os.ReadFile(pidFile)
if err != nil {
return err
}
pidStr := string(pidBytes)
pid, err := strconv.ParseInt(pidStr, 10, 64)
if err != nil {
return err
}
return syscall.Kill(int(pid), syscall.SIGHUP)
}

func ReloadAllClients(db *gorm.DB, watcher *ClientWatcher) error {
tunnels, err := models.ListClientTunnels(db)
if err != nil {
Expand All @@ -16,3 +39,17 @@ func ReloadAllClients(db *gorm.DB, watcher *ClientWatcher) error {
}
return nil
}

func IsRunning() bool {
pidBytes, err := os.ReadFile(pidFile)
if err != nil {
return false
}
pidStr := string(pidBytes)
pid, err := strconv.ParseInt(pidStr, 10, 64)
if err != nil {
return false
}
err = syscall.Kill(int(pid), 0)
return err == nil
}
62 changes: 0 additions & 62 deletions internal/vtun/run.go

This file was deleted.

0 comments on commit 1bfc80a

Please sign in to comment.