Skip to content

Commit 8961441

Browse files
committed
remove fat
1 parent c09f241 commit 8961441

File tree

9 files changed

+106
-76
lines changed

9 files changed

+106
-76
lines changed

go.mod

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ module github.com/codemodify/systemkit-service
33
go 1.13
44

55
require (
6-
github.com/codemodify/systemkit-helpers-conv v1.7.9
7-
github.com/codemodify/systemkit-helpers-os v1.7.9
8-
github.com/codemodify/systemkit-helpers-reflection v1.7.9
96
github.com/codemodify/systemkit-logging v1.8.4
107
github.com/codemodify/systemkit-service-encoders-launchd v1.0.0
11-
github.com/codemodify/systemkit-service-encoders-rc_d v1.0.0
12-
github.com/codemodify/systemkit-service-encoders-systemd v1.0.0
13-
github.com/codemodify/systemkit-service-encoders-systemv v1.0.0
14-
github.com/codemodify/systemkit-service-encoders-upstart v1.0.0
8+
github.com/codemodify/systemkit-service-encoders-rc_d v1.0.1
9+
github.com/codemodify/systemkit-service-encoders-systemd v1.0.2
10+
github.com/codemodify/systemkit-service-encoders-systemv v1.0.1
11+
github.com/codemodify/systemkit-service-encoders-upstart v1.0.1
1512
github.com/codemodify/systemkit-service-spec v1.0.1
1613
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9
1714
)

