with_pid 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +1 -1
- data/lib/with_pid.rb +10 -1
- data/require.rb +1 -1
- data/spec/with_pid_spec.rb +1 -2
- data/templates/bash.erb +1 -9
- metadata +2 -2
data/README.markdown
CHANGED
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
|
-
|
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
data/spec/with_pid_spec.rb
CHANGED
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
|
-
|
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.
|
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-
|
12
|
+
date: 2010-04-26 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|