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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9fd791002dfcce1998043d8c2933dfe4916f711f
4
- data.tar.gz: 6eb46c2f1680ef7c4134452324139ad4589c4af1
3
+ metadata.gz: 19b0dedbcdd4ce8654c0323c2960995a1bd4c752
4
+ data.tar.gz: c1e69959059f0e8a0dc3ada73118203488019e4e
5
5
  SHA512:
6
- metadata.gz: 9242ed3fc57795d76a102afa72f3cd3eeb2d859461efcdea523109d4e8461ea216baac53137aeea4c57ce0fe5d2878b1075bede930dd77ac7015770bd09586fb
7
- data.tar.gz: e70d24a8b3af1051f6af9cab25058b131969bb6b3d97ed6662f7fc35bcd7b23085e246e779aae1b7fe83bc94e6b4cc0d1536e0c9adbcdbbca9f12a0298c251ca
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 a mistake.
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
- # Preferred
33
+ # Better
33
34
  daemon = Baal.new
34
35
 
35
- # Not preferred
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, ie.
80
+ All options with dashes have been converted to underscores:
81
81
 
82
82
  ```ruby
83
- # From
83
+ # "Original" (no options for this)
84
84
  daemon.make-pidfile
85
85
 
86
- # To
86
+ # Baal's
87
87
  daemon.make_pidfile
88
88
  ```
89
89
 
90
- and 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
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
- # These are just options...
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 language
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.make-pidfile # No method
102
- daemon.make_pidfile # As above
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
@@ -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
- @execution = [PROGRAM_NAME]
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 @execution and starts over with only the PROGRAM_NAME
46
+ # Clears @commands_and_opts and starts over with only the PROGRAM_NAME
45
47
  #
46
48
  def clear_all!
47
- @execution.clear
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
- @execution.join(' ').strip
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 [true, false, nil]
63
- # true: if command was successful (exit status 0)
64
- # false: if command was unsuccessful (exit status non-zero)
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
- system @execution
70
+ @stdout, @stderr, @std_status = Open3.capture3(PROGRAM_NAME, *@commands_and_opts)
71
+ nil
73
72
  end
74
73
  end
75
74
  end
@@ -28,7 +28,7 @@ module Baal
28
28
  # II. start_as: a path_name to a process
29
29
  #
30
30
  def start
31
- @execution.insert 1, COMMANDS[:start]
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
- @execution.insert 1, COMMANDS[:stop]
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
- @execution.insert 1, COMMANDS[:status]
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
- @execution.insert 1, COMMANDS[:help]
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
- @execution.insert 1, COMMANDS[:version]
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
- @execution.push "#{MATCHING_OPTIONS[:pid]}=#{id}"
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
- @execution.push "#{MATCHING_OPTIONS[:ppid]}=#{id}"
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
- @execution.push "#{MATCHING_OPTIONS[:pid_file]}=#{path}"
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
- @execution.push "#{MATCHING_OPTIONS[:exec]}=#{abs_path_to_exec}"
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
- @execution.push "#{MATCHING_OPTIONS[:name]}=#{process_name}"
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
- @execution.push "#{MATCHING_OPTIONS[:user]}=#{username_or_uid}"
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
- @execution.push "#{OPTIONAL_OPTS[:group]}=#{group_name_or_gid}"
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
- @execution.push "#{OPTIONAL_OPTS[:signal]}=#{signal}"
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
- @execution.push "#{OPTIONAL_OPTS[:retry]}=#{timeout_or_schedule}"
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
- @execution.push "#{OPTIONAL_OPTS[:start_as]}=#{path}"
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
- @execution.push OPTIONAL_OPTS[:test]
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
- @execution.push OPTIONAL_OPTS[:oknodo]
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
- @execution.push OPTIONAL_OPTS[:quiet]
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
- @execution.push "#{OPTIONAL_OPTS[:chuid]}=#{username_or_uid}#{group_or_gid}"
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
- @execution.push "#{OPTIONAL_OPTS[:chroot]}=#{new_root_dir}"
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
- @execution.push "#{OPTIONAL_OPTS[:chdir]}=#{path}"
173
+ @commands_and_opts.push "#{OPTIONAL_OPTS[:chdir]}=#{path}"
174
174
  self
175
175
  end
176
176
 
177
177
  def background
178
- @execution.push OPTIONAL_OPTS[:background]
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
- @execution.push OPTIONAL_OPTS[:no_close]
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
- @execution.push "#{OPTIONAL_OPTS[:nice_level]}=#{incr}"
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
- @execution.push "#{OPTIONAL_OPTS[:proc_sched]}=#{policy}#{priority}"
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
- @execution.push "#{OPTIONAL_OPTS[:io_sched]}=#{sched_class}#{priority}"
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
- @execution.push "#{OPTIONAL_OPTS[:umask]}=#{mask}"
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
- @execution.push OPTIONAL_OPTS[:make_pid_file]
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
- @execution.push OPTIONAL_OPTS[:remove_pid_file]
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
- @execution.push OPTIONAL_OPTS[:verbose]
293
+ @commands_and_opts.push OPTIONAL_OPTS[:verbose]
294
294
  self
295
295
  end
296
296
  end
@@ -1,3 +1,3 @@
1
1
  module Baal
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
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.1.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-23 00:00:00.000000000 Z
11
+ date: 2017-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler