Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/config.cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ haproxy:
password: will_be_overridden
data_dir: /var/lib/swiftwave/haproxy
postgresql:
auto_start_local_postgres: false # true or false
host: 127.0.0.1
port: 5432
user: postgres
Expand Down
1 change: 1 addition & 0 deletions cmd/config.standalone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ haproxy:
password: will_be_overridden
data_dir: /var/lib/swiftwave/haproxy
postgresql:
auto_start_local_postgres: true # true or false
host: 127.0.0.1
port: 5432
user: postgres
Expand Down
15 changes: 15 additions & 0 deletions cmd/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func init() {
postgresCmd.AddCommand(postgresStatusCmd)
postgresCmd.AddCommand(postgresStartCmd)
postgresCmd.AddCommand(postgresStopCmd)
postgresCmd.AddCommand(postgresAutoRunCmd)
}

var postgresCmd = &cobra.Command{
Expand Down Expand Up @@ -156,6 +157,20 @@ var postgresStatusCmd = &cobra.Command{
},
}

var postgresAutoRunCmd = &cobra.Command{
Use: "auto-run-local",
Short: "Auto run postgres locally if `auto_run_local_postgres` is set to true in config file",
Long: "Auto run postgres locally if `auto_run_local_postgres` is set to true in config file",
Run: func(cmd *cobra.Command, args []string) {
if systemConfig.PostgresqlConfig.AutoStartLocalPostgres && systemConfig.Mode == system_config.Standalone {
// Start local postgres database
postgresStartCmd.Run(cmd, args)
} else {
printInfo("Auto run local postgres is disabled in config file")
}
},
}

// Private functions
func checkIfPostgresContainerExists() bool {
// Use local docker client to check if postgres container exists
Expand Down
2 changes: 1 addition & 1 deletion cmd/swiftwave.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Description=Swiftwave Service
After=multi-user.target

[Service]
ExecStart=/usr/bin/swiftwave start
ExecStart=/usr/bin/swiftwave postgres auto-run-local && /usr/bin/swiftwave start
Type=simple

[Install]
Expand Down
15 changes: 8 additions & 7 deletions system_config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ type ServiceConfig struct {
}

type PostgresqlConfig struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
User string `yaml:"user"`
Password string `yaml:"password"`
Database string `yaml:"database"`
TimeZone string `yaml:"time_zone"`
SSLMode string `yaml:"ssl_mode"`
Host string `yaml:"host"`
Port int `yaml:"port"`
User string `yaml:"user"`
Password string `yaml:"password"`
Database string `yaml:"database"`
TimeZone string `yaml:"time_zone"`
SSLMode string `yaml:"ssl_mode"`
AutoStartLocalPostgres bool `yaml:"auto_start_local_postgres"`
}

type HAProxyConfig struct {
Expand Down