cmd

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Install = &cobra.Command{
		Use:   "install",
		Short: "Install",
		Run: func(c *cobra.Command, args []string) {
			name := cmd.Use
			err := os.WriteFile(fmt.Sprintf("/etc/systemd/system/%s.service", name), []byte(fmt.Sprintf(`
[Unit]
Description=%s
After=network.target

[Service]
Type=simple
WorkingDirectory=%s
ExecStart=%s run
Restart=always
RestartSec=30s

[Install]
WantedBy=multi-user.target
`, strings.ToUpper(name), app.Dir, filepath.Join(app.Dir, name))), os.ModePerm)
			if err != nil {
				fmt.Print(err)
				return
			}
			_, err = utl.Command(fmt.Sprintf("systemctl enable %s", name), "systemctl daemon-reload", fmt.Sprintf("systemctl restart %s", name))
			if err != nil {
				fmt.Print(err)
			}
		},
	}
)
View Source
var (
	Start = &cobra.Command{
		Use:   "start",
		Short: "Start",
		Run: func(c *cobra.Command, args []string) {
			name := cmd.Use
			_, err := utl.Command(fmt.Sprintf("systemctl restart %s", name))
			if err != nil {
				fmt.Print(err)
			}
		},
	}
)
View Source
var (
	Status = &cobra.Command{
		Use:   "status",
		Short: "Status",
		Run: func(c *cobra.Command, args []string) {
			name := cmd.Use
			_, err := utl.Command(fmt.Sprintf("systemctl status %s", name))
			if err != nil {
				fmt.Print(err)
			}
		},
	}
)
View Source
var (
	Stop = &cobra.Command{
		Use:   "stop",
		Short: "Stop",
		Run: func(c *cobra.Command, args []string) {
			name := cmd.Use
			_, err := utl.Command(fmt.Sprintf("systemctl stop %s", name))
			if err != nil {
				fmt.Print(err)
			}
		},
	}
)
View Source
var (
	Uninstall = &cobra.Command{
		Use:   "uninstall",
		Short: "Uninstall",
		Run: func(c *cobra.Command, args []string) {
			name := cmd.Use
			_, err := utl.Command(fmt.Sprintf("systemctl stop %s", name), fmt.Sprintf("systemctl disable %s", name))
			if err != nil {
				fmt.Print(err)
				return
			}
			err = utl.Remove(fmt.Sprintf("/etc/systemd/system/%s.service", name))
			if err != nil {
				fmt.Print(err)
			}
		},
	}
)

Functions

func Execute

func Execute(name, description string, cmds ...*cobra.Command)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL