Skip to content

Commit

Permalink
Rework Windows Services (#426)
Browse files Browse the repository at this point in the history
We have a couple of hard to support windows corner cases. I think these stem from the difference between windows services, and traditional unix daemons. This makes them more approachable.

**Moves the windows startup process** to being explicit, instead of autodetected on whether it's in windows and non-interactive. Now there are `svc` and `svc-foreground` subcommands. This should remove a source of strange errors when interactivity is mis-detected, and also makes it easier to run launcher in various modes for debugging.

**Remove the service management** This removes the service management tools. That's better handled by the packaging.

**Change the flag parsing** from `kit/env` to `ff`. This should allow us to more easily pass in a flag file.
  • Loading branch information
directionless authored Feb 20, 2019
1 parent 0c18bb8 commit 1e7be61
Show file tree
Hide file tree
Showing 11 changed files with 315 additions and 450 deletions.
14 changes: 0 additions & 14 deletions cmd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,6 @@ func runSocket(args []string) error {
return nil
}

func runSubcommands() error {
var run func([]string) error
switch os.Args[1] {
case "socket":
run = runSocket
case "query":
run = runQuery
case "flare":
run = runFlare
}
err := run(os.Args[2:])
return errors.Wrapf(err, "running subcommand %s", os.Args[1])
}

// run the launcher daemon
func runLauncher(ctx context.Context, cancel func(), opts *options, logger log.Logger) error {
// determine the root directory, create one if it's not provided
Expand Down
39 changes: 22 additions & 17 deletions cmd/launcher/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build !windows

package main

import (
Expand All @@ -10,7 +8,6 @@ import (
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/kolide/kit/logutil"
"github.com/kolide/kit/version"
"github.com/pkg/errors"
)

Expand All @@ -27,24 +24,12 @@ func main() {
}
}

opts, err := parseOptions()
opts, err := parseOptions(os.Args[1:])
if err != nil {
level.Info(logger).Log("err", err)
os.Exit(1)
}

// handle --version
if opts.printVersion {
version.PrintFull()
os.Exit(0)
}

// handle --usage
if opts.developerUsage {
developerUsage()
os.Exit(0)
}

logger = logutil.NewServerLogger(opts.debug)

ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -56,14 +41,16 @@ func main() {
}

func isSubCommand() bool {
if len(os.Args) != 2 {
if len(os.Args) < 2 {
return false
}

subCommands := []string{
"socket",
"query",
"flare",
"svc",
"svc-fg",
}

for _, sc := range subCommands {
Expand All @@ -74,3 +61,21 @@ func isSubCommand() bool {

return false
}

func runSubcommands() error {
var run func([]string) error
switch os.Args[1] {
case "socket":
run = runSocket
case "query":
run = runQuery
case "flare":
run = runFlare
case "svc":
run = runWindowsSvc
case "svc-fg":
run = runWindowsSvcForeground
}
err := run(os.Args[2:])
return errors.Wrapf(err, "running subcommand %s", os.Args[1])
}
268 changes: 0 additions & 268 deletions cmd/launcher/main_windows.go

This file was deleted.

Loading

0 comments on commit 1e7be61

Please sign in to comment.