https://github.com/kenjij/kajiki
A simple gem to build daemons
https://github.com/kenjij/kajiki
daemon option-parsing ruby
Last synced: about 1 year ago
JSON representation
A simple gem to build daemons
- Host: GitHub
- URL: https://github.com/kenjij/kajiki
- Owner: kenjij
- License: mit
- Created: 2015-02-24T06:42:45.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2020-01-14T00:23:54.000Z (over 6 years ago)
- Last Synced: 2024-04-26T21:20:58.502Z (about 2 years ago)
- Topics: daemon, option-parsing, ruby
- Language: Ruby
- Homepage: https://kenjij.github.io/kajiki/
- Size: 710 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Kajiki
[](http://badge.fury.io/rb/kajiki) [](https://codeclimate.com/github/kenjij/kajiki) [](https://hakiri.io/github/kenjij/kajiki/master)
A simple gem to build daemons.
It provides basic functions to start and stop a daemon process. It also parses command-line options.
## Requirements
- Ruby 2.0.0 <=
Kajiki has no gem dependencies. It uses [Optimist](https://rubygems.org/gems/optimist), but it's embedded.
## Getting Started
### Install
```
$ gem install kajiki
```
### Code
```ruby
require 'kajiki'
opts = Kajiki.preset_options(:minimal)
Kajiki.run(opts) do |command|
case command
when 'start'
while true
puts 'Are we there yet?'
sleep(5)
end
when 'stop'
puts 'Arrived!'
end
end
```
### Use
To see help:
```
$ myapp -h
Usage: myapp [options] {start|stop}
-d, --daemonize Run in the background
-p, --pid= Store PID to file
-h, --help Show this message
```
To start your app as a daemon:
```
$ myapp -d -p ~/myapp.pid start
```
To stop your app running as a daemon:
```
$ myapp -p ~/myapp.pid stop
```
### More
There are two ways to use Kajiki.
1. With preset command-line option parsing and auto daemonizing
2. Custom option parsing and semi-auto daemonizing