Class: Cline::Server
- Inherits:
-
Object
- Object
- Cline::Server
- Defined in:
- lib/cline/server.rb
Class Method Summary collapse
- .clean ⇒ Object
- .client_process? ⇒ Boolean
- .pid ⇒ Object
- .pid_file ⇒ Object
- .running? ⇒ Boolean
- .socket_file ⇒ Object
- .start ⇒ Object
- .stop ⇒ Object
Instance Method Summary collapse
-
#initialize(socket_file) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
Constructor Details
#initialize(socket_file) ⇒ Server
Returns a new instance of Server.
57 58 59 60 |
# File 'lib/cline/server.rb', line 57 def initialize(socket_file) @socket_file = socket_file @server = UNIXServer.new(@socket_file.to_s) end |
Class Method Details
.clean ⇒ Object
31 32 33 34 |
# File 'lib/cline/server.rb', line 31 def clean File.unlink pid_file File.unlink socket_file end |
.client_process? ⇒ Boolean
40 41 42 |
# File 'lib/cline/server.rb', line 40 def client_process? Process.pid != pid end |
.pid ⇒ Object
44 45 46 |
# File 'lib/cline/server.rb', line 44 def pid Integer(pid_file.read) end |
.pid_file ⇒ Object
48 49 50 |
# File 'lib/cline/server.rb', line 48 def pid_file Pathname.new(Cline.cline_dir).join('cline.pid') end |
.running? ⇒ Boolean
36 37 38 |
# File 'lib/cline/server.rb', line 36 def running? socket_file.exist? end |
.socket_file ⇒ Object
52 53 54 |
# File 'lib/cline/server.rb', line 52 def socket_file Pathname.new(Cline.cline_dir).join('cline.sock') end |
.start ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cline/server.rb', line 11 def start raise %(Socket file #{socket_file} already exists.) if running? Process.daemon pid_file.open 'w' do |pid| pid.write Process.pid end Signal.trap(:KILL) { Server.clean } new(socket_file).run end |
.stop ⇒ Object
25 26 27 28 29 |
# File 'lib/cline/server.rb', line 25 def stop raise %(Server isn't running) unless running? Process.kill :TERM, pid end |