Browse Source

progress

tags/v0.6.0
Ryan Burnette 5 months ago
parent
commit
76710d58fa
4 changed files with 34 additions and 4 deletions
  1. 20
    0
      README.md
  2. 3
    3
      manager/dist/etc/systemd/system/_name_.service.tmpl
  3. 5
    0
      runner/runner.go
  4. 6
    1
      serviceman.go

+ 20
- 0
README.md View File

@@ -35,6 +35,7 @@ Also, I wanted a reasonable way to install [Telebit](https://telebit.io) on Wind
35 35
     -   node
36 36
     -   python
37 37
     -   ruby
38
+    -   path
38 39
 -   Logging
39 40
 -   Debugging
40 41
 -   Windows
@@ -398,6 +399,25 @@ See **Using with scripts** for more detailed information.
398 399
 
399 400
 </details>
400 401
 
402
+<details>
403
+<summary>Setting $PATH</summary>
404
+
405
+You can set the `$PATH` for your service like this:
406
+
407
+```bash
408
+sudo serviceman add ./myservice --path "/home/myuser/bin"
409
+```
410
+
411
+Snapshot your actual path like this:
412
+
413
+```bash
414
+sudo serviceman add ./myservice --path "$PATH"
415
+```
416
+
417
+Remember that this takes a snapshot and sets it in the configuration, it's not
418
+a live reference to your path.
419
+</details>
420
+
401 421
 ## Hints
402 422
 
403 423
 -   If something goes wrong, read the output **completely** - it'll probably be helpful

+ 3
- 3
manager/dist/etc/systemd/system/_name_.service.tmpl View File

@@ -22,9 +22,6 @@ Wants=network-online.target systemd-networkd-wait-online.service
22 22
 
23 23
 {{ end -}}
24 24
 [Service]
25
-{{ if .Path -}}
26
-PATH={{ .Path }}
27
-{{ end -}}
28 25
 # Restart on crash (bad signal), but not on 'clean' failure (error exit code)
29 26
 # Allow up to 3 restarts within 10 seconds
30 27
 # (it's unlikely that a user or properly-running script will do this)
@@ -38,6 +35,9 @@ User={{ .User }}
38 35
 Group={{ .Group }}
39 36
 
40 37
 {{ end -}}
38
+{{- if .Envs }}
39
+Environment="{{- range $key, $value := .Envs }}{{ $key }}={{ $value }};{{- end }}"
40
+{{- end }}
41 41
 {{ if .Workdir -}}
42 42
 WorkingDirectory={{ .Workdir }}
43 43
 {{ end -}}

+ 5
- 0
runner/runner.go View File

@@ -78,6 +78,11 @@ func Start(conf *service.Service) error {
78 78
 		if "" != conf.Workdir {
79 79
 			cmd.Dir = conf.Workdir
80 80
 		}
81
+		if len(conf.Envs) > 0 {
82
+			for k, v := range conf.Envs {
83
+				cmd.Env = append(cmd.Env, k+"="+v)
84
+			}
85
+		}
81 86
 		err = cmd.Start()
82 87
 		if nil != err {
83 88
 			fmt.Fprintf(lf, "[%s] Could not start %q process: %s\n", time.Now(), conf.Name, err)

+ 6
- 1
serviceman.go View File

@@ -70,6 +70,7 @@ func add() {
70 70
 	forUser := false
71 71
 	forSystem := false
72 72
 	dryrun := false
73
+	pathEnv := ""
73 74
 	flag.StringVar(&conf.Title, "title", "", "a human-friendly name for the service")
74 75
 	flag.StringVar(&conf.Desc, "desc", "", "a human-friendly description of the service (ex: Foo App)")
75 76
 	flag.StringVar(&conf.Name, "name", "", "a computer-friendly name for the service (ex: foo-app)")
@@ -79,7 +80,7 @@ func add() {
79 80
 	flag.BoolVar(&forSystem, "system", false, "attempt to add system service as an unprivileged/unelevated user")
80 81
 	flag.BoolVar(&forUser, "user", false, "add user space / user mode service even when admin/root/sudo/elevated")
81 82
 	flag.BoolVar(&force, "force", false, "if the interpreter or executable doesn't exist, or things don't make sense, try anyway")
82
-	flag.StringVar(&conf.Path, "path", "", "set the path for the resulting systemd service")
83
+	flag.StringVar(&pathEnv, "path", "", "set the path for the resulting systemd service")
83 84
 	flag.StringVar(&conf.User, "username", "", "run the service as this user")
84 85
 	flag.StringVar(&conf.Group, "groupname", "", "run the service as this group")
85 86
 	flag.BoolVar(&conf.PrivilegedPorts, "cap-net-bind", false, "this service should have access to privileged ports")
@@ -164,6 +165,10 @@ func add() {
164 165
 		ass = append(ass, fmt.Sprintf("  --name %s", conf.Name))
165 166
 		ass = append(ass, "")
166 167
 	}
168
+	if "" != pathEnv {
169
+		conf.Envs = make(map[string]string)
170
+		conf.Envs["PATH"] = pathEnv
171
+	}
167 172
 
168 173
 	exepath, err := findExec(flagargs[0], force)
169 174
 	if nil != err {

Loading…
Cancel
Save