pleaserun 0.0.7 → 0.0.8

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: 6db755c281a2e5f041c547f22b425ca854f75d8b
4
- data.tar.gz: 1cdf25e749553dccdc7204c0a68ce167dc56e77e
3
+ metadata.gz: b75cc7758690fb971b56d5165e28d94905aee46e
4
+ data.tar.gz: 09b2a63296a6371d22c6539bbaeeaac92d562a9a
5
5
  SHA512:
6
- metadata.gz: cd618ba975af6c590ce5c934e1480e28f6b11cd86f68d84ebd600b5b483afbd7173780e05de5fa3402ffe95c8edc7414a57e61de973624f5737a96696db49c67
7
- data.tar.gz: 1652915321ccd1c26b07dade2ffb840da8416ab19cf8e6e7f3fc1ad0b49872372038ee8393734c057dfbb9fc242996d97a81a62dc1422189b15c9404a7569a1c
6
+ metadata.gz: df6e5dc9eaa748011b70f43571c935636f88b0c42cbafaca10fb9ba2ef05113c4cffc5cebf567c705b0260f43e7cc178d655f279a41c481a98ba25dfb5bde912
7
+ data.tar.gz: ae58a7cd28f9408737aae00e92ad9e90efb240cb2c79b18009622b44c89298de521ce21ab757ab9fd8cd61840cc973e09c47c017126ead9b7de25f3b950a2f7d
data/.rubocop.yml CHANGED
@@ -47,3 +47,17 @@ RedundantReturn:
47
47
  # enable/disable.
48
48
  CaseIndentation:
49
49
  Enabled: false
50
+
51
+ # module This::Module::Definition is good.
52
+ Style/ClassAndModuleChildren:
53
+ Enabled: true
54
+ EnforcedStyle: compact
55
+
56
+ # "in interpolation #{use.some("double quotes is ok")}"
57
+ Style/StringLiteralsInInterpolation:
58
+ Enabled: true
59
+ EnforcedStyle: double_quotes
60
+
61
+ # Long-block `if !something ... end` are more readable to me than `unless something ... end`
62
+ Style/NegatedIf:
63
+ Enabled: false
data/Guardfile CHANGED
@@ -2,16 +2,15 @@
2
2
  # More info at https://github.com/guard/guard#readme
3
3
 
4
4
  notification :tmux,
5
- display_message: true,
6
- timeout: 5, # in seconds
7
- default_message_format: '%s >> %s',
8
- success: 'green',
9
- default_message_color: 'black',
10
- line_separator: ' > ', # since we are single line we need a separator
11
- color_location: 'status-left-bg' # to customize which tmux element will change color
5
+ :display_message => true,
6
+ :timeout => 5, # in seconds
7
+ :default_message_format => '%s >> %s',
8
+ :success => 'green',
9
+ :default_message_color => 'black',
10
+ :line_separator => ' > ', # since we are single line we need a separator
11
+ :color_location => 'status-left-bg' # to customize which tmux element will change color
12
12
 
13
- guard :rspec, cmd: 'rspec --color --order rand:$RANDOM' do
14
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
15
- watch(%r{^spec/.*\.rb$}) { |m| m[0] }
13
+ guard :rspec, :cmd => 'rspec --color --order rand:$RANDOM' do
14
+ watch(/^lib\/(.+)\.rb$/) { |m| "spec/#{m[1]}_spec.rb" }
15
+ watch(/^spec\/.*\.rb$/) { |m| m[0] }
16
16
  end
17
-
data/README.md CHANGED
@@ -17,7 +17,7 @@ With pleaserun, you can generate the following launchers/scripts/whatever:
17
17
  * runit
18
18
  * sysv init
19
19
 
20
- Want more? It's easy to add things. [File an issue](issues/) and ask away!
20
+ Want more? It's easy to add things. [File an issue](../../issues/) and ask away!
21
21
 
22
22
  ## Installation
23
23
 
@@ -42,8 +42,8 @@ first let's get redis and build it.
42
42
 
43
43
  Assuming the above succeeds (it did for me!), we now have redis installed to `/tmp/redis`:
44
44
 
45
- % ls /tmp/redis/bin
46
- redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server
45
+ % ls /tmp/redis/bin
46
+ redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server
47
47
 
48
48
  You might be thinking - why /tmp? This is just a demo! That's why! :)
49
49
 
data/bin/pleaserun CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  libdir = File.expand_path("../lib", File.dirname(__FILE__))
4
- $: << libdir if File.exists?(File.join(libdir, "pleaserun", "cli.rb"))
4
+ $LOAD_PATH << libdir if File.exist?(File.join(libdir, "pleaserun", "cli.rb"))
5
5
  require "pleaserun/cli"
6
-
7
6
  exit(PleaseRun::CLI.run || 0)
data/lib/pleaserun/cli.rb CHANGED
@@ -12,7 +12,6 @@ require "pleaserun/errors"
12
12
  #
13
13
  # This is invoked by `bin/pleaserun`.
14
14
  class PleaseRun::CLI < Clamp::Command # rubocop:disable ClassLength
15
-
16
15
  option ["-p", "--platform"], "PLATFORM", "The name of the platform to target, such as sysv, upstart, etc"
