Skip to content

Commit

Permalink
usage
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasng committed Dec 8, 2019
1 parent 41c60fd commit 648e69a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Service Shark is:
- easy to use
- lightweight (~2 MB)
- has zero runtime dependencies (no .NET Framework, Java, ...)
- [12factor/config](https://12factor.net/config) support
- written in [golang](https://golang.org/)

Service Shark is not:
Expand All @@ -26,11 +27,6 @@ Service Shark is not:
https://github.com/matthiasng/service-shark/releases/latest
```

#### Scoop
```
#todo setup scoop bucket + goreleaser
```

### Compiling from source
```
git clone https://github.com/matthiasng/service-shark.git
Expand All @@ -40,4 +36,25 @@ go build -o service-shark.exe main.go

## Usage

#todo
```
-cmd string
Command [required]
-logdir string
Log directory.
File name: {name}_YYYY-MM-DD_HH-MM-SS (default "./log")
-name string
Service name [required]
-workdir string
Working directory [required]
-- (terminator)
Pass all arguments after the terminator "--" to command.
Bind argument to environment variable with "env:{VAR_NAME}".
```

Exampe
```
service-shark.exe -name MyService -workdir C:/MyService -cmd java -- -jar MyProg.jar -Xmx1G -myArg "env:TEST_VALUE"
```
Service Shark will run ``java`` with ``-jar MyProg.jar -Xmx1G -myArg "123"`` from ``C:/MyService``.

See [example/test-example-service.ps1](./example/test-example-service.ps1) for a complate example.
2 changes: 1 addition & 1 deletion command/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (h *Host) init(env service.Environment) error {
return err
}

logFileName := fmt.Sprintf("%s_%s.log", h.Name(), time.Now().Format("02-01-2006_15-04-05"))
logFileName := fmt.Sprintf("%s_%s.log", h.Name(), time.Now().Format("2006-01-02-_15-04-05"))
logFilePath := path.Join(h.Arguments.LogDirectory, logFileName)

logFile, err := os.Create(logFilePath)
Expand Down
14 changes: 11 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@ var arguments = cli.Arguments{}

func init() {
flag.CommandLine.Usage = func() {
fmt.Println("Usage of Service Shark:")
fmt.Println("Service Shark:")
fmt.Println(" Host any executable as a Windows service.")
fmt.Println("Usage:")
flag.PrintDefaults()
fmt.Println(" -- (terminator)")
fmt.Println(` Pass all arguments after the terminator "--" to command.`)
fmt.Println(` Bind argument to environment variable with "env:{VAR_NAME}".`)
fmt.Println("Example:")
fmt.Println(` service-shark.exe ... -cmd java -- -jar test.jar -Xmx1G -myArg "env:MY_VALUE"`)
fmt.Println(` => java -jar test.jar -Xmx1G -myArg "my env value"`)
}

flag.StringVar(&arguments.Name, "name", "", "Service name [required]")
flag.StringVar(&arguments.WorkingDirectory, "workdir", "", "Working directory [required]")
flag.StringVar(&arguments.LogDirectory, "logdir", "./log", "Log directory. Absolute path or relative to working directory.")
flag.StringVar(&arguments.Command, "cmd", "", "Command [required]")
flag.StringVar(&arguments.LogDirectory, "logdir", "./log", "Log directory.\nFile name: {name}_YYYY-MM-DD_HH-MM-SS")
flag.StringVar(&arguments.Command, "cmd", "", `Command [required]`)

flag.Parse()
}
Expand Down

0 comments on commit 648e69a

Please sign in to comment.