A library for service application daemonize.

Features

  • Easy switch from terminal application to background service.

Installation

Add this line to your app’s Gemfile:

gem 'app-service'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install app-service
or
$ gem install -l app-service-x.x.x.gem

Usage

Example

require  "app/service"

# execute service application with default settings.
App::Service.setup( ARGV.shift )

# execute service application with custom settings.
App::Service.setup( ARGV.shift, **options )
# run on terminal application.
ruby sample.rb  run

# start background service.
ruby sample.rb  start

# stop background service.
ruby sample.rb  stop

# restart background service.
ruby sample.rb  restart

# show status of background service.
ruby sample.rb  status

Reference

Setup App::Service.

App::Service.setup( mode = nil, **options )
  • Result:

    • none.

  • Parameter:

    • mode: Run mode. [run start stop restart status]

    • argv: Commandline arguments. (default: ARGV)

    • app_dir: Application working directory. (default: "..")

    • tmp_dir: Temporary directory. (default: "tmp")

    • log_dir: Logging directory. (default: "log")

    • log_sync: Logging sync mode. (default: false)

    • shift_age: Log file count, or log change event. [0.., "daily", "weekly", "monthly"] (default: 0)

    • shift_size: Log rotation limit size. (default: 1048576)

    • log_level: Log level. (default: Logger::Severity::DEBUG) [0:DEBUG, 1:INFO, 2:WARN, 3:ERROR, 4:FATAL, 5:UNKNOWN]

    • progname: (default: nil)

    • formatter: (default: Formatter.new)

    • datetime_format: (default: '%Y-%m-%d %H:%M:%S')

    • shift_period_suffix: (default: '%Y%m%d')

Shutdown App::Service.

App::Service.shutdown( cond = 0 )
  • Result:

    • none.

  • Parameter:

    • cond: process exit condition. (default: 0)

Get run mode.

  • Result:

    • String: Run mode. [run start stop restart status]

  • Parameter:

    • none.

Get logger instance.

  • Result:

    • Logger instance.

  • Parameter:

    • none.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/arimay/app-service.

License

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

Copyright (c) ARIMA Yasuhiro <[email protected]>