17
16
  option ["-v", "--version"], "VERSION", "The version of the platform to target, such as 'lsb-3.1' for sysv or '1.5' for upstart",
18
17
  :default => "default", :attribute_name => :target_version
@@ -42,7 +41,7 @@ class PleaseRun::CLI < Clamp::Command # rubocop:disable ClassLength
42
41
  next if [:program, :args, :target_version].include?(facet.name)
43
42
 
44
43
  # Turn the attribute name into a flag.
45
- option "--#{facet.name}", facet.name.to_s.upcase, facet.description,
44
+ option "--#{facet.name.to_s.gsub("_", "-")}", facet.name.to_s.upcase, facet.description,
46
45
  :attribute_name => facet.name
47
46
  end
48
47
 
@@ -144,6 +143,8 @@ are made. If it fails, nagios will not start. Yay!
144
143
  self.name = File.basename(program)
145
144
  @logger.warn("No name given, setting reasonable default based on the executable", :name => name)
146
145
  end
146
+
147
+ nil
147
148
  end # def setup_defaults
148
149
 
149
150
  def run_json(runner)
@@ -162,7 +163,6 @@ are made. If it fails, nagios will not start. Yay!
162
163
  result["install_actions"] = runner.install_actions
163
164
 
164
165
  puts JSON.dump(result)
165
- return 0
166
166
  end # def run_json
167
167
 
168
168
  def run_human(runner)
@@ -59,17 +59,19 @@ module PleaseRun::Configurable
59
59
  facet = Facet.new(name, description, options, &validator)
60
60
  attributes << facet
61
61
 
62
- # define '<name>' and '<name>=' methods
62
+ # define accessor method
63
63
  define_method(name.to_sym) do
64
64
  # object instance, not class ivar
65
65
  @attributes[name.to_sym].value
66
66
  end
67
67
 
68
+ # define mutator
68
69
  define_method("#{name}=".to_sym) do |value|
69
70
  # object instance, not class ivar
70
71
  @attributes[name.to_sym].value = value
71
72
  end
72
73
 
74
+ # define presence check method
73
75
  define_method("#{name}?".to_sym) do
74
76
  return @attributes[name.to_sym].set?
75
77
  end
@@ -80,7 +82,7 @@ module PleaseRun::Configurable
80
82
  end
81
83
 
82
84
  def all_attributes
83
- return ancestors.select { |a| a.respond_to?(:attributes) }.collect { |a| a.attributes }.flatten
85
+ return ancestors.select { |a| a.respond_to?(:attributes) }.collect(&:attributes).flatten
84
86
  end # def attributes
85
87
  end # def ClassMixin
86
88
 
@@ -17,12 +17,14 @@ class PleaseRun::Detector
17
17
  ["fedora", "18"] => ["systemd", "default"],
18
18
  ["fedora", "19"] => ["systemd", "default"],
19
19
  ["fedora", "20"] => ["systemd", "default"],
20
+ ["mac_os_x", "10.8"] => ["launchd", "10.9"],
20
21
  ["mac_os_x", "10.9"] => ["launchd", "10.9"],
21
- ["mac_os_x", "10.9"] => ["launchd", "10.9"],
22
+ ["mac_os_x", "10.10"] => ["launchd", "10.9"],
22
23
  ["ubuntu", "12.04"] => ["upstart", "1.5"],
23
24
  ["ubuntu", "12.10"] => ["upstart", "1.5"],
24
25
  ["ubuntu", "13.04"] => ["upstart", "1.5"],
25
- ["ubuntu", "13.10"] => ["upstart", "1.5"]
26
+ ["ubuntu", "13.10"] => ["upstart", "1.5"],
27
+ ["ubuntu", "14.04"] => ["upstart", "1.5"]
26
28
  }
27
29
 
28
30
  def self.detect
@@ -41,7 +43,7 @@ class PleaseRun::Detector
41
43
  end
42
44
 
43
45
  @system = lookup([platform, version])
44
- raise UnknownSystem if @system.nil?
46
+ raise UnknownSystem, "#{platform} #{version}" if @system.nil?
45
47
  return @system
46
48
  end # def self.detect
47
49
 
@@ -1,5 +1,2 @@
1
- # :nodoc:
2
- module PleaseRun
3
- # :nodoc:
4
- module Platform; end
5
- end
1
+ PleaseRun = Module.new
2
+ PleaseRun::Platform = Module.new
@@ -94,6 +94,43 @@ class PleaseRun::Platform::Base
94
94
  end
95
95
  end
96
96
 
