-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
start.rb
48 lines (42 loc) · 1.18 KB
/
start.rb
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
# frozen_string_literal: true
#
# This code is based on https://github.com/fohte/rubocop-daemon.
#
# Copyright (c) 2018 Hayato Kawai
#
# The MIT License (MIT)
#
# https://github.com/fohte/rubocop-daemon/blob/master/LICENSE.txt
#
module RuboCop
module Server
module ClientCommand
# This class is a client command to start server process.
# @api private
class Start < Base
def initialize(detach: true)
@detach = detach
super()
end
def run
if Server.running?
warn "RuboCop server (#{Cache.pid_path.read}) is already running."
return
end
Cache.acquire_lock do |locked|
unless locked
# Another process is already starting server,
# so wait for it to be ready.
Server.wait_for_running_status!(true)
exit 0
end
Cache.write_version_file(RuboCop::Version::STRING)
host = ENV.fetch('RUBOCOP_SERVER_HOST', '127.0.0.1')
port = ENV.fetch('RUBOCOP_SERVER_PORT', 0)
Server::Core.new.start(host, port, detach: @detach)
end
end
end
end
end
end