Skip to content

GoRunner is a simple subprocess runner with graceful shutdown

License

Notifications You must be signed in to change notification settings

imunhatep/gorunner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoRunner is a simple subprocess runner with graceful shutdown

Requires go lang env for compiling.

Features:

  • binary
  • semi-graceful process closing (force killing process after timeout)

Usage

make build
build/gorunner --help

Help

NAME:
   gorunner - Parallel sub-process runner with graceful stop if any sub-process exits

USAGE:
   gorunner --run='/bin/echo "test1"' --run='/bin/echo "test2"' -vv

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --run value, -r value       cli command to run, can be defined multiple times
   --timeout value, -t value   how long to wait before forcing others tasks to exit with sig kill (default: 1m0s)
   --maxprocs value, -j value  controls the number of operating system threads allocated to goroutines (default: 2)
   -v                          log verbosity: info (default: false)
   --vv                        log verbosity: debug (default: false)
   --help, -h                  show help (default: false)

Example

make build && \
    build/gorunner \
    --run="$(pwd)/resources/repeat" \
    --run="$(pwd)/resources/well-cli" \
    --run="$(pwd)/resources/watch.sh $(pwd)/resources/test.conf" \
    -vv

Arguments explanation

  • First --run="$(pwd)/resources/repeat" starts example binary (see source code /resources/repeat.go) with the only purpose to output next text
  • Second --run="$(pwd)/resources/well-cli" starts another example binary (see source code /resources/well-cli.go), have 2 goroutines listening for interruption signals
  • Third --run="$(pwd)/resources/watch.sh $(pwd)/resources/test.conf" a bash script that watches file content and exits on changes

Try to update resources/test.conf file content while running example from other terminal:

date > ./resources/test.conf

Or pressing CTRL+C, that will send SIGINT to sub-processes:

Logging level: warn 
[run2] Watching: /home/aly/w/golang/reloader/resources/test.conf
[run1] reached well.Wait()
[run1] 2020-10-01T12:33:51.529497Z hostname well-cli info: "Tick!" count=20
[run1] 2020-10-01T12:33:51.530047Z hostname well-cli info: "Tick!" count=10
[run0] next
[run1] 2020-10-01T12:33:52.529856Z hostname well-cli info: "Tick!" count=19
[run1] 2020-10-01T12:33:52.530414Z hostname well-cli info: "Tick!" count=9
[run2] /home/aly/w/golang/reloader/resources/test.conf keep..
[run0] next
[run1] 2020-10-01T12:33:53.530575Z hostname well-cli info: "Tick!" count=8
[run1] 2020-10-01T12:33:53.530176Z hostname well-cli info: "Tick!" count=18
[run2] /home/aly/w/golang/reloader/resources/test.conf keep..
^C2020-10-01T12:33:54.397999Z hostname gorunner warning: "well: got signal" delay=5 signal="interrupt"
[run1] 2020-10-01T12:33:54.398105Z hostname well-cli warning: "well: got signal" delay=5 signal="interrupt"
[run1] 2020-10-01T12:33:54.530831Z hostname well-cli info: "Tick!" count=7
[run1] 2020-10-01T12:33:54.531918Z hostname well-cli info: "Tick!" count=17
[run1] 2020-10-01T12:33:55.531097Z hostname well-cli info: "Tick!" count=6
[run1] 2020-10-01T12:33:55.532101Z hostname well-cli info: "Tick!" count=16
[run1] 2020-10-01T12:33:56.531234Z hostname well-cli info: "Tick!" count=5
[run1] 2020-10-01T12:33:56.532242Z hostname well-cli info: "Tick!" count=15
[run1] 2020-10-01T12:33:57.531273Z hostname well-cli info: "Tick!" count=4
[run1] 2020-10-01T12:33:57.532359Z hostname well-cli info: "Tick!" count=14
[run1] 2020-10-01T12:33:58.531399Z hostname well-cli info: "Tick!" count=3
[run1] 2020-10-01T12:33:58.532500Z hostname well-cli info: "Tick!" count=13
[run1] 2020-10-01T12:33:59.531634Z hostname well-cli info: "Sick.. exiting!"
[run1] Exiting
[run1] Exiting
[run1] 2020-10-01T12:33:59.532732Z hostname well-cli info: "Sick.. exiting!"
signal: interrupt

About

GoRunner is a simple subprocess runner with graceful shutdown

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published