97
+ attribute :limit_coredump, "Largest size (in blocks) of a core file that can be created. (setrlimit RLIMIT_CORE)" do
98
+ validate { |v| v == "ulimited" || v.to_i > 0 }
99
+ end
100
+
101
+ attribute :limit_cputime, "Maximum amount of cpu time (in seconds) a program may use. (setrlimit RLIMIT_CPU)" do
102
+ validate { |v| v == "ulimited" || v.to_i > 0 }
103
+ end
104
+
105
+ attribute :limit_data, "Maximum data segment size (setrlimit RLIMIT_DATA)" do
106
+ validate { |v| v == "ulimited" || v.to_i > 0 }
107
+ end
108
+
109
+ attribute :limit_file_size, "Maximum size (in blocks) of a file receiving writes (setrlimit RLIMIT_FSIZE)" do
110
+ validate { |v| v == "ulimited" || v.to_i > 0 }
111
+ end
112
+
113
+ attribute :limit_locked_memory, "Maximum amount of memory (in bytes) lockable with mlock(2) (setrlimit RLIMIT_MEMLOCK)" do
114
+ validate { |v| v == "ulimited" || v.to_i > 0 }
115
+ end
116
+
117
+ attribute :limit_open_files, "Maximum number of open files, sockets, etc. (setrlimit RLIMIT_NOFILE)" do
118
+ validate { |v| v == "ulimited" || v.to_i > 0 }
119
+ end
120
+
121
+ attribute :limit_user_processes, "Maximum number of running processes (or threads!) for this user id. Not recommended because this setting applies to the user, not the process group. (setrlimit RLIMIT_NPROC)" do
122
+ validate { |v| v == "ulimited" || v.to_i > 0 }
123
+ end
124
+
125
+ attribute :limit_physical_memory, "Maximum resident set size (in bytes); the amount of physical memory used by a process. (setrlimit RLIMIT_RSS)" do
126
+ validate { |v| v == "ulimited" || v.to_i > 0 }
127
+ end
128
+
129
+ attribute :limit_stack_size, "Maximum size (in bytes) of a stack segment (setrlimit RLIMIT_STACK)" do
130
+ validate { |v| v == "ulimited" || v.to_i > 0 }
131
+ end
132
+
133
+
97
134
  attribute :prestart, "A command to execute before starting and restarting. A failure of this command will cause the start/restart to abort. This is useful for health checks, config tests, or similar operations."
98
135
 
99
136
  def initialize(target_version)
@@ -6,9 +6,27 @@ require "pleaserun/namespace"
6
6
  # This will generate the familiar /etc/init.d/ scripts.
7
7
  class PleaseRun::Platform::SYSV < PleaseRun::Platform::Base
8
8
  def files
9
- return Enumerator::Generator.new do |out|
9
+ Enumerator::Generator.new do |out|
10
10
  out.yield(safe_filename("/etc/init.d/{{ name }}"), render_template("init.sh"), 0755)
11
11
  out.yield(safe_filename("/etc/default/{{ name }}"), render_template("default"))
12
12
  end
13
13
  end
14
+
15
+ def ulimit_setup
16
+ ulimits = []
17
+ ulimits << "-c ${limit_coredump}" if limit_coredump
18
+ ulimits << "-t ${limit_cputime}" if limit_cputime
19
+ ulimits << "-d ${limit_data}" if limit_data
20
+ ulimits << "-f ${limit_file_size}" if limit_file_size
21
+ ulimits << "-l ${limit_locked_memory}" if limit_locked_memory
22
+ ulimits << "-n ${limit_open_files}" if limit_open_files
23
+ ulimits << "-u ${limit_user_processes}" if limit_user_processes
24
+ ulimits << "-m ${limit_physical_memory}" if limit_physical_memory
25
+ ulimits << "-s ${limit_stack_size}" if limit_stack_size
26
+ ulimits
27
+ end
28
+
29
+ def ulimit_shell
30
+ ulimit_setup.collect { |args| "ulimit #{args}" }.join("\n")
31
+ end
14
32
  end
@@ -7,10 +7,6 @@ class PleaseRun::Platform::Upstart < PleaseRun::Platform::Base
7
7
  def files
8
8
  return Enumerator::Generator.new do |out|
9
9
  out.yield(safe_filename("/etc/init/{{ name }}.conf"), render_template("init.conf"))
10
- # Don't bother putting /etc/init.d/ shims anymore.
11
- # The best way to interact with upstart is through initctl, start, stop,
12
- # and restart commands
13
- #out.yield(safe_filename("/etc/init.d/{{ name }}"), render_template("init.d.sh"), 0755)
14
10
  end
15
11
  end
16
12
  end
data/pleaserun.gemspec CHANGED
@@ -1,18 +1,16 @@
1
1
  Gem::Specification.new do |spec|
2
- files = %x{git ls-files}.split("\n")
2
+ files = `git ls-files`.split("\n")
3
3
 
4
4
  spec.name = "pleaserun"
5
- spec.version = "0.0.7"
5
+ spec.version = "0.0.8"
6
6
  spec.summary = "pleaserun"
7
7
  spec.description = "pleaserun"
8
8
  spec.license = "Apache 2.0"
9
9
 
10
- # Note: You should set the version explicitly.
11
10
  spec.add_dependency "cabin", ">0" # for logging. apache 2 license
12
11
  spec.add_dependency "clamp"
13
- spec.add_dependency "cabin"
14
12
  spec.add_dependency "stud"
15
- spec.add_dependency "mustache"
13
+ spec.add_dependency "mustache", ">= 0.99.8"
16
14
  spec.add_dependency "insist"
17
15
  spec.add_dependency "ohai", "~> 6.20" # used for host detection
18
16
 
