Skip to content

Commit

Permalink
feat(cmd/systemd/create_service): Add --create-file to automaticall…
Browse files Browse the repository at this point in the history
…y create systemd service file
  • Loading branch information
ondrejsika committed Apr 17, 2023
1 parent a1fb753 commit fac482f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion cmd/systemd/create_service/create_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package create_service

import (
"fmt"
"io/ioutil"
"log"

parent_cmd "github.com/sikalabs/slu/cmd/systemd"
Expand All @@ -10,6 +11,7 @@ import (
"github.com/spf13/cobra"
)

var FlagCreateFile bool
var FlagName string
var FlagDescription string
var FlagUser string
Expand All @@ -34,12 +36,27 @@ var Cmd = &cobra.Command{
if err != nil {
log.Fatalln(err)
}
fmt.Println(out)
if FlagCreateFile {
err := ioutil.WriteFile(
"/etc/systemd/system/"+FlagName+".service", []byte(out), 0644)
if err != nil {
log.Fatalln(err)
}
} else {
fmt.Println(out)
}
},
}

func init() {
parent_cmd.Cmd.AddCommand(Cmd)
Cmd.Flags().BoolVarP(
&FlagCreateFile,
"create-file",
"c",
false,
"Create service file in /etc/systemd/system",
)
Cmd.Flags().StringVarP(
&FlagName,
"name",
Expand Down

0 comments on commit fac482f

Please sign in to comment.