Ruby-Launchd - Control Mac OS X services with Ruby

Ruby-Launchd is like launchctl (or the famous lunchy). It lets you easily create, start and stop services on Mac OS X, but with Ruby.

Installation

Add this line to your application's Gemfile:

gem 'launchd'

And then execute:

$ bundle

Or install it yourself as:

$ gem install launchd

Usage

Initialize a service object:

service = Launchd::Service.new,
  label:             'com.example.chunkybacon',     # Required
  program_arguments: %w(/usr/sbin/chunkyd --bacon), # Required
  keep_alive:        true                           # Optional

Only label and program_arguments are required. See man launchd.plist(5) for all possible properties.

Then stop, overwrite and start the service with the given properties (i.e. for deployment):

service.restart

IMPORTANT: If you run the code as root (sudo), the daemon will get installed as system-wide service under /Library/LaunchDaemons. Otherwise it get saved as current user's agent inside ~/Library/LaunchAgents which will only run after login.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.