@@ -23,6 +21,5 @@ Gem::Specification.new do |spec|
23
21
 
24
22
  spec.authors = ["Jordan Sissel"]
25
23
  spec.email = ["jls@semicomplete.com"]
26
- #spec.homepage = "..."
24
+ spec.homepage = "https://github.com/jordansissel/pleaserun"
27
25
  end
28
-
@@ -26,4 +26,3 @@ describe PleaseRun::Platform::Base do
26
26
  end
27
27
  end
28
28
  end
29
-
@@ -24,7 +24,7 @@ describe PleaseRun::Platform::Launchd do
24
24
  next runner
25
25
  end
26
26
 
27
- let(:files) { subject.files.collect { |path, content| path } }
27
+ let(:files) { subject.files.collect { |path, _| path } }
28
28
 
29
29
  it "emits a file in /Library/LaunchDaemons" do
30
30
  insist { files }.include?("/Library/LaunchDaemons/fancypants.plist")
@@ -22,7 +22,7 @@ describe PleaseRun::Platform::Systemd do
22
22
  next runner
23
23
  end
24
24
 
25
- let(:files) { subject.files.collect { |path, content| path } }
25
+ let(:files) { subject.files.collect { |path, _| path } }
26
26
 
27
27
  it "emits a file in /lib/systemd/system" do
28
28
  insist { files }.include?("/lib/systemd/system/fancypants.service")
@@ -7,11 +7,17 @@ describe PleaseRun::Platform::SYSV do
7
7
  let(:version) { PleaseRun::Detector.detect[1] }
8
8
 
9
9
  context "deployment", :sysv => true do
10
- it_behaves_like PleaseRun::Platform do
11
- let(:start) { "/etc/init.d/#{subject.name} start" }
12
- let(:stop) { "/etc/init.d/#{subject.name} stop" }
13
- let(:status) { "/etc/init.d/#{subject.name} status" }
14
- let(:restart) { "/etc/init.d/#{subject.name} restart" }
10
+ etc_initd_writable = File.lstat("/etc/init.d").writable? rescue false
11
+ if !etc_initd_writable
12
+ it "cannot write to /etc/init.d, so there's no deployment test to do. You'll need to run this as root, probably. Be careful, if you do run this as root."
13
+ else
14
+ it_behaves_like PleaseRun::Platform do
15
+ let(:skip) { "Cannot write to /etc/init.d" } unless etc_initd_writable
16
+ let(:start) { "/etc/init.d/#{subject.name} start" }
17
+ let(:stop) { "/etc/init.d/#{subject.name} stop" }
18
+ let(:status) { "/etc/init.d/#{subject.name} status" }
19
+ let(:restart) { "/etc/init.d/#{subject.name} restart" }
20
+ end
15
21
  end
16
22
  end
17
23
 
@@ -22,7 +28,7 @@ describe PleaseRun::Platform::SYSV do
22
28
  next runner
23
29
  end
24
30
 
25
- let(:files) { subject.files.collect { |path, content| path } }
31
+ let(:files) { subject.files.collect { |path, _| path } }
26
32
 
27
33
  it "emits a file in /etc/init.d/" do
28
34
  insist { files }.include?("/etc/init.d/fancypants")
@@ -6,7 +6,7 @@ describe PleaseRun::Platform::Upstart do
6
6
  let(:platform) { PleaseRun::Detector.detect[0] }
7
7
  let(:version) { PleaseRun::Detector.detect[1] }
8
8
 
9
- context "deployment", :upstart=> true do
9
+ context "deployment", :upstart => true do
10
10
  it_behaves_like PleaseRun::Platform do
11
11
  let(:start) { "initctl start #{subject.name}" }
12
12
  let(:stop) { "initctl stop #{subject.name}" }
@@ -22,15 +22,11 @@ describe PleaseRun::Platform::Upstart do
22
22
  next runner
23
23
  end
24
24
 
25
- let(:files) { subject.files.collect { |path, content| path } }
25
+ let(:files) { subject.files.collect { |path, _| path } }
26
26
 
27
27
  it "emits a file in /etc/init/" do
28
28
  insist { files }.include?("/etc/init/fancypants.conf")
29
29
  end
30
-
31
- it "emits a file in /etc/init.d/" do
32
- insist { files }.include?("/etc/init.d/fancypants")
33
- end
34
30
  end
35
31
 
36
32
  context "#install_actions" do
@@ -38,7 +38,7 @@ shared_examples_for PleaseRun::Platform do
38
38
  system_quiet("launchctl unload #{subject.daemons_path}")
39
39
  system_quiet("launchctl remove #{subject.name}")
40
40
  end
41
- subject.files.each do |path, content|
41
+ subject.files.each do |path, _|
42
42
  File.unlink(path) if File.exist?(path)
43
43
  end
44
44
  end