go.sum

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
github.com/codemodify/systemkit-helpers-conv v1.7.9 h1:a3MRS88pBnOauCX82xuZEnHeJSfULQm6mVl9mIfC23Q=
2-
github.com/codemodify/systemkit-helpers-conv v1.7.9/go.mod h1:yqHcvZcVmd9RPIIi49biNO9ALSY3CFTQeUnOVc1GjDY=
3-
github.com/codemodify/systemkit-helpers-os v1.7.9 h1:Z1EgPCkhj/zoZ9sKlgsx1lLw/eRvwU2h5mMWGvvyyQU=
4-
github.com/codemodify/systemkit-helpers-os v1.7.9/go.mod h1:2j8txlmkBgd4jjTz5h2nAvRPeK2D5ibE2i2g3wrOnLk=
5-
github.com/codemodify/systemkit-helpers-reflection v1.7.9 h1:vPsYvbOiEZHT+rpoXlRx14IvzsKEAkYy7Aw2QEjF/G0=
6-
github.com/codemodify/systemkit-helpers-reflection v1.7.9/go.mod h1:HunZSrygIcl5IBmnWAYoDoqvFRVu7GIUvC0/scCfPzY=
71
github.com/codemodify/systemkit-logging v1.8.4 h1:nkbj0VpnRnpI4PE4w9HNUv/ySO3A/1Y9LVeT9j+ZvGM=
82
github.com/codemodify/systemkit-logging v1.8.4/go.mod h1:29Zc9P/MnY2bgenJU9aoDszUef+Xf40b3ajtusTBC1Q=
93
github.com/codemodify/systemkit-service-encoders-launchd v1.0.0 h1:S9cgQPK9hkt+cp6Uwe0Eb3zSf7arNBqu/Ls06o43Dcw=
104
github.com/codemodify/systemkit-service-encoders-launchd v1.0.0/go.mod h1:Tylr2+OiLYhn56y8MRvlbl3WfT1rTXPtJEZGiP/1FWk=
11-
github.com/codemodify/systemkit-service-encoders-rc_d v1.0.0 h1:r+JaDxsrcbBjyGT8hRFol5YcCZNvT46dEF2AD1epFjI=
12-
github.com/codemodify/systemkit-service-encoders-rc_d v1.0.0/go.mod h1:itEzE535yOXIReXz1DR8sliY5POhHQmrZ4aC4Ad1tEk=
13-
github.com/codemodify/systemkit-service-encoders-systemd v1.0.0 h1:D6sInl0a7Lnz8NeRyHYVoYD17Zd7JdfalAvR0zySrd8=
14-
github.com/codemodify/systemkit-service-encoders-systemd v1.0.0/go.mod h1:Dt0AUUz+4AstT3MJTd0l7Vpgx+Vpo/WGLNF5LaAt63o=
15-
github.com/codemodify/systemkit-service-encoders-systemv v1.0.0 h1:/ZDlCdK9K4yviWKtNseTaMFdht/yQ/ZdRwhcVyHSGUI=
16-
github.com/codemodify/systemkit-service-encoders-systemv v1.0.0/go.mod h1:BwZ2zjABnOxflGeaLJ0qojSFyeq80VDQgLXUOIXX36c=
17-
github.com/codemodify/systemkit-service-encoders-upstart v1.0.0 h1:/63fIbsFDCIQAiY0NNiDfcB+Zh31mxxzY9KVg2ubgCU=
18-
github.com/codemodify/systemkit-service-encoders-upstart v1.0.0/go.mod h1:Oi5kzF810agTz/DJOL+v2uhaF9oC+sqkEd1WhmZCg70=
5+
github.com/codemodify/systemkit-service-encoders-rc_d v1.0.1 h1:6FpnxwhaH4LKk3a2FMGtGYI/2D0lwSzvubfptid9UE0=
6+
github.com/codemodify/systemkit-service-encoders-rc_d v1.0.1/go.mod h1:2BkmLV28VQH66vETGqr4tl07YxLmomaH5qLln3AHefI=
7+
github.com/codemodify/systemkit-service-encoders-systemd v1.0.2 h1:KBvunQ7fQBtHbwjKQKBUweiv/aTyEVObkqMEOtbufhk=
8+
github.com/codemodify/systemkit-service-encoders-systemd v1.0.2/go.mod h1:mOjsWZXg3wF9IEcovq5JCfr4aO98Ct4/AEmsmKtPpoc=
9+
github.com/codemodify/systemkit-service-encoders-systemv v1.0.1 h1:FZ4B4abQ3C9shxUmg56ahEOzfclIBVCdVqnJWaVzn+I=
10+
github.com/codemodify/systemkit-service-encoders-systemv v1.0.1/go.mod h1:snmOHK9ByvPn03jukY0ixjUokmgG9veSLNIzNBuaBKM=
11+
github.com/codemodify/systemkit-service-encoders-upstart v1.0.1 h1:oN9959zaKCfEnvPuKln3aAsU4cqRydFDI7vqrTgf7Fw=
12+
github.com/codemodify/systemkit-service-encoders-upstart v1.0.1/go.mod h1:BcJD0iLp++xhQQTSeYo5qoIa5r5eerC8igwe7PsxPyk=
1913
github.com/codemodify/systemkit-service-spec v1.0.1 h1:UHg60PsR+2blb9kqE3j+pJbHhUys6j+mQ8QprxrytBg=
2014
github.com/codemodify/systemkit-service-spec v1.0.1/go.mod h1:/GURRGinl4NxbiK+mi9RIkrsXhNkjfIaIOma5SWF4nM=
2115
github.com/groob/plist v0.0.0-20200425180238-0f631f258c01 h1:0T3XGXebqLj7zSVLng9wX9axQzTEnvj/h6eT7iLfUas=

helpers/helpers.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package helpers
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"os/exec"
7+
"os/user"
8+
)
9+
10+
func AsJSONString(i interface{}) string {
11+
bytes, err := json.Marshal(i)
12+
if err != nil {
13+
return fmt.Sprintf("ERROR: AsJSONString(), details [%s]", err.Error())
14+
}
15+
return string(bytes)
16+
}
17+
18+
func Is(err1 error, err2 error) bool {
19+
if err1 == err2 {
20+
return true
21+
}
22+
23+
if err1 != nil && err2 != nil {
24+
return err1.Error() == err2.Error()
25+
}
26+
27+
return false
28+
}
29+
30+
func ExecWithArgs(name string, args ...string) (out string, err error) {
31+
output, err := exec.Command(name, args...).CombinedOutput()
32+
return string(output), err
33+
}
34+
35+
36+
func IsRoot() bool {
37+
u, err := user.Current()
38+
39+
if err != nil {
40+
return false
41+
}
42+
43+
// On unix systems, root user either has the UID 0,
44+
// the GID 0 or both.
45+
return u.Uid == "0" || u.Gid == "0"
46+
}
47+
48+
func HomeDir(returnIfError string) string {
49+
u, err := user.Current()
50+
if err != nil {
51+
return returnIfError
52+
}
53+
54+
return u.HomeDir
55+
}

