diff options
author | Toshiki Sonoda <sonoda.toshiki@fujitsu.com> | 2022-09-02 16:20:26 +0900 |
---|---|---|
committer | Toshiki Sonoda <sonoda.toshiki@fujitsu.com> | 2022-09-06 20:17:11 +0900 |
commit | a9a411f8a83ab5644582b8929a32abacc18a17fc (patch) | |
tree | e94196c3d5f7936f55d36041c67276dcb0a980ae /cmd | |
parent | 9ab6449e36792734853eb59161ccd3bfe5d0d509 (diff) | |
download | podman-a9a411f8a83ab5644582b8929a32abacc18a17fc.tar.gz podman-a9a411f8a83ab5644582b8929a32abacc18a17fc.tar.bz2 podman-a9a411f8a83ab5644582b8929a32abacc18a17fc.zip |
Add generate systemd -e/--env option
-e/--env option sets environment variables to the systemd unit files.
Fixes: #15523
Signed-off-by: Toshiki Sonoda <sonoda.toshiki@fujitsu.com>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/generate/systemd.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/cmd/podman/generate/systemd.go b/cmd/podman/generate/systemd.go index e40416534..a7cdd9bfe 100644 --- a/cmd/podman/generate/systemd.go +++ b/cmd/podman/generate/systemd.go @@ -13,6 +13,7 @@ import ( "github.com/containers/podman/v4/cmd/podman/registry" "github.com/containers/podman/v4/cmd/podman/utils" "github.com/containers/podman/v4/pkg/domain/entities" + envLib "github.com/containers/podman/v4/pkg/env" systemDefine "github.com/containers/podman/v4/pkg/systemd/define" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -28,9 +29,11 @@ const ( wantsFlagName = "wants" afterFlagName = "after" requiresFlagName = "requires" + envFlagName = "env" ) var ( + envInput []string files bool format string systemdRestart string @@ -109,6 +112,9 @@ func init() { flags.StringArrayVar(&systemdOptions.Requires, requiresFlagName, nil, "Similar to wants, but declares stronger requirement dependencies") _ = systemdCmd.RegisterFlagCompletionFunc(requiresFlagName, completion.AutocompleteNone) + flags.StringArrayVarP(&envInput, envFlagName, "e", nil, "Set environment variables to the systemd unit files") + _ = systemdCmd.RegisterFlagCompletionFunc(envFlagName, completion.AutocompleteNone) + flags.SetNormalizeFunc(utils.TimeoutAliasFlags) } @@ -141,6 +147,13 @@ func systemd(cmd *cobra.Command, args []string) error { if cmd.Flags().Changed(stopTimeoutCompatFlagName) { setStopTimeout++ } + if cmd.Flags().Changed(envFlagName) { + cliEnv, err := envLib.ParseSlice(envInput) + if err != nil { + return fmt.Errorf("error parsing environment variables: %w", err) + } + systemdOptions.AdditionalEnvVariables = envLib.Slice(cliEnv) + } switch setStopTimeout { case 1: systemdOptions.StopTimeout = &stopTimeout |