Skip to content

Commit

Permalink
Add command for installing the application.
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-osman committed Jul 27, 2023
1 parent 367956b commit f8e622a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
65 changes: 65 additions & 0 deletions install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 lampctl")
fmt.Println(" systemctl start lampctl")

return nil
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func main() {
},
},
Commands: []*cli.Command{
installCommand,
{
Name: "createuser",
Usage: "create a new user account",
Expand Down

0 comments on commit f8e622a

Please sign in to comment.