Git Product home page Git Product logo

go-upstart's Introduction

go-upstart

Go library to interact with upstart jobs

Why?

Because you want to be able to control system services (via upstart) from your go code.

What?

Upstart is the init system that several linux distributions have shipped with (most notably, Ubuntu 12.04 and 14.04). You can read more about it here.

If you use one of these distributions in production, you've probably run something like sudo service ssh restart to control services. This package provides a programmatic way of doing that from go code (without invoking the command in a subshell - because thats feels dirty).

How?

import github.com/amoghe/go-upstart

func main() {
  // Somewhere in your program
  _ = upstart.RestartJob("ssh")
}

This pkg also ships with a cmdline tool (go-upstart-tool is in a subdir - so you won't get it on go install, you'll need to build it by running go build in the appropriate subdir under your$GOPATH).

The tool is useful for testing that the pkg actually works when running on a system that has upstart because it allows you to exercise the functions in this library without writing any go code.

Gotchas!

This lib attempts to detect whether it is on a system where upstart is the init system in a very naive way - by trying to communicate with the upstart manager object. If this fails, it determines that upstart is not available and fails all subsequent operations.

This detection is done exactly once, at pkg initialization. Detection can be retriggered subsequently by using the appropriate Detect() method (which returns a bool, indicating whether we could communicate with upstart).

Even if upstart is detected, and we're able to communicate with it, it is likely that your program may have insufficient privileges to actually control jobs (stop/restart of system services typically needs root access). In these cases the pkg functions return errors, which are quite obtuse. These arise in the underlying dbus lib and this pkg doesn't attempt to differentiate between permission errors and other errors. Patches to improve this are more than welcome!

Also, this package lacks tests because tests would need superuser privileges to actually make requests from the upstart daemon. Any tests written without these privileges would just be testing whether we can exchange messages over dbus, and thats not very interesting.

Contributing

If you feel like this package is missing something or if you find bugs, file an issue (and feel free to throw in a PR)!

License

This pkg is available under the simplified BSD license. See the LICENSE.txt file.

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.