-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cmd/systemd/create_service): Create systemd file generator
- Loading branch information
1 parent
ef93067
commit a1fb753
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package create_service | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
parent_cmd "github.com/sikalabs/slu/cmd/systemd" | ||
"github.com/sikalabs/slu/utils/systemd_utils" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var FlagName string | ||
var FlagDescription string | ||
var FlagUser string | ||
var FlagGroup string | ||
var FlagWorkingDirectory string | ||
var FlagExecStart string | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "create-service", | ||
Short: "Create systemd service file", | ||
Aliases: []string{"cs"}, | ||
Args: cobra.NoArgs, | ||
Run: func(c *cobra.Command, args []string) { | ||
out, err := systemd_utils.CreateSystemdServiceString( | ||
FlagName, | ||
FlagDescription, | ||
FlagUser, | ||
FlagGroup, | ||
FlagWorkingDirectory, | ||
FlagExecStart, | ||
) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
fmt.Println(out) | ||
}, | ||
} | ||
|
||
func init() { | ||
parent_cmd.Cmd.AddCommand(Cmd) | ||
Cmd.Flags().StringVarP( | ||
&FlagName, | ||
"name", | ||
"n", | ||
"", | ||
"Systed service name", | ||
) | ||
Cmd.MarkFlagRequired("name") | ||
Cmd.Flags().StringVarP( | ||
&FlagDescription, | ||
"description", | ||
"d", | ||
"", | ||
"Systed service description", | ||
) | ||
Cmd.MarkFlagRequired("description") | ||
Cmd.Flags().StringVarP( | ||
&FlagUser, | ||
"user", | ||
"u", | ||
"", | ||
"Systed service user", | ||
) | ||
Cmd.MarkFlagRequired("user") | ||
Cmd.Flags().StringVarP( | ||
&FlagGroup, | ||
"group", | ||
"g", | ||
"", | ||
"Systed service group", | ||
) | ||
Cmd.MarkFlagRequired("group") | ||
Cmd.Flags().StringVarP( | ||
&FlagWorkingDirectory, | ||
"working-directory", | ||
"w", | ||
"", | ||
"Systed service working-directory", | ||
) | ||
Cmd.MarkFlagRequired("working-directory") | ||
Cmd.Flags().StringVarP( | ||
&FlagExecStart, | ||
"exec-start", | ||
"e", | ||
"", | ||
"Systed service exec-start", | ||
) | ||
Cmd.MarkFlagRequired("exec-start") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package systemd | ||
|
||
import ( | ||
"github.com/sikalabs/slu/cmd/root" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "systemd", | ||
Short: "Utils for systemd", | ||
Aliases: []string{"sysd"}, | ||
} | ||
|
||
func init() { | ||
root.RootCmd.AddCommand(Cmd) | ||
} |