-
Notifications
You must be signed in to change notification settings - Fork 2
/
daemon_control
executable file
·63 lines (47 loc) · 1.49 KB
/
daemon_control
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env ruby
######################################################
###
## File: daemon_control
## Desc: daemon control element of the im_gateway.rb server
#
# NOTE: Supports the following command line arguments:
# start stop restart status
#
# NOTE: The pid file is parent directory of the server as:
# #{server.basename}.pid
require 'pathname'
require 'daemons'
me = Pathname.new __FILE__
usage = <<~USAGE
Usage: #{me.basename} rb_program [start | stop | restart | status]
Where:
rb_program is a path to a Ruby program.
Options:
start start an instance of the rb_program
stop stop all instances of the rb_program
restart stop all instances and restart them afterwards
reload send a SIGHUP to all instances of the rb_program
run start the rb_program and stay on top
zap set the rb_program to a stopped state
status show status (PID) of rb_program instances
NOTE:
A pid (process ID) file is used in the same directory as
the rb_program. It has the same base name with the extension
of '.pid'
USAGE
if ARGV.empty? ||
ARGV.include?('--help') ||
ARGV.include?('-h') ||
%w[start stop restart status].include?(ARGV[0].downcase)
puts usage
exit
end
rb_program = Pathname.new(ARGV.shift)
unless rb_program.exist?
puts <<~ERROR
Error: Program does not exist. #{rb_program}
ERROR
puts usage
exit(-1)
end
Daemons.run(rb_program.realpath)