@@ -17,12 +17,19 @@ import (
1717var tuiMode bool
1818var benchMode bool
1919var configPath string
20+ var globalConfigPath string
2021
2122// rootCmd represents the base command when called without any subcommands.
2223var rootCmd = & cobra.Command {
2324 Use : "goup" ,
2425 Short : "GoUP is a minimal configurable web server" ,
2526 Long : `GoUP is a minimal configurable web server written in Go.` ,
27+ PersistentPreRun : func (cmd * cobra.Command , args []string ) {
28+ if err := config .LoadGlobalConfig (globalConfigPath ); err != nil {
29+ fmt .Printf ("Error loading global config: %v\n " , err )
30+ os .Exit (1 )
31+ }
32+ },
2633}
2734
2835// Execute adds all child commands to the root command and sets flags appropriately.
@@ -37,6 +44,8 @@ func init() {
3744 rootCmd .AddCommand (generateCmd )
3845 rootCmd .AddCommand (genPassCmd )
3946 rootCmd .AddCommand (startCmd )
47+ rootCmd .AddCommand (startWebCmd )
48+ rootCmd .AddCommand (startDNSCmd )
4049 rootCmd .AddCommand (validateCmd )
4150 rootCmd .AddCommand (listCmd )
4251 rootCmd .AddCommand (pluginsCmd )
@@ -45,7 +54,8 @@ func init() {
4554 startCmd .Flags ().BoolVarP (& benchMode , "bench" , "b" , false , "Enable benchmark mode" )
4655
4756 // Global flags
48- rootCmd .PersistentFlags ().StringVarP (& configPath , "config" , "c" , "" , "Path to specific configuration file" )
57+ rootCmd .PersistentFlags ().StringVarP (& configPath , "config" , "c" , "" , "Path to specific site configuration file" )
58+ rootCmd .PersistentFlags ().StringVar (& globalConfigPath , "global-config" , "" , "Path to specific global configuration file" )
4959}
5060
5161var generateCmd = & cobra.Command {
@@ -155,21 +165,10 @@ var startCmd = &cobra.Command{
155165}
156166
157167func start (cmd * cobra.Command , args []string ) {
158- var configs []config.SiteConfig
159- var err error
160-
161- if configPath != "" {
162- configs , err = config .LoadConfigsFromFile (configPath )
163- if err != nil {
164- fmt .Printf ("Error loading config from %s: %v\n " , configPath , err )
165- os .Exit (1 )
166- }
167- } else {
168- configs , err = config .LoadAllConfigs ()
169- if err != nil {
170- fmt .Printf ("Error loading configurations: %v\n " , err )
171- os .Exit (1 )
172- }
168+ configs , err := loadConfigs ()
169+ if err != nil {
170+ fmt .Printf ("Error loading configurations: %v\n " , err )
171+ os .Exit (1 )
173172 }
174173
175174 if len (configs ) == 0 {
@@ -181,8 +180,8 @@ func start(cmd *cobra.Command, args []string) {
181180 os .Exit (1 )
182181 }
183182
184- fmt .Println ("Starting servers ..." )
185- server .StartServers (configs , tuiMode , benchMode )
183+ fmt .Println ("Starting full GoUp server (Web + DNS) ..." )
184+ server .StartServers (configs , tuiMode , benchMode , server . ModeAll )
186185
187186 // Wait indefinitely if not in TUI mode, the servers will keep running
188187 // and loggers will keep writing to both the stdout and the log files.
@@ -191,6 +190,53 @@ func start(cmd *cobra.Command, args []string) {
191190 }
192191}
193192
193+ var startWebCmd = & cobra.Command {
194+ Use : "start-web" ,
195+ Short : "Start only the web server" ,
196+ Run : startWeb ,
197+ }
198+
199+ func startWeb (cmd * cobra.Command , args []string ) {
200+ configs , err := loadConfigs ()
201+ if err != nil {
202+ fmt .Printf ("Error loading configurations: %v\n " , err )
203+ os .Exit (1 )
204+ }
205+
206+ fmt .Println ("Starting GoUp Web Server..." )
207+ server .StartServers (configs , tuiMode , benchMode , server .ModeWeb )
208+
209+ if ! tuiMode {
210+ select {}
211+ }
212+ }
213+
214+ var startDNSCmd = & cobra.Command {
215+ Use : "start-dns" ,
216+ Short : "Start only the DNS server" ,
217+ Run : startDNS ,
218+ }
219+
220+ func startDNS (cmd * cobra.Command , args []string ) {
221+ // We might not strictly need site configs for DNS only, but StartServers expects them
222+ // effectively ignoring them if ModeWeb is not set, except for context setup.
223+ configs , _ := loadConfigs ()
224+
225+ fmt .Println ("Starting GoUp DNS Server..." )
226+ server .StartServers (configs , tuiMode , benchMode , server .ModeDNS )
227+
228+ if ! tuiMode {
229+ select {}
230+ }
231+ }
232+
233+ func loadConfigs () ([]config.SiteConfig , error ) {
234+ if configPath != "" {
235+ return config .LoadConfigsFromFile (configPath )
236+ }
237+ return config .LoadAllConfigs ()
238+ }
239+
194240var validateCmd = & cobra.Command {
195241 Use : "validate" ,
196242 Short : "Validate the configuration files" ,
0 commit comments