path option #7
							
								
								
									
										20
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								README.md
									
									
									
									
									
								
							@ -35,6 +35,7 @@ Also, I wanted a reasonable way to install [Telebit](https://telebit.io) on Wind
 | 
				
			|||||||
    -   node
 | 
					    -   node
 | 
				
			||||||
    -   python
 | 
					    -   python
 | 
				
			||||||
    -   ruby
 | 
					    -   ruby
 | 
				
			||||||
 | 
					    -   path
 | 
				
			||||||
-   Logging
 | 
					-   Logging
 | 
				
			||||||
-   Debugging
 | 
					-   Debugging
 | 
				
			||||||
-   Windows
 | 
					-   Windows
 | 
				
			||||||
@ -392,6 +393,25 @@ See **Using with scripts** for more detailed information.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
</details>
 | 
					</details>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<details>
 | 
				
			||||||
 | 
					<summary>Setting $PATH</summary>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You can set the `$PATH` for your service like this:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```bash
 | 
				
			||||||
 | 
					sudo serviceman add ./myservice --path "/home/myuser/bin"
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Snapshot your actual path like this:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```bash
 | 
				
			||||||
 | 
					sudo serviceman add ./myservice --path "$PATH"
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Remember that this takes a snapshot and sets it in the configuration, it's not
 | 
				
			||||||
 | 
					a live reference to your path.
 | 
				
			||||||
 | 
					</details>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Hints
 | 
					## Hints
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-   If something goes wrong, read the output **completely** - it'll probably be helpful
 | 
					-   If something goes wrong, read the output **completely** - it'll probably be helpful
 | 
				
			||||||
 | 
				
			|||||||
@ -35,6 +35,9 @@ User={{ .User }}
 | 
				
			|||||||
Group={{ .Group }}
 | 
					Group={{ .Group }}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{{ end -}}
 | 
					{{ end -}}
 | 
				
			||||||
 | 
					{{- if .Envs }}
 | 
				
			||||||
 | 
					Environment="{{- range $key, $value := .Envs }}{{ $key }}={{ $value }};{{- end }}"
 | 
				
			||||||
 | 
					{{- end }}
 | 
				
			||||||
{{ if .Workdir -}}
 | 
					{{ if .Workdir -}}
 | 
				
			||||||
WorkingDirectory={{ .Workdir }}
 | 
					WorkingDirectory={{ .Workdir }}
 | 
				
			||||||
{{ end -}}
 | 
					{{ end -}}
 | 
				
			||||||
 | 
				
			|||||||
@ -78,6 +78,11 @@ func Start(conf *service.Service) error {
 | 
				
			|||||||
		if "" != conf.Workdir {
 | 
							if "" != conf.Workdir {
 | 
				
			||||||
			cmd.Dir = conf.Workdir
 | 
								cmd.Dir = conf.Workdir
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							if len(conf.Envs) > 0 {
 | 
				
			||||||
 | 
								for k, v := range conf.Envs {
 | 
				
			||||||
 | 
									cmd.Env = append(cmd.Env, k+"="+v)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		err = cmd.Start()
 | 
							err = cmd.Start()
 | 
				
			||||||
		if nil != err {
 | 
							if nil != err {
 | 
				
			||||||
			fmt.Fprintf(lf, "[%s] Could not start %q process: %s\n", time.Now(), conf.Name, err)
 | 
								fmt.Fprintf(lf, "[%s] Could not start %q process: %s\n", time.Now(), conf.Name, err)
 | 
				
			||||||
 | 
				
			|||||||
@ -70,6 +70,7 @@ func add() {
 | 
				
			|||||||
	forUser := false
 | 
						forUser := false
 | 
				
			||||||
	forSystem := false
 | 
						forSystem := false
 | 
				
			||||||
	dryrun := false
 | 
						dryrun := false
 | 
				
			||||||
 | 
						pathEnv := ""
 | 
				
			||||||
	flag.StringVar(&conf.Title, "title", "", "a human-friendly name for the service")
 | 
						flag.StringVar(&conf.Title, "title", "", "a human-friendly name for the service")
 | 
				
			||||||
	flag.StringVar(&conf.Desc, "desc", "", "a human-friendly description of the service (ex: Foo App)")
 | 
						flag.StringVar(&conf.Desc, "desc", "", "a human-friendly description of the service (ex: Foo App)")
 | 
				
			||||||
	flag.StringVar(&conf.Name, "name", "", "a computer-friendly name for the service (ex: foo-app)")
 | 
						flag.StringVar(&conf.Name, "name", "", "a computer-friendly name for the service (ex: foo-app)")
 | 
				
			||||||
@ -79,6 +80,7 @@ func add() {
 | 
				
			|||||||
	flag.BoolVar(&forSystem, "system", false, "attempt to add system service as an unprivileged/unelevated user")
 | 
						flag.BoolVar(&forSystem, "system", false, "attempt to add system service as an unprivileged/unelevated user")
 | 
				
			||||||
	flag.BoolVar(&forUser, "user", false, "add user space / user mode service even when admin/root/sudo/elevated")
 | 
						flag.BoolVar(&forUser, "user", false, "add user space / user mode service even when admin/root/sudo/elevated")
 | 
				
			||||||
	flag.BoolVar(&force, "force", false, "if the interpreter or executable doesn't exist, or things don't make sense, try anyway")
 | 
						flag.BoolVar(&force, "force", false, "if the interpreter or executable doesn't exist, or things don't make sense, try anyway")
 | 
				
			||||||
 | 
						flag.StringVar(&pathEnv, "path", "", "set the path for the resulting systemd service")
 | 
				
			||||||
	flag.StringVar(&conf.User, "username", "", "run the service as this user")
 | 
						flag.StringVar(&conf.User, "username", "", "run the service as this user")
 | 
				
			||||||
	flag.StringVar(&conf.Group, "groupname", "", "run the service as this group")
 | 
						flag.StringVar(&conf.Group, "groupname", "", "run the service as this group")
 | 
				
			||||||
	flag.BoolVar(&conf.PrivilegedPorts, "cap-net-bind", false, "this service should have access to privileged ports")
 | 
						flag.BoolVar(&conf.PrivilegedPorts, "cap-net-bind", false, "this service should have access to privileged ports")
 | 
				
			||||||
@ -163,6 +165,10 @@ func add() {
 | 
				
			|||||||
		ass = append(ass, fmt.Sprintf("  --name %s", conf.Name))
 | 
							ass = append(ass, fmt.Sprintf("  --name %s", conf.Name))
 | 
				
			||||||
		ass = append(ass, "")
 | 
							ass = append(ass, "")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if "" != pathEnv {
 | 
				
			||||||
 | 
							conf.Envs = make(map[string]string)
 | 
				
			||||||
 | 
							conf.Envs["PATH"] = pathEnv
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	exepath, err := findExec(flagargs[0], force)
 | 
						exepath, err := findExec(flagargs[0], force)
 | 
				
			||||||
	if nil != err {
 | 
						if nil != err {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user