Coder Social home page Coder Social logo

bark's Introduction

bark

a golang watchdog for fast detection and restart of child processes

summary

Watch a child process and get notified immediately upon status change (such as termination). Remedies deficiency in the Go stdlib.

relevant inspiration:

a) detection of child process failure on OSX using the golang stdlib os.Process.Wait can take 30 seconds. Ouch.

b) Ian Lance Taylor suggested a Wait4 approach in this thread, and Igor Bukanov indicates it worked well for his use case; I confirm here that response is rapid.

http://grokbase.com/t/gg/golang-nuts/157dmnz8dq/go-nuts-os-process-wait-and-signals-before-process-dies

https://groups.google.com/forum/#!searchin/golang-nuts/os.Process.Wait$20and$20signals$20before$20process$20dies/golang-nuts/Xr7TP_yF5dQ/ksjZzddYgpcJ

what bark provides

The bark library provides the ability to monitor a child process, to automatically restart it if it fails, and to shut it down (SIGKILL or kill -9) upon request.

Simple and fast.

use / example


import (
  "github.com/betable/bark"
)

...
watcher := NewWatchdog(nil, "/path/to/child/executable")
watcher.Start() // launchs proc, automatically restarts it

// give it a second to get started
time.Sleep(2 * time.Millisecond)

// current Process ID is available here; if 0 then
// it is between restarts and you should poll again.
pid := <-watcher.CurrentPid

// ready to stop both child and watchdog
watcher.TermChildAndStopWatchdog <- true

// wait for shutdown of child and watchdog to complete
<-watcher.Done
fmt.Print("watchdog and child pid shutdown.\n")
...

rarely needed

Also available, the ReqStopWatchdog channel will shutdown only the watchdog, and leave the child process unmonitored:

watcher.ReqStopWatchdog <- true

Copyright (c) 2016 Betable.com and Rubicon Media, LLC.

License: Apache 2.0

bark's People

Contributors

glycerine avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.