-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.go
65 lines (52 loc) · 1.17 KB
/
install.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"fmt"
"html/template"
"os"
"github.com/urfave/cli/v2"
)
const systemdUnitFile = `[Unit]
Description=i5 Reverse Proxy
Wants=network-online.target
After=network-online.target
[Service]
ExecStart={{.path}}
[Install]
WantedBy=multi-user.target
`
var installCommand = &cli.Command{
Name: "install",
Usage: "install the application as a local service",
Action: install,
}
func install(c *cli.Context) error {
// Determine the full path to the executable
p, err := os.Executable()
if err != nil {
return err
}
// Compile the template
t, err := template.New("").Parse(systemdUnitFile)
if err != nil {
return err
}
// Attempt to open the file
f, err := os.Create("/lib/systemd/system/i5.service")
if err != nil {
return err
}
defer f.Close()
// Write the template
t.Execute(f, map[string]interface{}{
"path": p,
})
fmt.Println("Service installed!")
fmt.Println("")
fmt.Println("To modify command line arguments, please edit:")
fmt.Println(" /lib/systemd/system/i5.service")
fmt.Println("")
fmt.Println("To enable the service and start it, run:")
fmt.Println(" systemctl enable i5")
fmt.Println(" systemctl start i5")
return nil
}