with_pid 0.1.0 → 0.1.1

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.
data/README.markdown CHANGED
@@ -15,7 +15,7 @@ sudo gem install with_pid
15
15
  Ruby script
16
16
  -----------
17
17
 
18
- <code>/data/my_app/current/bin/dj</code>:
18
+ ### /data/my_app/current/bin/dj
19
19
 
20
20
  <pre>
21
21
  #!/usr/bin/env ruby
data/lib/with_pid.rb CHANGED
@@ -2,16 +2,25 @@ require 'rubygems'
2
2
  require 'erb'
3
3
 
4
4
  def with_pid(options)
5
+ # Path to bash script
6
+ bash_path = options[:tmp] + "/" + options[:name]
7
+
8
+ # Add pid_dir option
5
9
  options[:pid_dir] = File.dirname(options[:pid])
10
+
11
+ # Render bash script
6
12
  template = File.dirname(__FILE__) + '/../templates/bash.erb'
7
13
  template = File.expand_path(template)
8
14
  template = File.read(template)
9
15
  template = ERB.new(template).result(binding)
10
- bash_path = options[:tmp] + "/" + options[:name]
16
+
17
+ # Write bash script to tmp
11
18
  FileUtils.mkdir_p(options[:tmp])
12
19
  File.open(bash_path, 'w') do |f|
13
20
  f.write(template)
14
21
  end
22
+
23
+ # Execute bash script
15
24
  `chmod +x #{bash_path}`
16
25
  `#{bash_path}`
17
26
  end
data/require.rb CHANGED
@@ -13,7 +13,7 @@ Require do
13
13
  name 'with_pid'
14
14
  homepage "http://github.com/winton/#{name}"
15
15
  summary "The simple way to create and monitor a Ruby daemon"
16
- version '0.1.0'
16
+ version '0.1.1'
17
17
  end
18
18
 
19
19
  rakefile do
@@ -17,8 +17,7 @@ describe :with_pid do
17
17
  :command => "ps",
18
18
  :name => "test",
19
19
  :pid => @tmp + "/test.pid",
20
- :tmp => @tmp,
21
- :user => "winton"
20
+ :tmp => @tmp
22
21
  )
23
22
  output.include?('PID').should == true
24
23
  File.read(@tmp + "/test.pid").to_i.should > 0
data/templates/bash.erb CHANGED
@@ -4,8 +4,6 @@ PATH=/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
4
4
  CURDIR=`pwd`
5
5
  COMMAND="<%= options[:command] %>"
6
6
  PID_FILE="<%= options[:pid] %>"
7
- USER="<%= options[:user] %>"
8
- HOME="/home/$USER" ; export HOME
9
7
 
10
8
  mkdir -p <%= options[:pid_dir] %>
11
9
 
@@ -21,22 +19,16 @@ case "<%= options[:action] %>" in
21
19
  rm -f $PID_FILE
22
20
  fi
23
21
  echo $$ > $PID_FILE;
24
- <% if RUBY_PLATFORM.include?('darwin') %>
25
- exec 2<&1 sudo -u$USER "$COMMAND"
26
- <% else %>
27
- exec 2<&1 su -c"$COMMAND" $USER
28
- <% end %>
22
+ exec 2<&1 $COMMAND
29
23
  ;;
30
24
  stop)
31
25
  echo "Stopping <%= options[:name] %>"
32
26
  if [ -f $PID_FILE ]; then
33
27
  kill -15 `cat $PID_FILE` 2>/dev/null; true
34
28
  fi
35
-
36
29
  [ -e "$PIDFILE" ] && rm -f $PIDFILE
37
30
  ;;
38
31
  *)
39
- usage
40
32
  ;;
41
33
  esac
42
34
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: with_pid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winton Welsh
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-04-18 00:00:00 -07:00
12
+ date: 2010-04-26 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15