locd 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/NAME +1 -0
- data/VERSION +1 -1
- data/config/default.lit.yaml +43 -0
- data/lib/locd.rb +0 -3
- data/lib/locd/agent.rb +50 -13
- data/lib/locd/agent/proxy.rb +27 -12
- data/lib/locd/agent/rotate_logs.rb +2 -2
- data/lib/locd/agent/site.rb +4 -1
- data/lib/locd/agent/system.rb +47 -12
- data/lib/locd/cli/command/agent.rb +48 -404
- data/lib/locd/cli/command/agent/add.rb +12 -4
- data/lib/locd/cli/command/agent/ls.rb +56 -0
- data/lib/locd/cli/command/agent/open.rb +53 -0
- data/lib/locd/cli/command/agent/plist.rb +43 -0
- data/lib/locd/cli/command/agent/restart.rb +43 -0
- data/lib/locd/cli/command/agent/rm.rb +46 -0
- data/lib/locd/cli/command/agent/shared.rb +253 -0
- data/lib/locd/cli/command/agent/start.rb +38 -0
- data/lib/locd/cli/command/agent/status.rb +41 -0
- data/lib/locd/cli/command/agent/stop.rb +39 -0
- data/lib/locd/cli/command/agent/tail.rb +82 -0
- data/lib/locd/cli/command/agent/truncate_logs.rb +65 -0
- data/lib/locd/cli/command/agent/update.rb +48 -0
- data/lib/locd/cli/command/base.rb +35 -3
- data/lib/locd/cli/command/job.rb +29 -36
- data/lib/locd/cli/command/job/add.rb +57 -0
- data/lib/locd/cli/command/main.rb +3 -3
- data/lib/locd/cli/command/proxy.rb +44 -20
- data/lib/locd/cli/command/rotate_logs.rb +28 -49
- data/lib/locd/cli/command/rotate_logs/add.rb +44 -0
- data/lib/locd/config.rb +88 -20
- data/lib/locd/config/types.rb +56 -27
- data/lib/locd/newsyslog.rb +23 -24
- data/lib/locd/proxy.rb +21 -9
- data/lib/locd/version.rb +94 -5
- data/locd.gemspec +10 -4
- metadata +67 -9
@@ -16,7 +16,7 @@ module Command
|
|
16
16
|
# Definitions
|
17
17
|
# =======================================================================
|
18
18
|
|
19
|
-
class Agent <
|
19
|
+
class Agent < Base
|
20
20
|
|
21
21
|
desc "add [OPTIONS] -- CMD_TEMPLATE...",
|
22
22
|
"Add an agent that runs a command in the current directory"
|
@@ -28,11 +28,18 @@ class Agent < Locd::CLI::Command::Base
|
|
28
28
|
available at http://yard.my_gem.test:8888 (unless Loc'd is running on a
|
29
29
|
different port than 8888).
|
30
30
|
|
31
|
-
locd site add
|
31
|
+
locd site add \\
|
32
|
+
--name=yard.my_gem.test \\
|
33
|
+
-- bundle exec yard server \\
|
34
|
+
--reload \\
|
35
|
+
--port {port} \\
|
36
|
+
--bind {bind}
|
32
37
|
|
33
38
|
END
|
34
39
|
|
35
|
-
|
40
|
+
include_shared t[ groups: t.HasAny( :write,
|
41
|
+
:add,
|
42
|
+
:respond_with_agents ) ]
|
36
43
|
|
37
44
|
def add *cmd_template, **kwds
|
38
45
|
logger.trace __method__.to_s,
|
@@ -42,7 +49,7 @@ class Agent < Locd::CLI::Command::Base
|
|
42
49
|
|
43
50
|
# Merge all the keywords together into the format needed to call
|
44
51
|
# {Locd::Agent.add}
|
45
|
-
kwds.merge! **option_kwds( :force, groups: [:write] ),
|
52
|
+
kwds.merge! **option_kwds( :force, groups: [ :write ] ),
|
46
53
|
cmd_template: cmd_template
|
47
54
|
|
48
55
|
# Check args
|
@@ -69,6 +76,7 @@ class Agent < Locd::CLI::Command::Base
|
|
69
76
|
end
|
70
77
|
end
|
71
78
|
|
79
|
+
|
72
80
|
# /Namespace
|
73
81
|
# =======================================================================
|
74
82
|
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
|
5
|
+
# Refinements
|
6
|
+
# =======================================================================
|
7
|
+
|
8
|
+
require 'nrser/refinements/types'
|
9
|
+
using NRSER::Types
|
10
|
+
|
11
|
+
|
12
|
+
# Namespace
|
13
|
+
# =======================================================================
|
14
|
+
|
15
|
+
module Locd
|
16
|
+
module CLI
|
17
|
+
module Command
|
18
|
+
|
19
|
+
|
20
|
+
# Definitions
|
21
|
+
# =======================================================================
|
22
|
+
|
23
|
+
class Agent < Base
|
24
|
+
|
25
|
+
desc "ls",
|
26
|
+
"List agents"
|
27
|
+
|
28
|
+
map list: :ls
|
29
|
+
|
30
|
+
include_shared t[ name: :pattern, kind: :argument ],
|
31
|
+
required: false,
|
32
|
+
default: nil
|
33
|
+
|
34
|
+
include_shared t[ groups: :pattern, kind: :option ]
|
35
|
+
|
36
|
+
include_shared t[ groups: :respond_with_agents ]
|
37
|
+
|
38
|
+
def ls
|
39
|
+
results = if pattern.nil?
|
40
|
+
agent_class.all
|
41
|
+
else
|
42
|
+
agent_class.list pattern, **option_kwds( groups: :pattern )
|
43
|
+
end
|
44
|
+
|
45
|
+
respond results.values.sort
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
# /Namespace
|
52
|
+
# =======================================================================
|
53
|
+
|
54
|
+
end # module Command
|
55
|
+
end # module CLI
|
56
|
+
end # module Locd
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'nrser/refinements/types'
|
5
|
+
using NRSER::Types
|
6
|
+
|
7
|
+
|
8
|
+
# Namespace
|
9
|
+
# =======================================================================
|
10
|
+
|
11
|
+
module Locd
|
12
|
+
module CLI
|
13
|
+
module Command
|
14
|
+
|
15
|
+
|
16
|
+
# Definitions
|
17
|
+
# =======================================================================
|
18
|
+
|
19
|
+
class Agent < Base
|
20
|
+
|
21
|
+
desc "open",
|
22
|
+
"Open an agent's URL in the browser"
|
23
|
+
|
24
|
+
include_shared t[ groups: t.HasAny( :pattern, :multi, :start ) ]
|
25
|
+
|
26
|
+
option :start,
|
27
|
+
desc: %{ Start any stopped agents before opening },
|
28
|
+
type: :boolean,
|
29
|
+
default: true
|
30
|
+
|
31
|
+
def open
|
32
|
+
Locd::Agent::Proxy.get!.ensure_running
|
33
|
+
|
34
|
+
find_multi!( pattern ).each do |agent|
|
35
|
+
if options[:start]
|
36
|
+
agent.ensure_running( **option_kwds( groups: :start ) )
|
37
|
+
end
|
38
|
+
|
39
|
+
Cmds! "open %s", agent.url
|
40
|
+
|
41
|
+
logger.info "Opened agent `#{ agent.label }` at #{ agent.url }"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
# /Namespace
|
49
|
+
# =======================================================================
|
50
|
+
|
51
|
+
end # module Command
|
52
|
+
end # module CLI
|
53
|
+
end # module Locd
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'nrser/refinements/types'
|
5
|
+
using NRSER::Types
|
6
|
+
|
7
|
+
|
8
|
+
# Namespace
|
9
|
+
# =======================================================================
|
10
|
+
|
11
|
+
module Locd
|
12
|
+
module CLI
|
13
|
+
module Command
|
14
|
+
|
15
|
+
|
16
|
+
# Definitions
|
17
|
+
# =======================================================================
|
18
|
+
|
19
|
+
class Agent < Base
|
20
|
+
|
21
|
+
desc "plist",
|
22
|
+
"Print an agent's launchd property list"
|
23
|
+
|
24
|
+
include_shared t[ groups: :pattern ]
|
25
|
+
|
26
|
+
def plist
|
27
|
+
agent = find_only! pattern
|
28
|
+
|
29
|
+
if options[:json] || options[:yaml]
|
30
|
+
respond agent.plist
|
31
|
+
else
|
32
|
+
respond agent.path.read
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
# /Namespace
|
39
|
+
# =======================================================================
|
40
|
+
|
41
|
+
end # module Command
|
42
|
+
end # module CLI
|
43
|
+
end # module Locd
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'nrser/refinements/types'
|
5
|
+
using NRSER::Types
|
6
|
+
|
7
|
+
|
8
|
+
# Namespace
|
9
|
+
# =======================================================================
|
10
|
+
|
11
|
+
module Locd
|
12
|
+
module CLI
|
13
|
+
module Command
|
14
|
+
|
15
|
+
|
16
|
+
# Definitions
|
17
|
+
# =======================================================================
|
18
|
+
|
19
|
+
class Agent < Base
|
20
|
+
|
21
|
+
desc "restart",
|
22
|
+
"Restart an agent"
|
23
|
+
|
24
|
+
include_shared t[ groups: t.HasAny( :pattern, :multi, :restart ) ]
|
25
|
+
|
26
|
+
include_shared t[ name: t.or( :enable, :force ), groups: :start ]
|
27
|
+
|
28
|
+
def restart
|
29
|
+
find_multi!( pattern ).
|
30
|
+
each { |agent|
|
31
|
+
agent.restart **option_kwds( groups: [ :restart, :stop, :start ] )
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
# /Namespace
|
39
|
+
# =======================================================================
|
40
|
+
|
41
|
+
end # module Command
|
42
|
+
end # module CLI
|
43
|
+
end # module Locd
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'nrser/refinements/types'
|
5
|
+
using NRSER::Types
|
6
|
+
|
7
|
+
|
8
|
+
# Namespace
|
9
|
+
# =======================================================================
|
10
|
+
|
11
|
+
module Locd
|
12
|
+
module CLI
|
13
|
+
module Command
|
14
|
+
|
15
|
+
|
16
|
+
# Definitions
|
17
|
+
# =======================================================================
|
18
|
+
|
19
|
+
class Agent < Base
|
20
|
+
|
21
|
+
desc "rm PATTERN [OPTIONS]",
|
22
|
+
"Remove (uninstall, delete) a agent"
|
23
|
+
|
24
|
+
map remove: :rm
|
25
|
+
|
26
|
+
include_shared t[ groups: t.has_any( :pattern, :multi ) ]
|
27
|
+
|
28
|
+
option :logs,
|
29
|
+
desc: "Remove logs too",
|
30
|
+
type: :boolean,
|
31
|
+
default: false
|
32
|
+
|
33
|
+
def rm
|
34
|
+
kwds = option_kwds :logs
|
35
|
+
find_multi!( pattern ).each { |agent| agent.remove **kwds }
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
# /Namespace
|
42
|
+
# =======================================================================
|
43
|
+
|
44
|
+
end # module Command
|
45
|
+
end # module CLI
|
46
|
+
end # module Locd
|
@@ -0,0 +1,253 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Requirements
|
4
|
+
# =======================================================================
|
5
|
+
|
6
|
+
# Stdlib
|
7
|
+
# -----------------------------------------------------------------------
|
8
|
+
|
9
|
+
# Deps
|
10
|
+
# -----------------------------------------------------------------------
|
11
|
+
|
12
|
+
# Project / Package
|
13
|
+
# -----------------------------------------------------------------------
|
14
|
+
|
15
|
+
|
16
|
+
# Refinements
|
17
|
+
# =======================================================================
|
18
|
+
|
19
|
+
require 'nrser/refinements/types'
|
20
|
+
using NRSER::Types
|
21
|
+
|
22
|
+
|
23
|
+
# Namespace
|
24
|
+
# =======================================================================
|
25
|
+
|
26
|
+
module Locd
|
27
|
+
module CLI
|
28
|
+
module Command
|
29
|
+
|
30
|
+
|
31
|
+
# Definitions
|
32
|
+
# =======================================================================
|
33
|
+
|
34
|
+
# CLI interface using the `thor` gem.
|
35
|
+
#
|
36
|
+
# @see http://whatisthor.com/
|
37
|
+
#
|
38
|
+
class Agent < Base
|
39
|
+
|
40
|
+
# Shared Options
|
41
|
+
# ============================================================================
|
42
|
+
|
43
|
+
def_shared :option,
|
44
|
+
name: :long,
|
45
|
+
groups: :respond_with_agents,
|
46
|
+
group: "Display",
|
47
|
+
desc: "Display agent details table",
|
48
|
+
aliases: 'l',
|
49
|
+
type: :boolean
|
50
|
+
|
51
|
+
|
52
|
+
# `:pattern` Group
|
53
|
+
# ----------------------------------------------------------------------------
|
54
|
+
#
|
55
|
+
# Options when provided a `PATTERN` argument used to find agents by label.
|
56
|
+
#
|
57
|
+
|
58
|
+
def_shared :argument,
|
59
|
+
name: :pattern,
|
60
|
+
groups: :pattern,
|
61
|
+
desc: "Label or workdir pattern to find agent(s)",
|
62
|
+
type: :string,
|
63
|
+
required: false,
|
64
|
+
complete: ->( klass:, **etc ) { klass.agent_class.labels.to_a }
|
65
|
+
|
66
|
+
def_shared :option,
|
67
|
+
name: :full,
|
68
|
+
groups: :pattern,
|
69
|
+
group: "Pattern",
|
70
|
+
desc: "Require label PATTERN to match entire string",
|
71
|
+
aliases: [ '-u', ],
|
72
|
+
type: :boolean
|
73
|
+
|
74
|
+
def_shared :option,
|
75
|
+
name: :ignore_case,
|
76
|
+
groups: :pattern,
|
77
|
+
group: "Pattern",
|
78
|
+
desc: "Make label PATTERN case-insensitive",
|
79
|
+
aliases: [ 'i' ],
|
80
|
+
type: :boolean
|
81
|
+
|
82
|
+
def_shared :option,
|
83
|
+
name: :recursive,
|
84
|
+
groups: :pattern,
|
85
|
+
group: "Pattern",
|
86
|
+
desc: "Make workdir PATTERN match all subdirs too",
|
87
|
+
aliases: [ 'r' ],
|
88
|
+
type: :boolean
|
89
|
+
|
90
|
+
# NOTE We don't expose the workdir pattern's `:cwd` option...
|
91
|
+
# If you want to match a directory from the CLI, just provide that
|
92
|
+
# directory... no reason to specify the `:cwd` in an option then
|
93
|
+
# provide a relative PATTERN
|
94
|
+
#
|
95
|
+
|
96
|
+
# `:multi` Group
|
97
|
+
# ----------------------------------------------------------------------------
|
98
|
+
#
|
99
|
+
# For commands that can match multiple agents.
|
100
|
+
#
|
101
|
+
|
102
|
+
def_shared :option,
|
103
|
+
name: :all,
|
104
|
+
groups: :multi,
|
105
|
+
group: "Pattern",
|
106
|
+
desc: "Apply to ALL agents that PATTERN matches",
|
107
|
+
aliases: [ 'a' ],
|
108
|
+
type: :boolean
|
109
|
+
|
110
|
+
|
111
|
+
# `:write` Group
|
112
|
+
# ----------------------------------------------------------------------------
|
113
|
+
#
|
114
|
+
# Options when writing an agent `.plist` (`create`, `update`).
|
115
|
+
#
|
116
|
+
|
117
|
+
def_shared :option,
|
118
|
+
name: :label,
|
119
|
+
groups: :write,
|
120
|
+
desc:
|
121
|
+
"Agent label, which is also the domain the proxy will serve it at",
|
122
|
+
aliases: [ '--name', '-n' ],
|
123
|
+
type: :string,
|
124
|
+
required: true
|
125
|
+
|
126
|
+
def_shared :option,
|
127
|
+
name: :workdir,
|
128
|
+
groups: :write,
|
129
|
+
desc: "Working directory for the agent's command",
|
130
|
+
aliases: [ '--dir' ],
|
131
|
+
type: :string
|
132
|
+
|
133
|
+
def_shared :option,
|
134
|
+
name: :log_path,
|
135
|
+
groups: :write,
|
136
|
+
desc: "Path to log agent's STDOUT and STDERR (combined)",
|
137
|
+
aliases: [ '--log' ],
|
138
|
+
type: :string
|
139
|
+
|
140
|
+
def_shared :option,
|
141
|
+
name: :keep_alive,
|
142
|
+
groups: :write,
|
143
|
+
desc: "Try to keep the agent running",
|
144
|
+
type: :boolean,
|
145
|
+
default: false
|
146
|
+
|
147
|
+
def_shared :option,
|
148
|
+
name: :run_at_load,
|
149
|
+
groups: :write,
|
150
|
+
desc: "Start the agent when loading it",
|
151
|
+
type: :boolean,
|
152
|
+
default: false
|
153
|
+
|
154
|
+
|
155
|
+
# `:add` Group
|
156
|
+
# ----------------------------------------------------------------------------
|
157
|
+
|
158
|
+
def_shared :option,
|
159
|
+
name: :force,
|
160
|
+
groups: :add,
|
161
|
+
group: "Add",
|
162
|
+
desc: "Overwrite any existing agent",
|
163
|
+
type: :boolean,
|
164
|
+
default: false
|
165
|
+
|
166
|
+
|
167
|
+
def_shared :option,
|
168
|
+
name: :load,
|
169
|
+
groups: :add,
|
170
|
+
group: "Add",
|
171
|
+
desc: "Load the agent into `launchd`",
|
172
|
+
type: :boolean,
|
173
|
+
default: true
|
174
|
+
|
175
|
+
|
176
|
+
# `:start` Group
|
177
|
+
# --------------------------------------------------------------------------
|
178
|
+
#
|
179
|
+
# Relevant options when starting agents.
|
180
|
+
#
|
181
|
+
|
182
|
+
def_shared :option,
|
183
|
+
name: :load,
|
184
|
+
groups: :start,
|
185
|
+
group: "Start",
|
186
|
+
desc: "Load the agent before starting",
|
187
|
+
type: :boolean,
|
188
|
+
default: true
|
189
|
+
|
190
|
+
def_shared :option,
|
191
|
+
name: :force,
|
192
|
+
groups: :start,
|
193
|
+
group: "Start",
|
194
|
+
desc: "Force loading of agent even if it's disabled",
|
195
|
+
type: :boolean,
|
196
|
+
default: false
|
197
|
+
|
198
|
+
def_shared :option,
|
199
|
+
name: :enable,
|
200
|
+
groups: :start,
|
201
|
+
group: "Start",
|
202
|
+
desc: "Set `launchd` *Disabled* key to `false`",
|
203
|
+
type: :boolean,
|
204
|
+
default: false
|
205
|
+
|
206
|
+
|
207
|
+
# `:stop` Group
|
208
|
+
# --------------------------------------------------------------------------
|
209
|
+
#
|
210
|
+
# Relevant options when stopping agents.
|
211
|
+
#
|
212
|
+
|
213
|
+
def_shared :option,
|
214
|
+
name: :unload,
|
215
|
+
groups: :stop,
|
216
|
+
group: "Stop",
|
217
|
+
desc: "Unload the agent from `launchd` after stopping",
|
218
|
+
type: :boolean,
|
219
|
+
default: true
|
220
|
+
|
221
|
+
def_shared :option,
|
222
|
+
name: :disable,
|
223
|
+
groups: :stop,
|
224
|
+
group: "Stop",
|
225
|
+
desc: "Set `launchd` *Disabled* key to `true`",
|
226
|
+
type: :boolean,
|
227
|
+
default: false
|
228
|
+
|
229
|
+
|
230
|
+
# `:restart` Group
|
231
|
+
# --------------------------------------------------------------------------
|
232
|
+
#
|
233
|
+
# Relevant options when stopping agents.
|
234
|
+
#
|
235
|
+
|
236
|
+
def_shared :option,
|
237
|
+
name: :reload,
|
238
|
+
groups: :restart,
|
239
|
+
group: "Restart",
|
240
|
+
desc: "Unload and reload the agent in `launchd`",
|
241
|
+
type: :boolean,
|
242
|
+
default: true
|
243
|
+
|
244
|
+
|
245
|
+
end # class Locd::CLI::Command::Agent
|
246
|
+
|
247
|
+
|
248
|
+
# /Namespace
|
249
|
+
# =======================================================================
|
250
|
+
|
251
|
+
end # module Command
|
252
|
+
end # module CLI
|
253
|
+
end # module Locd
|