From 44aad1515aa41550f8313e7c61bcd33c24950710 Mon Sep 17 00:00:00 2001 From: Tejas Kokje Date: Thu, 2 Jul 2020 08:41:36 +0000 Subject: [PATCH] + service: Adding freebsd arm support --- go.mod | 2 +- go.sum | 4 ++-- home/service.go | 15 +++++++++++++++ util/helpers.go | 9 +++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index eb03f550..61657bcb 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/fsnotify/fsnotify v1.4.7 github.com/gobuffalo/packr v1.30.1 github.com/joomcode/errorx v1.0.1 - github.com/kardianos/service v1.0.0 + github.com/kardianos/service v1.1.0 github.com/krolaw/dhcp4 v0.0.0-20180925202202-7cead472c414 github.com/miekg/dns v1.1.29 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 19938814..805d39be 100644 --- a/go.sum +++ b/go.sum @@ -57,8 +57,8 @@ github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/joomcode/errorx v1.0.1 h1:CalpDWz14ZHd68fIqluJasJosAewpz2TFaJALrUxjrk= github.com/joomcode/errorx v1.0.1/go.mod h1:kgco15ekB6cs+4Xjzo7SPeXzx38PbJzBwbnu9qfVNHQ= -github.com/kardianos/service v1.0.0 h1:HgQS3mFfOlyntWX8Oke98JcJLqt1DBcHR4kxShpYef0= -github.com/kardianos/service v1.0.0/go.mod h1:8CzDhVuCuugtsHyZoTvsOBuvonN/UDBvl0kH+BUxvbo= +github.com/kardianos/service v1.1.0 h1:QV2SiEeWK42P0aEmGcsAgjApw/lRxkwopvT+Gu6t1/0= +github.com/kardianos/service v1.1.0/go.mod h1:RrJI2xn5vve/r32U5suTbeaSGoMU6GbNPoj36CVYcHc= github.com/karrick/godirwalk v1.10.12 h1:BqUm+LuJcXjGv1d2mj3gBiQyrQ57a0rYoAmhvJQ7RDU= github.com/karrick/godirwalk v1.10.12/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= diff --git a/home/service.go b/home/service.go index 05804d63..21c9cfc6 100644 --- a/home/service.go +++ b/home/service.go @@ -272,6 +272,8 @@ func configureService(c *service.Config) { // On OpenWrt we're using a different type of sysvScript if util.IsOpenWrt() { c.Option["SysvScript"] = openWrtScript + } else if util.IsFreeBSD() { + c.Option["SysvScript"] = freeBSDScript } } @@ -493,3 +495,16 @@ status() { fi } ` +const freeBSDScript = `#!/bin/sh +# PROVIDE: {{.Name}} +# REQUIRE: networking +# KEYWORD: shutdown +. /etc/rc.subr +name="{{.Name}}" +{{.Name}}_env="IS_DAEMON=1" +{{.Name}}_user="root" +pidfile="/var/run/${name}.pid" +command="/usr/sbin/daemon" +command_args="-P ${pidfile} -r -f {{.WorkingDirectory}}/{{.Name}}" +run_rc_command "$1" +` diff --git a/util/helpers.go b/util/helpers.go index b32ac456..08afa3f1 100644 --- a/util/helpers.go +++ b/util/helpers.go @@ -92,3 +92,12 @@ func IsOpenWrt() bool { return strings.Contains(string(body), "OpenWrt") } + +// IsFreeBSD checks if OS is FreeBSD +func IsFreeBSD() bool { + if runtime.GOOS == "freebsd" { + return true + } + + return false +}