mirror of
https://github.com/fosrl/olm.git
synced 2026-02-07 21:46:40 +00:00
3
main.go
3
main.go
@@ -177,7 +177,8 @@ func runOlmMainWithArgs(ctx context.Context, cancel context.CancelFunc, signalCt
|
|||||||
|
|
||||||
// Load configuration from file, env vars, and CLI args
|
// Load configuration from file, env vars, and CLI args
|
||||||
// Priority: CLI args > Env vars > Config file > Defaults
|
// Priority: CLI args > Env vars > Config file > Defaults
|
||||||
config, showVersion, showConfig, err := LoadConfig(os.Args[1:])
|
// Use the passed args parameter instead of os.Args[1:] to support Windows service mode
|
||||||
|
config, showVersion, showConfig, err := LoadConfig(args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to load configuration: %v\n", err)
|
fmt.Printf("Failed to load configuration: %v\n", err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -99,15 +99,32 @@ func (s *olmService) Execute(args []string, r <-chan svc.ChangeRequest, changes
|
|||||||
// Continue with empty args if loading fails
|
// Continue with empty args if loading fails
|
||||||
savedArgs = []string{}
|
savedArgs = []string{}
|
||||||
}
|
}
|
||||||
|
s.elog.Info(1, fmt.Sprintf("Loaded saved service args: %v", savedArgs))
|
||||||
|
|
||||||
// Combine service start args with saved args, giving priority to service start args
|
// Combine service start args with saved args, giving priority to service start args
|
||||||
|
// Note: When the service is started via SCM, args[0] is the service name
|
||||||
|
// When started via s.Start(args...), the args passed are exactly what we provide
|
||||||
finalArgs := []string{}
|
finalArgs := []string{}
|
||||||
|
|
||||||
|
// Check if we have args passed directly to Execute (from s.Start())
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
// Skip the first arg which is typically the service name
|
// The first arg from SCM is the service name, but when we call s.Start(args...),
|
||||||
if len(args) > 1 {
|
// the args we pass become args[1:] in Execute. However, if started by SCM without
|
||||||
|
// args, args[0] will be the service name.
|
||||||
|
// We need to check if args[0] looks like the service name or a flag
|
||||||
|
if len(args) == 1 && args[0] == serviceName {
|
||||||
|
// Only service name, no actual args
|
||||||
|
s.elog.Info(1, "Only service name in args, checking saved args")
|
||||||
|
} else if len(args) > 1 && args[0] == serviceName {
|
||||||
|
// Service name followed by actual args
|
||||||
finalArgs = append(finalArgs, args[1:]...)
|
finalArgs = append(finalArgs, args[1:]...)
|
||||||
|
s.elog.Info(1, fmt.Sprintf("Using service start parameters (after service name): %v", finalArgs))
|
||||||
|
} else {
|
||||||
|
// Args don't start with service name, use them all
|
||||||
|
// This happens when args are passed via s.Start(args...)
|
||||||
|
finalArgs = append(finalArgs, args...)
|
||||||
|
s.elog.Info(1, fmt.Sprintf("Using service start parameters (direct): %v", finalArgs))
|
||||||
}
|
}
|
||||||
s.elog.Info(1, fmt.Sprintf("Using service start parameters: %v", finalArgs))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no service start parameters, use saved args
|
// If no service start parameters, use saved args
|
||||||
@@ -116,6 +133,7 @@ func (s *olmService) Execute(args []string, r <-chan svc.ChangeRequest, changes
|
|||||||
s.elog.Info(1, fmt.Sprintf("Using saved service args: %v", finalArgs))
|
s.elog.Info(1, fmt.Sprintf("Using saved service args: %v", finalArgs))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.elog.Info(1, fmt.Sprintf("Final args to use: %v", finalArgs))
|
||||||
s.args = finalArgs
|
s.args = finalArgs
|
||||||
|
|
||||||
// Start the main olm functionality
|
// Start the main olm functionality
|
||||||
@@ -325,12 +343,15 @@ func removeService() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func startService(args []string) error {
|
func startService(args []string) error {
|
||||||
// Save the service arguments as backup
|
fmt.Printf("Starting service with args: %v\n", args)
|
||||||
if len(args) > 0 {
|
|
||||||
err := saveServiceArgs(args)
|
// Always save the service arguments so they can be loaded on service restart
|
||||||
if err != nil {
|
err := saveServiceArgs(args)
|
||||||
return fmt.Errorf("failed to save service args: %v", err)
|
if err != nil {
|
||||||
}
|
fmt.Printf("Warning: failed to save service args: %v\n", err)
|
||||||
|
// Continue anyway, args will still be passed directly
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Saved service args to: %s\n", getServiceArgsPath())
|
||||||
}
|
}
|
||||||
|
|
||||||
m, err := mgr.Connect()
|
m, err := mgr.Connect()
|
||||||
@@ -346,6 +367,7 @@ func startService(args []string) error {
|
|||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
// Pass arguments directly to the service start call
|
// Pass arguments directly to the service start call
|
||||||
|
// Note: These args will appear in Execute() after the service name
|
||||||
err = s.Start(args...)
|
err = s.Start(args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to start service: %v", err)
|
return fmt.Errorf("failed to start service: %v", err)
|
||||||
|
|||||||
@@ -348,6 +348,9 @@ func (c *Client) getToken() (string, []ExitNode, error) {
|
|||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-CSRF-Token", "x-csrf-protection")
|
req.Header.Set("X-CSRF-Token", "x-csrf-protection")
|
||||||
|
|
||||||
|
// print out the request for debugging
|
||||||
|
logger.Debug("Requesting token from %s with body: %s", req.URL.String(), string(jsonData))
|
||||||
|
|
||||||
// Make the request
|
// Make the request
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
if tlsConfig != nil {
|
if tlsConfig != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user