@@ -6,7 +6,6 @@ package install
66
77import (
88 "errors"
9- "fmt"
109 "os/exec"
1110
1211 "github.com/rs/zerolog"
@@ -19,11 +18,9 @@ import (
1918 "github.com/uyuni-project/uyuni-tools/mgradm/shared/podman"
2019 "github.com/uyuni-project/uyuni-tools/mgradm/shared/saline"
2120 "github.com/uyuni-project/uyuni-tools/mgradm/shared/tftp"
22- adm_utils "github.com/uyuni-project/uyuni-tools/mgradm/shared/utils"
2321 "github.com/uyuni-project/uyuni-tools/shared"
2422 . "github.com/uyuni-project/uyuni-tools/shared/l10n"
2523 shared_podman "github.com/uyuni-project/uyuni-tools/shared/podman"
26- "github.com/uyuni-project/uyuni-tools/shared/ssl"
2724 "github.com/uyuni-project/uyuni-tools/shared/types"
2825 "github.com/uyuni-project/uyuni-tools/shared/utils"
2926)
@@ -82,15 +79,19 @@ func installForPodman(
8279 return err
8380 }
8481
85- log .Info ().Msg (L ("Run setup command" ))
86-
87- if err := runSetup (preparedImage , & flags .ServerFlags , fqdn ); err != nil {
82+ // This creates installation values to be passed as envvars
83+ if err := podman .GenerateServerEnvironmentFile (flags .Installation , fqdn , flags .Mirror != "" ); err != nil {
8884 return err
8985 }
9086
87+ if err := podman .GenerateSystemdService (
88+ systemd , preparedImage , flags .Installation , flags .Podman .Args , flags .Mirror ,
89+ ); err != nil {
90+ return utils .Error (err , L ("failed to generate server service" ))
91+ }
92+
9193 cnx := shared .NewConnection ("podman" , shared_podman .ServerContainerName , "" )
92- if err := podman .WaitForSystemStart (systemd , cnx , preparedImage , flags .Installation .TZ ,
93- flags .Installation .Debug .Java , flags .Mirror , flags .Podman .Args ); err != nil {
94+ if err := podman .WaitForSystemStart (systemd , cnx ); err != nil {
9495 return utils .Error (err , L ("cannot wait for system start" ))
9596 }
9697 if err := cnx .CopyCaCertificate (fqdn ); err != nil {
@@ -114,7 +115,7 @@ func installForPodman(
114115 )
115116}
116117
117- func setupDatabase (dbFlags adm_utils .DBFlags , reportdbFlags adm_utils .DBFlags , preparedImage string ) error {
118+ func setupDatabase (dbFlags types .DBFlags , reportdbFlags types .DBFlags , preparedImage string ) error {
118119 if err := shared_podman .CreateCredentialsSecrets (
119120 shared_podman .DBUserSecret , dbFlags .User ,
120121 shared_podman .DBPassSecret , dbFlags .Password ,
@@ -129,81 +130,29 @@ func setupDatabase(dbFlags adm_utils.DBFlags, reportdbFlags adm_utils.DBFlags, p
129130 return err
130131 }
131132
132- if dbFlags .IsLocal () {
133- // The admin password is not needed for external databases
134- if err := shared_podman .CreateCredentialsSecrets (
135- shared_podman .DBAdminUserSecret , dbFlags .Admin .User ,
136- shared_podman .DBAdminPassSecret , dbFlags .Admin .Password ,
137- ); err != nil {
138- return err
139- }
140- if dbFlags .Walbackup {
141- if err := pgsql .GenerateBackupVolumeConfig (systemd ); err != nil {
142- return err
143- }
144- }
145- // Run the DB container setup if the user doesn't set a custom host name for it.
146- if err := pgsql .SetupPgsql (systemd , preparedImage ); err != nil {
147- return err
148- }
149- if dbFlags .Walbackup {
150- if err := db .Enable (true ); err != nil {
151- return err
152- }
153- }
154- } else {
133+ if ! dbFlags .IsLocal () {
155134 log .Info ().Msgf (
156135 L ("Skipped database container setup to use external database %s" ),
157136 dbFlags .Host ,
158137 )
138+ return nil
159139 }
160- return nil
161- }
162140
163- // runSetup execute the setup.
164- func runSetup (image string , flags * adm_utils.ServerFlags , fqdn string ) error {
165- env := adm_utils .GetSetupEnv (flags .Mirror , & flags .Installation , fqdn )
166- envNames := []string {}
167- envValues := []string {}
168- for key , value := range env {
169- envNames = append (envNames , "-e" , key )
170- envValues = append (envValues , fmt .Sprintf ("%s=%s" , key , value ))
171- }
172-
173- command := []string {
174- "run" ,
175- "--rm" ,
176- "--shm-size=0" ,
177- "--shm-size-systemd=0" ,
178- "--name" , "uyuni-setup" ,
179- "--network" , shared_podman .UyuniNetwork ,
180- "-e" , "TZ=" + flags .Installation .TZ ,
181- "--secret" , shared_podman .DBUserSecret + ",type=env,target=MANAGER_USER" ,
182- "--secret" , shared_podman .DBPassSecret + ",type=env,target=MANAGER_PASS" ,
183- "--secret" , shared_podman .ReportDBUserSecret + ",type=env,target=REPORT_DB_USER" ,
184- "--secret" , shared_podman .ReportDBPassSecret + ",type=env,target=REPORT_DB_PASS" ,
185- "-e REPORT_DB_CA_CERT=" + ssl .DBCAContainerPath ,
186- "--secret" , shared_podman .DBCASecret + ",type=mount,target=" + ssl .DBCAContainerPath ,
187- "--secret" , shared_podman .CASecret + ",type=mount,target=" + ssl .CAContainerPath ,
188- "--secret" , shared_podman .CASecret + ",type=mount,target=/usr/share/susemanager/salt/certs/RHN-ORG-TRUSTED-SSL-CERT" ,
189- "--secret" , shared_podman .CASecret + ",type=mount,target=/srv/www/htdocs/pub/RHN-ORG-TRUSTED-SSL-CERT" ,
190- "--secret" , shared_podman .SSLCertSecret + ",type=mount,target=" + ssl .ServerCertPath ,
191- "--secret" , shared_podman .SSLKeySecret + ",type=mount,target=" + ssl .ServerCertKeyPath ,
192- }
193- for _ , volume := range utils .ServerVolumeMounts {
194- command = append (command , "-v" , fmt .Sprintf ("%s:%s" , volume .Name , volume .MountPath ))
195- }
196- command = append (command , envNames ... )
197- command = append (command , image )
198-
199- command = append (command , "/usr/bin/bash" , "-e" , "-c" , "/docker-entrypoint-init.d/00-mgrSetup.sh" )
200-
201- if _ , err := newRunner ("podman" , command ... ).Env (envValues ).StdMapping ().Exec (); err != nil {
202- return utils .Error (err , L ("server setup failed" ))
203- }
204-
205- log .Info ().Msgf (L ("Server set up, login on https://%[1]s with %[2]s user" ), fqdn , flags .Installation .Admin .Login )
141+ // The admin password is not needed for external databases
142+ if err := shared_podman .CreateCredentialsSecrets (
143+ shared_podman .DBAdminUserSecret , dbFlags .Admin .User ,
144+ shared_podman .DBAdminPassSecret , dbFlags .Admin .Password ,
145+ ); err != nil {
146+ return err
147+ }
148+ // Run the DB container setup if the user doesn't set a custom host name for it.
149+ if err := pgsql .SetupPgsql (systemd , preparedImage ); err != nil {
150+ return err
151+ }
152+ if dbFlags .Walbackup {
153+ if err := db .Enable (true ); err != nil {
154+ return err
155+ }
156+ }
206157 return nil
207158}
208-
209- var newRunner = utils .NewRunner
0 commit comments