@@ -0,0 +1,14 @@
1
+ user="{{{user}}}"
2
+ group="{{{group}}}"
3
+ chroot="{{{chroot}}}"
4
+ chdir="{{{chdir}}}"
5
+ nice="{{{nice}}}"
6
+ {{#limit_coredump}}limit_coredump="{{{limit_coredump}}}"
7
+ {{/limit_coredump}}{{#limit_cputime}}limit_cputime="{{{limit_cputime}}}"
8
+ {{/limit_cputime}}{{#limit_data}}limit_data="{{{limit_data}}}"
9
+ {{/limit_data}}{{#limit_file_size}}limit_file_size="{{{limit_file_size}}}"
10
+ {{/limit_file_size}}{{#limit_locked_memory}}limit_locked_memory="{{{limit_locked_memory}}}"
11
+ {{/limit_locked_memory}}{{#limit_open_files}}limit_open_files="{{{limit_open_files}}}"
12
+ {{/limit_open_files}}{{#limit_user_processes}}limit_user_processes="{{{limit_user_processes}}}"
13
+ {{/limit_user_processes}}{{#limit_physical_memory}}limit_physical_memory="{{{limit_physical_memory}}}"
14
+ {{/limit_physical_memory}}{{#limit_stack_size}}limit_stack_size="{{{limit_stack_size}}}"{{/limit_stack_size}}
@@ -26,12 +26,20 @@ pidfile="/var/run/$name.pid"
26
26
  [ -r /etc/default/$name ] && . /etc/default/$name
27
27
  [ -r /etc/sysconfig/$name ] && . /etc/sysconfig/$name
28
28
 
29
+ trace() {
30
+ logger -t "/etc/init.d/{{{name}}}" "$@"
31
+ }
32
+
33
+ emit() {
34
+ trace "$@"
35
+ echo "$@"
36
+ }
37
+
29
38
  start() {
30
39
  {{! I don't use 'su' here to run as a different user because the process 'su'
31
40
  stays as the parent, causing our pidfile to contain the pid of 'su' not the
32
41
  program we intended to run. Luckily, the 'chroot' program on OSX, FreeBSD, and Linux
33
- all support switching users and it invokes execve immediately after chrooting.
34
- }}
42
+ all support switching users and it invokes execve immediately after chrooting. }}
35
43
 
36
44
  {{#prestart}}
37
45
  if [ "$PRESTART" != "no" ] ; then
@@ -40,10 +48,14 @@ start() {
40
48
  fi
41
49
  {{/prestart}}
42
50
 
51
+ # Setup any environmental stuff beforehand
52
+ {{{ulimit_shell}}}
53
+
43
54
  # Run the program!
44
- chroot --userspec {{{user}}}:{{{group}}} {{{chroot}}} sh -c "
45
- {{#chdir}}cd {{{chdir}}}{{/chdir}}
46
- {{#nice}}nice {{{nice}}}{{/nice}}
55
+ {{#nice}}nice -n "$nice" \{{/nice}}
56
+ chroot --userspec "$user":"$group" "$chroot" sh -c "
57
+ {{{ulimit_shell}}}
58
+ cd \"$chdir\"
47
59
  exec \"$program\" $args
48
60
  " > /var/log/$name.log 2> /var/log/$name.err &
49
61
 
@@ -52,34 +64,34 @@ start() {
52
64
  # and a process possibly asking for status.
53
65
  echo $! > $pidfile
54
66
 
55
- echo "$name started."
67
+ emit "$name started"
56
68
  return 0
57
69
  }
58
70
 
59
71
  stop() {
60
72
  # Try a few times to kill TERM the program
61
73
  if status ; then
62
- pid=`cat "$pidfile"`
63
- echo "Killing $name (pid $pid) with SIGTERM"
74
+ pid=$(cat "$pidfile")
75
+ trace "Killing $name (pid $pid) with SIGTERM"
64
76
  kill -TERM $pid
65
77
  # Wait for it to exit.
66
78
  for i in 1 2 3 4 5 ; do
67
- echo "Waiting $name (pid $pid) to die..."
79
+ trace "Waiting $name (pid $pid) to die..."
68
80
  status || break
69
81
  sleep 1
70
82
  done
71
83
  if status ; then
72
- echo "$name stop failed; still running."
84
+ emit "$name stop failed; still running."
73
85
  else
74
- echo "$name stopped."
86
+ emit "$name stopped."
75
87
  fi
76
88
  fi
77
89
  }
78
90
 
79
91
  status() {
80
92
  if [ -f "$pidfile" ] ; then
81
- pid=`cat "$pidfile"`
82
- if kill -0 $pid > /dev/null 2> /dev/null ; then
93
+ pid=$(cat "$pidfile")
94
+ if ps -p $pid > /dev/null 2> /dev/null ; then
83
95
  # process by this pid is running.
84
96
  # It may not be our pid, but that's what you get with just pidfiles.
85
97
  # TODO(sissel): Check if this process seems to be the same as the one we
@@ -97,7 +109,7 @@ status() {
97
109
  force_stop() {
98
110
  if status ; then
99
111
  stop
100
- status && kill -KILL `cat "$pidfile"`
112
+ status && kill -KILL $(cat "$pidfile")
101
113
  fi
102
114
  }
103
115
 
@@ -108,22 +120,33 @@ prestart() {
108
120
  status=$?
109
121
 
110
122
  if [ $status -gt 0 ] ; then
111
- echo "Prestart command failed with code $status. If you wish to skip the prestart command, set PRESTART=no in your environment."
123
+ emit "Prestart command failed with code $status. If you wish to skip the prestart command, set PRESTART=no in your environment."
112
124
  fi
113
125
  return $status
114
126
  }
115
127
  {{/prestart}}
116
128
 
117
129
  case "$1" in
130
+ force-start|start|stop|force-stop|restart)
131
+ trace "Attempting '$1' on {{{name}}}"
132
+ ;;
133
+ esac
134
+
135
+ case "$1" in
136
+ force-start)
137
+ PRESTART=no
138
+ exec "$0" start
139
+ ;;
118
140
  start)
119
141
  status
120
142
  code=$?
121
143
  if [ $code -eq 0 ]; then
122
- echo "$name is already running"
144
+ emit "$name is already running"
145
+ exit $code
123
146
  else
124
147
  start
148
+ exit $?
125
149
  fi
126
- exit $code
127
150
  ;;
128
151
  stop) stop ;;
129
152
  force-stop) force_stop ;;
@@ -131,18 +154,20 @@ case "$1" in
131
154
  status
132
155
  code=$?
133
156
  if [ $code -eq 0 ] ; then
134
- echo "$name is running"
157
+ emit "$name is running"
135
158
  else
136
- echo "$name is not running"
159
+ emit "$name is not running"
137
160
  fi
138
161
  exit $code
139
162
  ;;
140
163
  restart)
141
- {{#prestart}}prestart || exit $?{{/prestart}}
164
+ {{#prestart}}if [ "$PRESTART" != "no" ] ; then
165
+ prestart || exit $?
166
+ fi{{/prestart}}
142
167
  stop && start
143
168
  ;;
144
169
  *)
145
- echo "Usage: $SCRIPTNAME {start|stop|force-stop|status|restart}" >&2
170
+ echo "Usage: $SCRIPTNAME {start|force-start|stop|force-start|force-stop|status|restart}" >&2
146
171
  exit 3
147
172
  ;;
148
173
  esac
metadata CHANGED
@@ -1,111 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pleaserun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Sissel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-24 00:00:00.000000000 Z
11
+ date: 2015-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cabin
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>'
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>'
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: clamp
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: cabin
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
38
+ - - ">="
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: stud
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - '>='
45
+ - - ">="
60
46
  - !ruby/object:Gem::Version
61
47
  version: '0'
62
48
  type: :runtime
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - '>='
52
+ - - ">="
67
53
  - !ruby/object:Gem::Version
68
54
  version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: mustache
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - '>='
59
+ - - ">="
74
60
  - !ruby/object:Gem::Version
75
- version: '0'
61
+ version: 0.99.8
76
62
  type: :runtime
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - '>='
66
+ - - ">="
81
67
  - !ruby/object:Gem::Version
82
- version: '0'
68
+ version: 0.99.8
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: insist
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
- - - '>='
73
+ - - ">="
88
74
  - !ruby/object:Gem::Version
89
75
  version: '0'
90
76
  type: :runtime
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - '>='
80
+ - - ">="
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: ohai
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
- - - ~>
87
+ - - "~>"
102
88
  - !ruby/object:Gem::Version
103
89
  version: '6.20'
104
90
  type: :runtime
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
- - - ~>
94
+ - - "~>"
109
95
  - !ruby/object:Gem::Version
110
96
  version: '6.20'
111
97
  description: pleaserun
@@ -116,8 +102,8 @@ executables:
116
102
  extensions: []
117
103
  extra_rdoc_files: []
118
104
  files:
119
- - .gitignore
120
- - .rubocop.yml
105
+ - ".gitignore"
106
+ - ".rubocop.yml"
121
107
  - CHANGELOG.asciidoc
122
108
  - Gemfile
123
109
  - Gemfile.lock
@@ -161,13 +147,7 @@ files:
161
147
  - templates/upstart/0.6.5/init.d.sh
162
148
  - templates/upstart/1.5/init.conf
163
149
  - templates/upstart/1.5/init.d.sh
164
- - test.rb
165
- - test/helpers.rb
166
- - test/test.rb
167
- - test/vagrant/Vagrantfile
168
- - test/vagrant/fedora-18/Vagrantfile
169
- - test/vagrant/fedora-18/provision.sh
170
- homepage:
150
+ homepage: https://github.com/jordansissel/pleaserun
171
151
  licenses:
172
152
  - Apache 2.0
173
153
  metadata: {}
@@ -178,17 +158,17 @@ require_paths:
178
158
  - lib
179
159
  required_ruby_version: !ruby/object:Gem::Requirement
180
160
  requirements:
181
- - - '>='
161
+ - - ">="
182
162
  - !ruby/object:Gem::Version
183
163
  version: '0'
184
164
  required_rubygems_version: !ruby/object:Gem::Requirement
185
165
  requirements:
186
- - - '>='
166
+ - - ">="
187
167
  - !ruby/object:Gem::Version
188
168
  version: '0'
189
169
  requirements: []
190
170
  rubyforge_project:
191
- rubygems_version: 2.1.11
171
+ rubygems_version: 2.4.3
192
172
  signing_key:
193
173
  specification_version: 4
194
174
  summary: pleaserun
data/test/helpers.rb DELETED
@@ -1,33 +0,0 @@
1
- class Stud::Try
2
- # Make Stud::Try quiet.
3
- def log_failure(*args); end
4
- end
5
-
6
- def test_in_container(tag, commands, outfile, errfile)
7
- chdir = File.join(File.dirname(__FILE__), "vagrant")
8
-
9
- # hacks for now because I don't know how to make vagrant smartly
10
- # choose the right provider.
11
- provider = case tag
12
- when /^fedora-/, /^centos-/
13
- "virtualbox"
14
- else
15
- "docker"
16
- end
17
- system("cd #{chdir}; vagrant up --provider=#{provider} #{tag} > #{outfile} 2> #{errfile}")
18
- insist { $? }.success?
19
-
20
- commands.each do |command|
21
- cmd = "cd #{chdir}; vagrant ssh #{tag} -- bash -l >> #{outfile} 2>> #{errfile}"
22
- IO.popen(cmd, "w") do |io|
23
- io.puts(". /etc/profile")
24
- io.puts(". ./.bashrc")
25
- io.puts(". ./.bash_profile")
26
- io.puts(command)
27
- io.puts("exit $?")
28
- io.close_write
29
- end
30
- insist { $? } == 0
31
- end
32
- return $?.success?
33
- end
data/test/test.rb DELETED
@@ -1,81 +0,0 @@
1
- require "insist"
2
- require "net/ssh"
3
- require "json"
4
- require "stud/try"
5
- require "stud/temporary"
6
- require "peach"
7
-
8
- require_relative "helpers"
9
- Thread.abort_on_exception = true
10
-
11
- raise "What tags to run?" if ARGV.empty?
12
-
13
- start = Time.now
14
- queue = Queue.new
15
-
16
- puts "Testing on #{ARGV.size} platforms:"
17
- puts ARGV.join(", ")
18
- puts
19
- ARGV.each do |tag|
20
- Thread.new do
21
- out = Stud::Temporary.pathname
22
- err = Stud::Temporary.pathname
23
- begin
24
- status = test_in_container(tag, [
25
- # TODO(sissel): Test other ruby versions
26
- "cd /pleaserun; rvm use 1.9.3; bundle install",
27
-
28
- # Run rspec as root to make pleaserun's real deployment tests run.
29
- "cd /pleaserun; rvm use 1.9.3; sudo -E `which ruby` `which rspec` --format json",
30
- #"cd /pleaserun; rvm use 1.9.3; rspec --format json",
31
- ], out, err)
32
- rescue Insist::Failure
33
- status = false
34
- end
35
- queue << [tag, status, out, err]
36
- end
37
- end
38
-
39
- results = ARGV.collect { tag, success, out, err = queue.pop }
40
- successes = results.count { |tag, success, out, err| success }
41
- failures = results.count { |tag, success, out, err| !success }
42
- tests = results.collect { |tag, success, out, err|
43
- begin
44
- JSON.parse(File.read(out).split("\n").last[/{.*$/])["examples"].each { |r| r["tag"] = tag }
45
- rescue TypeError, NoMethodError
46
- puts "Failed to parse json"
47
- puts :out => File.read(out)
48
- puts :err => File.read(err)
49
- raise
50
- end
51
- }.flatten
52
-
53
- duration = Time.now - start
54
-
55
- test_successes = tests.count { |t| t["status"] == "passed" }
56
- test_failures = tests.count { |t| t["status"] == "failed" }
57
-
58
- #require "pry"
59
- #tests.pry
60
- tests.each do |result|
61
- next if result["status"] == "passed"
62
-
63
- case result["status"]
64
- when "failed"
65
- puts "#{result["tag"]}: #{result["full_description"]}"
66
- exception = result["exception"]
67
- puts " #{exception["class"]}: #{exception["message"]}"
68
- when "pending"
69
- puts "#{result["tag"]}: PENDING: #{result["full_description"]}"
70
- end
71
- puts " #{result["file_path"]}:#{result["line_number"]}"
72
- end
73
-
74
- puts "Tests: #{test_successes} ok, #{test_failures} failures; Platforms: #{successes} ok, #{failures} failures;, Duration: #{sprintf("%0.3f", duration)} seconds"
75
-
76
- results.each do |tag, success, out, err|
77
- File.delete(err)
78
- File.delete(out)
79
- end
80
-
81
- exit(results.any? { |t,s,*args| !s } ? 1 : 0)
@@ -1,57 +0,0 @@
1
- # -*- mode: ruby -*-
2
- # vi: set ft=ruby :
3
-
4
- # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
- VAGRANTFILE_API_VERSION = "2"
6
-
7
- Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8
- root = File.expand_path("../../", File.dirname(__FILE__))
9
- config.vm.synced_folder root, "/pleaserun"
10
-
11
- # Ubuntu
12
- %w(12.04 12.10 13.04 13.10).each do |version|
13
- config.vm.define "ubuntu-#{version}" do |c|
14
- c.vm.box = "dummy"
15
- c.vm.box_url = "http://bit.ly/vagrant-docker-dummy"
16
- c.vm.provider :docker do |docker|
17
- docker.image = "jordansissel/system:ubuntu-#{version}"
18
- end
19
- end
20
- end
21
-
22
- # Debian
23
- %w(7.3 6.0.8).each do |version|
24
- config.vm.define "debian-#{version}" do |c|
25
- c.vm.box = "dummy"
26
- c.vm.box_url = "http://bit.ly/vagrant-docker-dummy"
27
- c.vm.provider :docker do |docker|
28
- docker.image = "jordansissel/system:debian-#{version}"
29
- end
30
- end
31
- end
32
-
33
- # Fedora
34
- config.vm.define "fedora-18" do |c|
35
- c.vm.box = "fedora-18"
36
- c.vm.box_url = "http://puppet-vagrant-boxes.puppetlabs.com/fedora-18-x64-vbox4210-nocm.box"
37
- c.vm.provider "virtualbox"
38
- c.vm.provision "shell", :path => "fedora-18/provision.sh"
39
- end
40
-
41
- # Centos
42
- # I would use docker, but I can't figure out how to get centos 6 w/ upstart working and there
43
- # are plenty of quality CentOS vagrant boxes around :)
44
- config.vm.define "centos-6.5" do |c|
45
- c.vm.box = "centos-6.5"
46
- c.vm.box_url = "http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-puppet.box"
47
- c.vm.provider "virtualbox"
48
- c.vm.provision "shell", :path => "fedora-18/provision.sh"
49
- end
50
-
51
- # Solaris/Illumos/OmniOS
52
- config.vm.define "omnios" do |c|
53
- c.vm.box = "omnios"
54
- c.vm.box_url = "http://omnios.omniti.com/media/omnios-latest.box"
55
- c.vm.provider "virtualbox"
56
- end
57
- end
@@ -1,28 +0,0 @@
1
- # -*- mode: ruby -*-
2
- # vi: set ft=ruby :
3
-
4
- # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
- VAGRANTFILE_API_VERSION = "2"
6
-
7
- Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8
- # All Vagrant configuration is done here. The most common configuration
9
- # options are documented and commented below. For a complete reference,
10
- # please see the online documentation at vagrantup.com.
11
-
12
- # Every Vagrant virtual environment requires a box to build off of.
13
- config.vm.box = "fedora-18"
14
-
15
- # The url from where the 'config.vm.box' box will be fetched if it
16
- # doesn't already exist on the user's system.
17
- config.vm.box_url = "http://puppet-vagrant-boxes.puppetlabs.com/fedora-18-x64-vbox4210-nocm.box"
18
-
19
- # Share an additional folder to the guest VM. The first argument is
20
- # the path on the host to the actual folder. The second argument is
21
- # the path on the guest to mount the folder. And the optional third
22
- # argument is a set of non-required options.
23
- # config.vm.synced_folder "../data", "/vagrant_data"
24
-
25
- config.vm.provision "shell", :path => "provision.sh"
26
-
27
- config.vm.synced_folder "../../../", "/pleaserun"
28
- end
@@ -1,20 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Make sure we install rvm as the vagrant user because I generally want
4
- # to test things as non-root. I'll escalate with sudo if I need privileges.
5
- [ `whoami` != "vagrant" ] && exec chroot --userspec=vagrant / bash -l "$0" "$@"
6
-
7
- export USER=`whoami`
8
- export HOME=/home/vagrant
9
-
10
- case $USER in
11
- root)
12
- [ ! -f "/etc/profile.d/rvm.sh" ] && curl -sSL https://get.rvm.io | bash -s stable
13
- . ". /etc/profile.d/rvm.sh"
14
- ;;
15
- *)
16
- [ ! -f "$HOME/.rvm/scripts/rvm" ] && curl -sSL https://get.rvm.io | bash -s stable
17
- . "$HOME/.rvm/scripts/rvm"
18
- ;;
19
- esac
20
- rvm list | grep -q 'No rvm rubies' && rvm install 1.9.3
data/test.rb DELETED
@@ -1,33 +0,0 @@
1
- $: << "./lib"
2
- require "pleaserun/sysv"
3
- require "fpm"
4
- require "fpm/package/dir"
5
- require "pleaserun/runit"
6
- pr = PleaseRun::SysVInit.new("ubuntu-12.04")
7
- #pr = PleaseRun::Runit.new("")
8
- pr.name = "test fancy"
9
- pr.user = "root"
10
- #pr.args = [ "-t", "sometag", "hello world" ]
11
- #pr.command = "printf"
12
- #pr.args = [ "1: %s\n2: %s\n3: %s\n", "3600", "hello world" ]
13
- #
14
- pr.program = "sleep"
15
- pr.args = [ "3600" ]
16
-
17
- pkg = FPM::Package::Dir.new
18
- pkg.name = "example"
19
- pr.files.each do |path, content|
20
- #next unless path == "/service/test_fancy/run"
21
- out = pkg.staging_path(path)
22
- outdir = File.dirname(out)
23
- FileUtils.mkdir_p(outdir)
24
- File.write(out, content)
25
- end
26
- pkg.output("./example")
27
-
28
- #* identity (user, group)
29
- #* limits (ulimit, etc)
30
- #* environment variables
31
- #* working directory
32
- #* containers (chroot, etc)
33
- #* log/output locations