service_darwin-launchd.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ import (
99
"strconv"
1010
"strings"
1111

12-
helpersJSON "github.com/codemodify/systemkit-helpers-conv"
13-
helpersExec "github.com/codemodify/systemkit-helpers-os"
14-
helpersUser "github.com/codemodify/systemkit-helpers-os"
15-
helpersErrors "github.com/codemodify/systemkit-helpers-reflection"
1612
logging "github.com/codemodify/systemkit-logging"
1713
encoders "github.com/codemodify/systemkit-service-encoders-launchd"
1814
spec "github.com/codemodify/systemkit-service-spec"
15+
"github.com/codemodify/systemkit-service/helpers"
1916
)
2017

2118
var logTag = "LaunchD-SERVICE"
@@ -29,8 +26,8 @@ type launchdService struct {
2926
func newServiceFromSERVICE(serviceSpec spec.SERVICE) Service {
3027
// override some values - platform specific
3128
// https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html
32-
logDir := filepath.Join(helpersUser.HomeDir(""), "Library/Logs", serviceSpec.Name)
33-
if helpersUser.IsRoot() {
29+
logDir := filepath.Join(helpers.HomeDir(""), "Library/Logs", serviceSpec.Name)
30+
if helpers.IsRoot() {
3431
logDir = filepath.Join("/Library/Logs", serviceSpec.Name)
3532
}
3633

@@ -42,7 +39,7 @@ func newServiceFromSERVICE(serviceSpec spec.SERVICE) Service {
4239
serviceSpec.Logging.StdErr.Value = filepath.Join(logDir, serviceSpec.Name+".stderr.log")
4340
}
4441

45-
logging.Debugf("%s: serviceSpec object: %s", logTag, helpersJSON.AsJSONString(serviceSpec))
42+
logging.Debugf("%s: serviceSpec object: %s", logTag, helpers.AsJSONString(serviceSpec))
4643

4744
launchdService := &launchdService{
4845
serviceSpec: serviceSpec,
@@ -53,8 +50,8 @@ func newServiceFromSERVICE(serviceSpec spec.SERVICE) Service {
5350
}
5451

5552
func newServiceFromName(name string) (Service, error) {
56-
serviceFile := filepath.Join(helpersUser.HomeDir(""), "Library/LaunchAgents", name+".plist")
57-
if helpersUser.IsRoot() {
53+
serviceFile := filepath.Join(helpers.HomeDir(""), "Library/LaunchAgents", name+".plist")
54+
if helpers.IsRoot() {
5855
serviceFile = filepath.Join("/Library/LaunchDaemons", name+".plist")
5956
}
6057

@@ -101,7 +98,7 @@ func (thisRef launchdService) Install() error {
10198
func (thisRef launchdService) Uninstall() error {
10299
// 1.
103100
err := thisRef.Stop()
104-
if err != nil && !helpersErrors.Is(err, ErrServiceDoesNotExist) {
101+
if err != nil && !helpers.Is(err, ErrServiceDoesNotExist) {
105102
return err
106103
}
107104

@@ -197,21 +194,21 @@ func (thisRef launchdService) Info() Info {
197194
}
198195

199196
func (thisRef launchdService) filePath() string {
200-
if helpersUser.IsRoot() {
197+
if helpers.IsRoot() {
201198
return filepath.Join("/Library/LaunchDaemons", thisRef.serviceSpec.Name+".plist")
202199
}
203200

204-
return filepath.Join(helpersUser.HomeDir(""), "Library/LaunchAgents", thisRef.serviceSpec.Name+".plist")
201+
return filepath.Join(helpers.HomeDir(""), "Library/LaunchAgents", thisRef.serviceSpec.Name+".plist")
205202
}
206203

207204
func runLaunchCtlCommand(args ...string) (string, error) {
208-
// if !helpersUser.IsRoot() {
205+
// if !helpers.IsRoot() {
209206
// args = append([]string{"--user"}, args...)
210207
// }
211208

212209
logging.Debugf("%s: RUN-LAUNCHCTL: launchctl %s", logTag, strings.Join(args, " "))
213210

214-
output, err := helpersExec.ExecWithArgs("launchctl", args...)
211+
output, err := helpers.ExecWithArgs("launchctl", args...)
215212
errAsString := ""
216213
if err != nil {
217214
errAsString = err.Error()

service_freebsd-rc-d.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import (
88
"path/filepath"
99
"strings"
1010

11-
helpersJSON "github.com/codemodify/systemkit-helpers-conv"
12-
helpersExec "github.com/codemodify/systemkit-helpers-os"
13-
helpersErrors "github.com/codemodify/systemkit-helpers-reflection"
1411
logging "github.com/codemodify/systemkit-logging"
1512
encoders "github.com/codemodify/systemkit-service-encoders-rc_d"
1613
spec "github.com/codemodify/systemkit-service-spec"
14+
"github.com/codemodify/systemkit-service/helpers"
1715
)
1816

1917
var logTagRCD = "rc.d-SERVICE"
@@ -25,7 +23,7 @@ type rcdService struct {
2523
}
2624

2725
func newServiceFromSERVICE(serviceSpec spec.SERVICE) Service {
28-
logging.Debugf("%s: serviceSpec object: %s", logTagRCD, helpersJSON.AsJSONString(serviceSpec))
26+
logging.Debugf("%s: serviceSpec object: %s", logTagRCD, helpers.AsJSONString(serviceSpec))
2927

3028
return &rcdService{
3129
serviceSpec: serviceSpec,
@@ -105,7 +103,7 @@ func (thisRef rcdService) Uninstall() error {
105103

106104
// 2.
107105
err := thisRef.Stop()
108-
if err != nil && !helpersErrors.Is(err, ErrServiceDoesNotExist) {
106+
if err != nil && !helpers.Is(err, ErrServiceDoesNotExist) {
109107
return err
110108
}
111109

@@ -197,7 +195,7 @@ func (thisRef rcdService) filePath() string {
197195
func runServiceCommand(args ...string) (string, error) {
198196
logging.Debugf("%s: RUN-SERVICE: service %s", logTagRCD, strings.Join(args, " "))
199197

200-
output, err := helpersExec.ExecWithArgs("service", args...)
198+
output, err := helpers.ExecWithArgs("service", args...)
201199
errAsString := ""
202200
if err != nil {
203201
errAsString = err.Error()

service_linux-systemd.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ import (
99
"strconv"
1010
"strings"
1111

12-
helpersJSON "github.com/codemodify/systemkit-helpers-conv"
13-
helpersExec "github.com/codemodify/systemkit-helpers-os"
14-
helpersUser "github.com/codemodify/systemkit-helpers-os"
15-
helpersErrors "github.com/codemodify/systemkit-helpers-reflection"
1612
logging "github.com/codemodify/systemkit-logging"
1713
encoders "github.com/codemodify/systemkit-service-encoders-systemd"
1814
spec "github.com/codemodify/systemkit-service-spec"
15+
"github.com/codemodify/systemkit-service/helpers"
1916
)
2017

2118
var logTagSystemD = "SystemD-SERVICE"
@@ -27,7 +24,7 @@ type systemdService struct {
2724
}
2825

2926
func newServiceFromSERVICE_SystemD(serviceSpec spec.SERVICE) Service {
30-
logging.Debugf("%s: spec.SERVICE object: %s", logTagSystemD, helpersJSON.AsJSONString(serviceSpec))
27+
logging.Debugf("%s: spec.SERVICE object: %s", logTagSystemD, helpers.AsJSONString(serviceSpec))
3128

3229
return &systemdService{
3330
serviceSpec: serviceSpec,
@@ -39,7 +36,7 @@ func newServiceFromName_SystemD(name string) (Service, error) {
3936
fileContent := []byte{}
4037
var err error
4138

42-
if helpersUser.IsRoot() {
39+
if helpers.IsRoot() {
4340
serviceFile := filepath.Join("/etc/systemd/system", name+".service")
4441
fileContent, err = ioutil.ReadFile(serviceFile)
4542
if err != nil {
@@ -50,7 +47,7 @@ func newServiceFromName_SystemD(name string) (Service, error) {
5047
}
5148
}
5249
} else {
53-
serviceFile := filepath.Join(helpersUser.HomeDir(""), ".config/systemd/user", name+".service")
50+
serviceFile := filepath.Join(helpers.HomeDir(""), ".config/systemd/user", name+".service")
5451
fileContent, err = ioutil.ReadFile(serviceFile)
5552
if err != nil {
5653
return nil, ErrServiceDoesNotExist
@@ -106,7 +103,7 @@ func (thisRef systemdService) Uninstall() error {
106103

107104
// 2.
108105
err := thisRef.Stop()
109-
if err != nil && !helpersErrors.Is(err, ErrServiceDoesNotExist) {
106+
if err != nil && !helpers.Is(err, ErrServiceDoesNotExist) {
110107
return err
111108
}
112109

@@ -246,21 +243,21 @@ func (thisRef systemdService) Info() Info {
246243
}
247244

248245
func (thisRef systemdService) filePath() string {
249-
if helpersUser.IsRoot() {
246+
if helpers.IsRoot() {
250247
return filepath.Join("/etc/systemd/system", thisRef.serviceSpec.Name+".service")
251248
}
252249

253-
return filepath.Join(helpersUser.HomeDir(""), ".config/systemd/user", thisRef.serviceSpec.Name+".service")
250+
return filepath.Join(helpers.HomeDir(""), ".config/systemd/user", thisRef.serviceSpec.Name+".service")
254251
}
255252

256253
func runSystemCtlCommand(args ...string) (string, error) {
257-
if !helpersUser.IsRoot() {
254+
if !helpers.IsRoot() {
258255
args = append([]string{"--user"}, args...)
259256
}
260257

261258
logging.Debugf("%s: RUN-SYSTEMCTL: systemctl %s", logTagSystemD, strings.Join(args, " "))
262259

263-
output, err := helpersExec.ExecWithArgs("systemctl", args...)
260+
output, err := helpers.ExecWithArgs("systemctl", args...)
264261
errAsString := ""
265262
if err != nil {
266263
errAsString = err.Error()

service_linux-systemv.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@ import (
88
"path/filepath"
99
"strings"
1010

11-
helpersJSON "github.com/codemodify/systemkit-helpers-conv"
12-
helpersExec "github.com/codemodify/systemkit-helpers-os"
13-
helpersUser "github.com/codemodify/systemkit-helpers-os"
14-
helpersErrors "github.com/codemodify/systemkit-helpers-reflection"
1511
logging "github.com/codemodify/systemkit-logging"
1612
encoders "github.com/codemodify/systemkit-service-encoders-systemv"
1713
spec "github.com/codemodify/systemkit-service-spec"
14+
"github.com/codemodify/systemkit-service/helpers"
1815
)
1916

2017
var logTagSystemV = "SystemV-SERVICE"
@@ -26,7 +23,7 @@ type systemvService struct {
2623
}
2724

2825
func newServiceFromSERVICE_SystemV(serviceSpec spec.SERVICE) Service {
29-
logging.Debugf("%s: serviceSpec object: %s", logTagSystemV, helpersJSON.AsJSONString(serviceSpec))
26+
logging.Debugf("%s: serviceSpec object: %s", logTagSystemV, helpers.AsJSONString(serviceSpec))
3027

3128
return &systemvService{
3229
serviceSpec: serviceSpec,
@@ -103,7 +100,7 @@ func (thisRef systemvService) Uninstall() error {
103100

104101
// 2.
105102
err := thisRef.Stop()
106-
if err != nil && !helpersErrors.Is(err, ErrServiceDoesNotExist) {
103+
if err != nil && !helpers.Is(err, ErrServiceDoesNotExist) {
107104
return err
108105
}
109106

@@ -193,13 +190,13 @@ func (thisRef systemvService) filePath() string {
193190
}
194191

195192
func runServiceCommand(args ...string) (string, error) {
196-
if !helpersUser.IsRoot() {
193+
if !helpers.IsRoot() {
197194
args = append([]string{"--user"}, args...)
198195
}
199196

200197
logging.Debugf("%s: RUN-SERVICE: service %s", logTagSystemV, strings.Join(args, " "))
201198

202-
output, err := helpersExec.ExecWithArgs("service", args...)
199+
output, err := helpers.ExecWithArgs("service", args...)
203200
errAsString := ""
204201
if err != nil {
205202
errAsString = err.Error()

0 commit comments

Comments
 (0)