Module: Rinit

Extended by:
ProcessUtils
Defined in:
lib/rinit.rb,
lib/rinit/version.rb,
lib/rinit/commands.rb,
lib/rinit/exceptions.rb,
lib/rinit/process_utils.rb,
lib/rinit/template_builder.rb

Defined Under Namespace

Modules: ProcessUtils Classes: CommandException, ProcessException, TemplateBuilder

Constant Summary collapse

VERSION =
"0.1.5"

Class Method Summary collapse

Methods included from ProcessUtils

get_pid_from_file, is_process_running?, kill_process, may_the_fork_be_with_you, pidfile_cleanup, write_pidfile

Class Method Details

.restart(pidfile, opts = {}) ⇒ Object

Examples:

"/tmp/foo.pid", {cmd: "/tmp/foo_daemon.rb", chuid: "foo", pidfile: "/tmp/foo.pid"}

Parameters:

  • pidfile (String)

    the full pidfile path

  • opts (Hash) (defaults to: {})

    see #start



36
37
38
39
# File 'lib/rinit/commands.rb', line 36

def restart(pidfile, opts={})
  stop(pidfile)
  start(opts)
end

.start(opts = {}) ⇒ nil

Examples:

{cmd: "/tmp/foo_daemon.rb", chuid: "foo", pidfile: "/tmp/foo.pid"}

Parameters:

  • opts (Hash) (defaults to: {})

    opts :cmd, :chuid, :pidfile

Returns:

  • (nil)


11
12
13
14
15
16
# File 'lib/rinit/commands.rb', line 11

def start(opts={})
  command = opts.fetch(:cmd) { raise Rinit::CommandException.new "No command given" }
  user    = opts.fetch(:chuid) { raise Rinit::CommandException.new "No user given" }
  pidfile = opts.fetch(:pidfile) { raise Rinit::CommandException.new "No pidfile was given" }
  may_the_fork_be_with_you(command, pidfile)
end

.status(pidfile) ⇒ Object

Parameters:

  • pidfile (String)

    the full pidfile path



27
28
29
# File 'lib/rinit/commands.rb', line 27

def status pidfile
  is_process_running?(pidfile)
end

.stop(pidfile) ⇒ nil

Returns if there were not any errors.

Parameters:

  • pidfile (String)

    the full pidfile path

Returns:

  • (nil)

    if there were not any errors



20
21
22
23
# File 'lib/rinit/commands.rb', line 20

def stop(pidfile)
  kill_process(pidfile)
  pidfile_cleanup(pidfile)
end