mirror of https://github.com/statping/statping
systemctl command
parent
56a7e921e1
commit
f8e60bead5
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"id": "com.statping",
|
||||||
|
"title": "Statping",
|
||||||
|
"author": "Hunter Long <info@statping.com>",
|
||||||
|
"description": "Monitor your web services and remote servers",
|
||||||
|
"tagline": "Server Monitoring",
|
||||||
|
"version": "0.90.61",
|
||||||
|
"healthCheckPath": "/health",
|
||||||
|
"httpPort": 8080,
|
||||||
|
"addons": {
|
||||||
|
"localstorage": {}
|
||||||
|
},
|
||||||
|
"manifestVersion": 2,
|
||||||
|
"website": "https://github.com/statping/statping",
|
||||||
|
"contactEmail": "info@statping.com",
|
||||||
|
"icon": "https://assets.statping.com/icon.png",
|
||||||
|
"tags": [ "monitoring", "uptime" ],
|
||||||
|
"mediaLinks": [ "https://assets.statping.com/cloudron.png" ]
|
||||||
|
}s
|
61
cmd/cli.go
61
cmd/cli.go
|
@ -34,8 +34,65 @@ func assetsCli() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func systemctlCli() error {
|
func systemctlCli(dir string, uninstall bool, port int64) error {
|
||||||
fmt.Println("still in the works...")
|
location := "/etc/systemd/system/statping.service"
|
||||||
|
|
||||||
|
if uninstall {
|
||||||
|
if _, _, err := utils.Command("systemctl", "stop", "statping"); err != nil {
|
||||||
|
log.Errorln(err)
|
||||||
|
}
|
||||||
|
if _, _, err := utils.Command("systemctl", "disable", "statping"); err != nil {
|
||||||
|
log.Errorln(err)
|
||||||
|
}
|
||||||
|
if err := utils.DeleteFile(location); err != nil {
|
||||||
|
log.Errorln(err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if ok := utils.FolderExists(dir); !ok {
|
||||||
|
return errors.New("directory does not exist: " + dir)
|
||||||
|
}
|
||||||
|
|
||||||
|
binPath, err := os.Executable()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
config := []byte(`[Unit]
|
||||||
|
Description=Statping Server
|
||||||
|
After=network.target
|
||||||
|
After=systemd-user-sessions.service
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
Restart=always
|
||||||
|
Environment=STATPING_DIR=` + dir + `
|
||||||
|
Environment=ALLOW_REPORTS=true
|
||||||
|
ExecStart=` + binPath + ` --port=` + utils.ToString(port) + `
|
||||||
|
WorkingDirectory=` + dir + `
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target"
|
||||||
|
`)
|
||||||
|
fmt.Println("Saving systemctl service to: ", location)
|
||||||
|
fmt.Printf("Using directory %s for Statping data\n", dir)
|
||||||
|
fmt.Printf("Running on port %d\n", port)
|
||||||
|
if err := utils.SaveFile(location, config); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, _, err := utils.Command("systemctl", "daemon-reload"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, _, err := utils.Command("systemctl", "enable", "statping.service"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, _, err := utils.Command("systemctl", "start", "statping"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Println("Statping was will auto start on reboots")
|
||||||
|
fmt.Println("systemctl service: /etc/systemd/system/statping.service")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/statping/statping/utils"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -72,17 +73,26 @@ var versionCmd = &cobra.Command{
|
||||||
|
|
||||||
var systemctlCmd = &cobra.Command{
|
var systemctlCmd = &cobra.Command{
|
||||||
Use: "systemctl [install/uninstall]",
|
Use: "systemctl [install/uninstall]",
|
||||||
Short: "Install or Uninstall systemctl links",
|
Short: "Install or Uninstall systemctl services",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if err := systemctlCli(); err != nil {
|
if args[1] == "install" {
|
||||||
|
if len(args) < 3 {
|
||||||
|
return errors.New("requires 'install <working_path> <port>'")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
port := utils.ToInt(args[2])
|
||||||
|
if port == 0 {
|
||||||
|
port = 80
|
||||||
|
}
|
||||||
|
if err := systemctlCli(args[1], args[0] == "uninstall", port); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Args: func(cmd *cobra.Command, args []string) error {
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
if len(args) < 2 {
|
||||||
return errors.New("requires 'install' or 'uninstall' as arguments")
|
return errors.New("requires 'install <working_path>' or 'uninstall' as arguments")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue