0.0
The project is in a healthy, maintained state
App::Service is a library for service application daemonize.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
 Project Readme

App::Service

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.

App::Service.mode
  • Result:

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

  • Parameter:

    • none.

Get logger instance.

App::Service.logger
  • 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 <arima.yasuhiro@gmail.com>