baal 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -18
- data/lib/baal.rb +12 -13
- data/lib/baal/commands.rb +5 -5
- data/lib/baal/matching_options.rb +6 -6
- data/lib/baal/optional_options.rb +19 -19
- data/lib/baal/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19b0dedbcdd4ce8654c0323c2960995a1bd4c752
|
4
|
+
data.tar.gz: c1e69959059f0e8a0dc3ada73118203488019e4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1316659592b8eb859a6149d41912a0d46bd8964b93ba17932bfc5208cfbc25fce73f32855cf123ac34e51d6351368b7b746d2e5504bc667649efd1ae792ad3bb
|
7
|
+
data.tar.gz: 672cf32efaef3619336a2214f39192557f4828482cf6161576f3ff796509b320602eaf2ce3bb9e695f5ec8bfe42bc9d6750d7f0ccca65b7e1170bf0b9c3d1ea3
|
data/README.md
CHANGED
@@ -24,19 +24,20 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
The intention of Baal is to provide an easily-readable, step-by-step process of building start-stop-daemon scripts.
|
26
26
|
|
27
|
-
The wrapper provides all methods you are used to and attempts to alert you (with a nice red error) if it notices
|
27
|
+
The wrapper provides all of the methods you are used to and attempts to alert you (with a nice red error) if it notices
|
28
|
+
a mistake.
|
28
29
|
|
29
30
|
All building is centered around the Daemon object which can be accessed like so:
|
30
31
|
|
31
32
|
```ruby
|
32
|
-
#
|
33
|
+
# Better
|
33
34
|
daemon = Baal.new
|
34
35
|
|
35
|
-
#
|
36
|
+
# Okay
|
36
37
|
daemon = Baal::Daemon.new
|
37
38
|
```
|
38
39
|
|
39
|
-
Once you have your builder object, it is simply a matter of constructing the needed commands and options
|
40
|
+
Once you have your builder object, it is simply a matter of constructing the needed commands and options:
|
40
41
|
|
41
42
|
```ruby
|
42
43
|
# Start a new process in the background
|
@@ -45,19 +46,19 @@ daemon.instance_of_exec('/abs/path/to/executable')
|
|
45
46
|
daemon.with_name('dave')
|
46
47
|
```
|
47
48
|
|
48
|
-
Then execute what you have built
|
49
|
+
Then execute what you have built:
|
49
50
|
|
50
51
|
```ruby
|
51
52
|
daemon.daemonize!
|
52
53
|
```
|
53
54
|
|
54
|
-
You can even check the current status of what you are to execute
|
55
|
+
You can even check the current status of what you are to execute:
|
55
56
|
|
56
57
|
```ruby
|
57
58
|
puts daemon.execution
|
58
59
|
```
|
59
60
|
|
60
|
-
You can also clear the current contents of what you have built up
|
61
|
+
You can also clear the current contents of what you have built up:
|
61
62
|
|
62
63
|
```ruby
|
63
64
|
# Begin with start
|
@@ -69,37 +70,36 @@ daemon.pid_file('/path/to/pid_file')
|
|
69
70
|
daemon.clear_all!
|
70
71
|
```
|
71
72
|
|
72
|
-
|
73
|
-
All of the methods that build up your start-stop-daemon script are chain-able
|
73
|
+
All of the methods that build up your start-stop-daemon script are chain-able:
|
74
74
|
|
75
75
|
```ruby
|
76
76
|
# Check the status of a process
|
77
77
|
daemon.status.with_pid(1234).daemonize!
|
78
78
|
```
|
79
79
|
|
80
|
-
All options with dashes have been converted to underscores
|
80
|
+
All options with dashes have been converted to underscores:
|
81
81
|
|
82
82
|
```ruby
|
83
|
-
#
|
83
|
+
# "Original" (no options for this)
|
84
84
|
daemon.make-pidfile
|
85
85
|
|
86
|
-
#
|
86
|
+
# Baal's
|
87
87
|
daemon.make_pidfile
|
88
88
|
```
|
89
89
|
|
90
|
-
|
91
|
-
command and option names (dashes are not allowed), those are available as well
|
90
|
+
There are many methods that have been written to be more Ruby-like, however, if you still prefer the original
|
91
|
+
command and option names (dashes are not allowed), those are available as well:
|
92
92
|
|
93
93
|
```ruby
|
94
|
-
#
|
94
|
+
# Baal's
|
95
95
|
daemon.start.start_as('/p/a/t/h').pid_file('/p/a/t/h').change_to_user('dave')
|
96
96
|
|
97
|
-
# Original
|
97
|
+
# Original
|
98
98
|
daemon.start.startas('/p/a/t/h').pidfile('/p/a/t/h').chuid('dave')
|
99
99
|
|
100
100
|
# No option for multi-word options with dashes
|
101
|
-
daemon.
|
102
|
-
daemon.
|
101
|
+
daemon.no-close # Error: No method available
|
102
|
+
daemon.no_close # Dashes converted to underscores
|
103
103
|
```
|
104
104
|
|
105
105
|
The documentation in the library should be enough, but if it isn't, or you just don't like my writing style, then there
|
data/lib/baal.rb
CHANGED
@@ -2,6 +2,7 @@ require 'baal/version'
|
|
2
2
|
require 'baal/commands'
|
3
3
|
require 'baal/matching_options'
|
4
4
|
require 'baal/optional_options'
|
5
|
+
require 'open3'
|
5
6
|
|
6
7
|
# The Baal module is the namespace containing all interaction with the Baal gem.
|
7
8
|
# Very little is actually done directly on the Baal module. The primary
|
@@ -34,18 +35,18 @@ module Baal
|
|
34
35
|
|
35
36
|
PROGRAM_NAME = 'start-stop-daemon'.freeze
|
36
37
|
|
38
|
+
attr_reader :stdout, :stderr, :std_status
|
39
|
+
|
37
40
|
def initialize
|
38
|
-
@
|
39
|
-
@testing = false
|
41
|
+
@commands_and_opts = []
|
40
42
|
end
|
41
43
|
|
42
44
|
# TODO: Add method to remove a single command or option
|
43
45
|
|
44
|
-
# Clears @
|
46
|
+
# Clears @commands_and_opts and starts over with only the PROGRAM_NAME
|
45
47
|
#
|
46
48
|
def clear_all!
|
47
|
-
@
|
48
|
-
@execution = [PROGRAM_NAME]
|
49
|
+
@commands_and_opts.clear
|
49
50
|
self
|
50
51
|
end
|
51
52
|
|
@@ -53,23 +54,21 @@ module Baal
|
|
53
54
|
# string to be executed
|
54
55
|
#
|
55
56
|
def execution
|
56
|
-
@
|
57
|
+
([PROGRAM_NAME] + @commands_and_opts).join(' ').strip
|
57
58
|
end
|
58
59
|
|
59
60
|
# Executes the built up start-stop-daemon string and throws an error if
|
60
61
|
# there isn't at least one command and at least one matching option.
|
61
62
|
#
|
62
|
-
# @return [
|
63
|
-
#
|
64
|
-
#
|
65
|
-
# nil: if command execution fails
|
66
|
-
#
|
67
|
-
# TODO: remove usage of system
|
63
|
+
# @return [nil] returns nil to force user to interact with the attr methods
|
64
|
+
# for the system output vs the array that would be returned if nil was
|
65
|
+
# not used
|
68
66
|
#
|
69
67
|
def daemonize!
|
70
68
|
at_least_one_command?
|
71
69
|
at_least_one_matching_option?
|
72
|
-
|
70
|
+
@stdout, @stderr, @std_status = Open3.capture3(PROGRAM_NAME, *@commands_and_opts)
|
71
|
+
nil
|
73
72
|
end
|
74
73
|
end
|
75
74
|
end
|
data/lib/baal/commands.rb
CHANGED
@@ -28,7 +28,7 @@ module Baal
|
|
28
28
|
# II. start_as: a path_name to a process
|
29
29
|
#
|
30
30
|
def start
|
31
|
-
@
|
31
|
+
@commands_and_opts.unshift COMMANDS[:start]
|
32
32
|
include_multiple_commands?
|
33
33
|
self
|
34
34
|
end
|
@@ -52,7 +52,7 @@ module Baal
|
|
52
52
|
# retry: option to check whether or not process(es) finish
|
53
53
|
#
|
54
54
|
def stop
|
55
|
-
@
|
55
|
+
@commands_and_opts.unshift COMMANDS[:stop]
|
56
56
|
include_multiple_commands?
|
57
57
|
self
|
58
58
|
end
|
@@ -62,14 +62,14 @@ module Baal
|
|
62
62
|
# exists. An exit code is returned accord to the LSB Init Script Actions.
|
63
63
|
# TODO: provide better error messages based on LSB.
|
64
64
|
def status
|
65
|
-
@
|
65
|
+
@commands_and_opts.unshift COMMANDS[:status]
|
66
66
|
include_multiple_commands?
|
67
67
|
self
|
68
68
|
end
|
69
69
|
|
70
70
|
# Command that shows cli help information and then exits.
|
71
71
|
def help
|
72
|
-
@
|
72
|
+
@commands_and_opts.unshift COMMANDS[:help]
|
73
73
|
include_multiple_commands?
|
74
74
|
self
|
75
75
|
end
|
@@ -77,7 +77,7 @@ module Baal
|
|
77
77
|
# Command that shows your program version of start-stop-daemon and then
|
78
78
|
# exits.
|
79
79
|
def version
|
80
|
-
@
|
80
|
+
@commands_and_opts.unshift COMMANDS[:version]
|
81
81
|
include_multiple_commands?
|
82
82
|
self
|
83
83
|
end
|
@@ -26,7 +26,7 @@ module Baal
|
|
26
26
|
# TODO: Add error to catch for 0 or less.
|
27
27
|
#
|
28
28
|
def pid(id)
|
29
|
-
@
|
29
|
+
@commands_and_opts.push "#{MATCHING_OPTIONS[:pid]}=#{id}"
|
30
30
|
self
|
31
31
|
end
|
32
32
|
alias with_pid pid
|
@@ -38,7 +38,7 @@ module Baal
|
|
38
38
|
# TODO: Add error to catch for 0 or less.
|
39
39
|
#
|
40
40
|
def ppid(id)
|
41
|
-
@
|
41
|
+
@commands_and_opts.push "#{MATCHING_OPTIONS[:ppid]}=#{id}"
|
42
42
|
self
|
43
43
|
end
|
44
44
|
alias with_ppid ppid
|
@@ -52,7 +52,7 @@ module Baal
|
|
52
52
|
# unintended consequences.
|
53
53
|
#
|
54
54
|
def pid_file(path)
|
55
|
-
@
|
55
|
+
@commands_and_opts.push "#{MATCHING_OPTIONS[:pid_file]}=#{path}"
|
56
56
|
self
|
57
57
|
end
|
58
58
|
alias with_pid_file pid_file
|
@@ -73,7 +73,7 @@ module Baal
|
|
73
73
|
# avoid this.
|
74
74
|
#
|
75
75
|
def exec(abs_path_to_exec)
|
76
|
-
@
|
76
|
+
@commands_and_opts.push "#{MATCHING_OPTIONS[:exec]}=#{abs_path_to_exec}"
|
77
77
|
self
|
78
78
|
end
|
79
79
|
alias instance_of_exec exec
|
@@ -90,7 +90,7 @@ module Baal
|
|
90
90
|
# of the expected process name that is 15 characters long.
|
91
91
|
#
|
92
92
|
def name(process_name)
|
93
|
-
@
|
93
|
+
@commands_and_opts.push "#{MATCHING_OPTIONS[:name]}=#{process_name}"
|
94
94
|
self
|
95
95
|
end
|
96
96
|
alias with_name name
|
@@ -103,7 +103,7 @@ module Baal
|
|
103
103
|
# processes to be acted upon.
|
104
104
|
#
|
105
105
|
def user(username_or_uid)
|
106
|
-
@
|
106
|
+
@commands_and_opts.push "#{MATCHING_OPTIONS[:user]}=#{username_or_uid}"
|
107
107
|
self
|
108
108
|
end
|
109
109
|
alias username user
|
@@ -36,7 +36,7 @@ module Baal
|
|
36
36
|
# id to be changed to
|
37
37
|
#
|
38
38
|
def group(group_name_or_gid)
|
39
|
-
@
|
39
|
+
@commands_and_opts.push "#{OPTIONAL_OPTS[:group]}=#{group_name_or_gid}"
|
40
40
|
self
|
41
41
|
end
|
42
42
|
alias group_name group
|
@@ -51,7 +51,7 @@ module Baal
|
|
51
51
|
# @param signal[String, Symbol] the signal to send
|
52
52
|
#
|
53
53
|
def signal(signal = 'TERM')
|
54
|
-
@
|
54
|
+
@commands_and_opts.push "#{OPTIONAL_OPTS[:signal]}=#{signal}"
|
55
55
|
self
|
56
56
|
end
|
57
57
|
alias with_signal signal
|
@@ -86,7 +86,7 @@ module Baal
|
|
86
86
|
# TODO: Add better arguments for constructing a schedule
|
87
87
|
#
|
88
88
|
def retry(timeout_or_schedule)
|
89
|
-
@
|
89
|
+
@commands_and_opts.push "#{OPTIONAL_OPTS[:retry]}=#{timeout_or_schedule}"
|
90
90
|
self
|
91
91
|
end
|
92
92
|
alias retry_timeout retry
|
@@ -101,7 +101,7 @@ module Baal
|
|
101
101
|
# @param path [String] path to process to attempt to start as
|
102
102
|
#
|
103
103
|
def start_as(path)
|
104
|
-
@
|
104
|
+
@commands_and_opts.push "#{OPTIONAL_OPTS[:start_as]}=#{path}"
|
105
105
|
self
|
106
106
|
end
|
107
107
|
alias startas start_as
|
@@ -110,7 +110,7 @@ module Baal
|
|
110
110
|
# but take no action
|
111
111
|
#
|
112
112
|
def test
|
113
|
-
@
|
113
|
+
@commands_and_opts.push OPTIONAL_OPTS[:test]
|
114
114
|
self
|
115
115
|
end
|
116
116
|
|
@@ -118,14 +118,14 @@ module Baal
|
|
118
118
|
# be, taken
|
119
119
|
#
|
120
120
|
def oknodo
|
121
|
-
@
|
121
|
+
@commands_and_opts.push OPTIONAL_OPTS[:oknodo]
|
122
122
|
self
|
123
123
|
end
|
124
124
|
|
125
125
|
# Do not print informational messages; only display error messages
|
126
126
|
#
|
127
127
|
def quiet
|
128
|
-
@
|
128
|
+
@commands_and_opts.push OPTIONAL_OPTS[:quiet]
|
129
129
|
self
|
130
130
|
end
|
131
131
|
|
@@ -146,7 +146,7 @@ module Baal
|
|
146
146
|
#
|
147
147
|
def chuid(username_or_uid, group_or_gid = nil)
|
148
148
|
group_or_gid = group_or_gid.nil? ? '' : ":#{group_or_gid}"
|
149
|
-
@
|
149
|
+
@commands_and_opts.push "#{OPTIONAL_OPTS[:chuid]}=#{username_or_uid}#{group_or_gid}"
|
150
150
|
self
|
151
151
|
end
|
152
152
|
alias change_to_user chuid
|
@@ -159,7 +159,7 @@ module Baal
|
|
159
159
|
# NOTE: the pid_file is written after the chroot
|
160
160
|
#
|
161
161
|
def chroot(new_root_dir)
|
162
|
-
@
|
162
|
+
@commands_and_opts.push "#{OPTIONAL_OPTS[:chroot]}=#{new_root_dir}"
|
163
163
|
self
|
164
164
|
end
|
165
165
|
|
@@ -170,19 +170,19 @@ module Baal
|
|
170
170
|
# chdir to the root directory before starting the process.
|
171
171
|
#
|
172
172
|
def chdir(path)
|
173
|
-
@
|
173
|
+
@commands_and_opts.push "#{OPTIONAL_OPTS[:chdir]}=#{path}"
|
174
174
|
self
|
175
175
|
end
|
176
176
|
|
177
177
|
def background
|
178
|
-
@
|
178
|
+
@commands_and_opts.push OPTIONAL_OPTS[:background]
|
179
179
|
self
|
180
180
|
end
|
181
181
|
alias in_background background
|
182
182
|
|
183
183
|
# Only relevant when using --background
|
184
184
|
def no_close
|
185
|
-
@
|
185
|
+
@commands_and_opts.push OPTIONAL_OPTS[:no_close]
|
186
186
|
self
|
187
187
|
end
|
188
188
|
|
@@ -192,7 +192,7 @@ module Baal
|
|
192
192
|
# positive or negative
|
193
193
|
#
|
194
194
|
def nice_level(incr)
|
195
|
-
@
|
195
|
+
@commands_and_opts.push "#{OPTIONAL_OPTS[:nice_level]}=#{incr}"
|
196
196
|
self
|
197
197
|
end
|
198
198
|
alias incr_nice_level nice_level
|
@@ -213,7 +213,7 @@ module Baal
|
|
213
213
|
end
|
214
214
|
|
215
215
|
priority = priority.nil? ? ' ' : ":#{priority}"
|
216
|
-
@
|
216
|
+
@commands_and_opts.push "#{OPTIONAL_OPTS[:proc_sched]}=#{policy}#{priority}"
|
217
217
|
self
|
218
218
|
end
|
219
219
|
alias procshed proc_sched
|
@@ -238,7 +238,7 @@ module Baal
|
|
238
238
|
end
|
239
239
|
|
240
240
|
priority = priority.nil? ? ' ' : ":#{priority}"
|
241
|
-
@
|
241
|
+
@commands_and_opts.push "#{OPTIONAL_OPTS[:io_sched]}=#{sched_class}#{priority}"
|
242
242
|
self
|
243
243
|
end
|
244
244
|
alias iosched io_sched
|
@@ -248,7 +248,7 @@ module Baal
|
|
248
248
|
#
|
249
249
|
# @param mask [String, Integer] umask value
|
250
250
|
def umask(mask)
|
251
|
-
@
|
251
|
+
@commands_and_opts.push "#{OPTIONAL_OPTS[:umask]}=#{mask}"
|
252
252
|
self
|
253
253
|
end
|
254
254
|
|
@@ -269,7 +269,7 @@ module Baal
|
|
269
269
|
# OptionalOptions#background option.
|
270
270
|
#
|
271
271
|
def make_pid_file
|
272
|
-
@
|
272
|
+
@commands_and_opts.push OPTIONAL_OPTS[:make_pid_file]
|
273
273
|
self
|
274
274
|
end
|
275
275
|
alias make_pidfile make_pid_file
|
@@ -283,14 +283,14 @@ module Baal
|
|
283
283
|
# option.
|
284
284
|
#
|
285
285
|
def remove_pid_file
|
286
|
-
@
|
286
|
+
@commands_and_opts.push OPTIONAL_OPTS[:remove_pid_file]
|
287
287
|
self
|
288
288
|
end
|
289
289
|
alias remove_pidfile remove_pid_file
|
290
290
|
|
291
291
|
# Print verbose informational messages when executing the script
|
292
292
|
def verbose
|
293
|
-
@
|
293
|
+
@commands_and_opts.push OPTIONAL_OPTS[:verbose]
|
294
294
|
self
|
295
295
|
end
|
296
296
|
end
|
data/lib/baal/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Nimmo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|