foreman-export-initscript 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.travis.yml +1 -0
- data/Gemfile +6 -0
- data/README.md +13 -0
- data/Rakefile +1 -0
- data/data/export/initscript/master.erb +133 -0
- data/foreman-export-initscript.gemspec +26 -0
- data/lib/foreman-export-initscript.rb +2 -0
- data/lib/foreman-export-initscript/version.rb +0 -0
- data/lib/foreman/export/initscript.rb +32 -0
- data/spec/foreman/export/initscript_spec.rb +30 -0
- data/spec/resources/export/initscript/app +149 -0
- data/spec/resources/export/initscript/app-concurrency +148 -0
- data/spec/spec_helper.rb +52 -0
- metadata +111 -0
data/.travis.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
script: "bundle exec rspec"
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Initscript exporter for foreman
|
2
|
+
|
3
|
+
### Using in your application
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
gem 'foreman-export-initscript', :git => 'git://github.com/lzgo/foreman-export-initscript.git'
|
7
|
+
```
|
8
|
+
|
9
|
+
then `bundle exec foreman export initscript /etc/init.d`
|
10
|
+
|
11
|
+
### Credits
|
12
|
+
|
13
|
+
Shamelessly inspired from foreman-export-nature: https://github.com/nature/foreman-export-nature
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,133 @@
|
|
1
|
+
#! /bin/sh
|
2
|
+
### BEGIN INIT INFO
|
3
|
+
# Provides: <%= app %>
|
4
|
+
# Required-Start: $remote_fs $syslog
|
5
|
+
# Required-Stop: $remote_fs $syslog
|
6
|
+
# Default-Start: 2 3 4 5
|
7
|
+
# Default-Stop: 0 1 6
|
8
|
+
# Short-Description: Generated initscript for <%= app %>
|
9
|
+
# Description: This file starts <%= app %>. It should be placed in /etc/init.d
|
10
|
+
### END INIT INFO
|
11
|
+
|
12
|
+
# Author: Foreman generator
|
13
|
+
#
|
14
|
+
|
15
|
+
# Do NOT "set -e"
|
16
|
+
|
17
|
+
# PATH should only include /usr/* if it runs after the mountnfs.sh script
|
18
|
+
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
19
|
+
DESC="Runs <%= app %>"
|
20
|
+
NAME=<%= app %>
|
21
|
+
PIDDIR=/var/run/$NAME
|
22
|
+
SCRIPTNAME=/etc/init.d/$NAME
|
23
|
+
USERNAME=<%= user %>
|
24
|
+
|
25
|
+
# Read configuration variable file if it is present
|
26
|
+
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
|
27
|
+
|
28
|
+
# Load the VERBOSE setting and other rcS variables
|
29
|
+
[ -r /lib/init/vars.sh ] && . /lib/init/vars.sh
|
30
|
+
|
31
|
+
# Define LSB log_* functions.
|
32
|
+
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
|
33
|
+
# and status_of_proc is working.
|
34
|
+
[ -r /lib/lsb/init-functions ] &&. /lib/lsb/init-functions
|
35
|
+
|
36
|
+
#
|
37
|
+
# Function that starts the daemon/service
|
38
|
+
#
|
39
|
+
do_start()
|
40
|
+
{
|
41
|
+
mkdir -p $PIDDIR
|
42
|
+
mkdir -p <%= log %>
|
43
|
+
chown $USERNAME: <%= log %>
|
44
|
+
# START APPLICATION: <%= app %>
|
45
|
+
<% engine.each_process do |name, process| %>
|
46
|
+
# START PROCESS: <%= name %>
|
47
|
+
<% 1.upto(engine.formation[name]) do |num| %>
|
48
|
+
# START CONCURRENT: <%= num %>
|
49
|
+
# Start: <%= app %>.<%= name %>.<%= num %>
|
50
|
+
# Create $PIDDIR/<%= name %>.<%= num %>.pid
|
51
|
+
su - $USERNAME -c 'cd <%= engine.root %>; export PORT=<%= engine.port_for(process, num) %>;<% engine.environment.each_pair do |var,env| %> export <%= var.upcase %>=<%= env %>; <% end %> <%= process.command %> >> <%= log %>/<%=name%>-<%=num%>.log 2>&1 & echo $!' > $PIDDIR/<%= name %>.<%= num %>.pid
|
52
|
+
<% end %>
|
53
|
+
<% end %>
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
#
|
58
|
+
# Function that stops the daemon/service
|
59
|
+
#
|
60
|
+
do_stop()
|
61
|
+
{
|
62
|
+
# STOP APPLICATION: <%= app %>
|
63
|
+
<% engine.each_process do |name, process| %>
|
64
|
+
# STOP PROCESS: <%= name %>
|
65
|
+
<% 1.upto(engine.formation[name]) do |num| %>
|
66
|
+
# STOP CONCURRENT: <%= num %>
|
67
|
+
# Stop: <%= app %>.<%= name %>.<%= num %>
|
68
|
+
kill `cat $PIDDIR/<%= name %>.<%= num %>.pid`
|
69
|
+
rm $PIDDIR/<%= name %>.<%= num %>.pid
|
70
|
+
<% end %>
|
71
|
+
<% end %>
|
72
|
+
rmdir $PIDDIR
|
73
|
+
}
|
74
|
+
|
75
|
+
case "$1" in
|
76
|
+
start)
|
77
|
+
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
|
78
|
+
do_start
|
79
|
+
case "$?" in
|
80
|
+
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
81
|
+
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
82
|
+
esac
|
83
|
+
;;
|
84
|
+
stop)
|
85
|
+
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
|
86
|
+
do_stop
|
87
|
+
case "$?" in
|
88
|
+
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
89
|
+
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
90
|
+
esac
|
91
|
+
;;
|
92
|
+
status)
|
93
|
+
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
|
94
|
+
;;
|
95
|
+
#reload|force-reload)
|
96
|
+
#
|
97
|
+
# If do_reload() is not implemented then leave this commented out
|
98
|
+
# and leave 'force-reload' as an alias for 'restart'.
|
99
|
+
#
|
100
|
+
#log_daemon_msg "Reloading $DESC" "$NAME"
|
101
|
+
#do_reload
|
102
|
+
#log_end_msg $?
|
103
|
+
#;;
|
104
|
+
restart|force-reload)
|
105
|
+
#
|
106
|
+
# If the "reload" option is implemented then remove the
|
107
|
+
# 'force-reload' alias
|
108
|
+
#
|
109
|
+
log_daemon_msg "Restarting $DESC" "$NAME"
|
110
|
+
do_stop
|
111
|
+
case "$?" in
|
112
|
+
0|1)
|
113
|
+
do_start
|
114
|
+
case "$?" in
|
115
|
+
0) log_end_msg 0 ;;
|
116
|
+
1) log_end_msg 1 ;; # Old process is still running
|
117
|
+
*) log_end_msg 1 ;; # Failed to start
|
118
|
+
esac
|
119
|
+
;;
|
120
|
+
*)
|
121
|
+
# Failed to stop
|
122
|
+
log_end_msg 1
|
123
|
+
;;
|
124
|
+
esac
|
125
|
+
;;
|
126
|
+
*)
|
127
|
+
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
|
128
|
+
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
|
129
|
+
exit 3
|
130
|
+
;;
|
131
|
+
esac
|
132
|
+
|
133
|
+
:
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "foreman-export-initscript"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.authors = ["Emile Cantin"]
|
8
|
+
s.email = ["emile.cantin@gmail.com"]
|
9
|
+
s.homepage = ""
|
10
|
+
s.summary = %q{Export foreman Procfile to a init script}
|
11
|
+
s.description = %q{Export foreman Procfile to a init script}
|
12
|
+
|
13
|
+
s.rubyforge_project = "foreman-export-initscript"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
# specify any dependencies here; for example:
|
21
|
+
s.add_development_dependency "rspec"
|
22
|
+
# s.add_development_dependency "fakefs", git: "git://github.com/defunkt/fakefs.git"
|
23
|
+
s.add_development_dependency "rr"
|
24
|
+
s.add_dependency "foreman"
|
25
|
+
# s.add_runtime_dependency "rest-client"
|
26
|
+
end
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "erb"
|
2
|
+
require "foreman/export"
|
3
|
+
|
4
|
+
class Foreman::Export::Initscript < Foreman::Export::Base
|
5
|
+
|
6
|
+
def export
|
7
|
+
|
8
|
+
#super
|
9
|
+
error("Must specify a location") unless location
|
10
|
+
FileUtils.mkdir_p(location) rescue error("Could not create: #{location}")
|
11
|
+
FileUtils.mkdir_p(log) rescue error("Could not create: #{log}")
|
12
|
+
# begin
|
13
|
+
# FileUtils.chown(user, nil, log)
|
14
|
+
# rescue Exception => e
|
15
|
+
# error("Could not chown #{log} to #{user} - #{e.message}")
|
16
|
+
# end
|
17
|
+
|
18
|
+
name = "initscript/master.erb"
|
19
|
+
name_without_first = name.split("/")[1..-1].join("/")
|
20
|
+
matchers = []
|
21
|
+
matchers << File.join(options[:template], name_without_first) if options[:template]
|
22
|
+
matchers << File.expand_path("~/.foreman/templates/#{name}")
|
23
|
+
matchers << File.expand_path("../../../../data/export/#{name}", __FILE__)
|
24
|
+
path = File.read(matchers.detect { |m| File.exists?(m) })
|
25
|
+
compiled = ERB.new(path).result(binding)
|
26
|
+
write_file "#{app}", compiled
|
27
|
+
# path = export_template name
|
28
|
+
# write_template "initscript/master.erb", "#{app}", binding
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "foreman/engine"
|
3
|
+
require "foreman/export/initscript"
|
4
|
+
require "tmpdir"
|
5
|
+
|
6
|
+
describe Foreman::Export::Initscript, :fakefs do
|
7
|
+
let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
|
8
|
+
let(:formation) { nil }
|
9
|
+
let(:engine) { Foreman::Engine.new(:formation => formation).load_procfile(procfile) }
|
10
|
+
let(:options) { Hash.new }
|
11
|
+
let(:initscript) { FileUtils.mkdir_p("/tmp/init"); Foreman::Export::Initscript.new("/tmp/init", engine, options) }
|
12
|
+
|
13
|
+
before(:each) { load_export_templates_into_fakefs("initscript") }
|
14
|
+
before(:each) { stub(initscript).say }
|
15
|
+
|
16
|
+
it "exports to the filesystem" do
|
17
|
+
initscript.export
|
18
|
+
normalize_space(File.read("/tmp/init/app")).should == normalize_space(example_export_file("initscript/app"))
|
19
|
+
end
|
20
|
+
|
21
|
+
context "with concurrency" do
|
22
|
+
let(:options) { Hash[:concurrency => "alpha=2"] }
|
23
|
+
|
24
|
+
it "exports to the filesystem with concurrency" do
|
25
|
+
initscript.export
|
26
|
+
normalize_space(File.read("/tmp/init/app")).should == normalize_space(example_export_file("initscript/app-concurrency"))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
#! /bin/sh
|
2
|
+
### BEGIN INIT INFO
|
3
|
+
# Provides: app
|
4
|
+
# Required-Start: $remote_fs $syslog
|
5
|
+
# Required-Stop: $remote_fs $syslog
|
6
|
+
# Default-Start: 2 3 4 5
|
7
|
+
# Default-Stop: 0 1 6
|
8
|
+
# Short-Description: Generated initscript for app
|
9
|
+
# Description: This file starts app. It should be placed in /etc/init.d
|
10
|
+
### END INIT INFO
|
11
|
+
|
12
|
+
# Author: Foreman generator
|
13
|
+
#
|
14
|
+
|
15
|
+
# Do NOT "set -e"
|
16
|
+
|
17
|
+
# PATH should only include /usr/* if it runs after the mountnfs.sh script
|
18
|
+
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
19
|
+
DESC="Runs app"
|
20
|
+
NAME=app
|
21
|
+
PIDDIR=/var/run/$NAME
|
22
|
+
SCRIPTNAME=/etc/init.d/$NAME
|
23
|
+
USERNAME=app
|
24
|
+
|
25
|
+
# Read configuration variable file if it is present
|
26
|
+
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
|
27
|
+
|
28
|
+
# Load the VERBOSE setting and other rcS variables
|
29
|
+
[ -r /lib/init/vars.sh ] && . /lib/init/vars.sh
|
30
|
+
|
31
|
+
# Define LSB log_* functions.
|
32
|
+
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
|
33
|
+
# and status_of_proc is working.
|
34
|
+
[ -r /lib/lsb/init-functions ] &&. /lib/lsb/init-functions
|
35
|
+
|
36
|
+
#
|
37
|
+
# Function that starts the daemon/service
|
38
|
+
#
|
39
|
+
do_start()
|
40
|
+
{
|
41
|
+
mkdir -p $PIDDIR
|
42
|
+
mkdir -p /var/log/app
|
43
|
+
chown $USERNAME: /var/log/app
|
44
|
+
# START APPLICATION: app
|
45
|
+
|
46
|
+
# START PROCESS: alpha
|
47
|
+
|
48
|
+
# START CONCURRENT: 1
|
49
|
+
# Start: app.alpha.1
|
50
|
+
# Create $PIDDIR/alpha.1.pid
|
51
|
+
su - $USERNAME -c 'cd /tmp/app; export PORT=5000; ./alpha >> /var/log/app/alpha-1.log 2>&1 & echo $!' > $PIDDIR/alpha.1.pid
|
52
|
+
|
53
|
+
|
54
|
+
# START PROCESS: bravo
|
55
|
+
|
56
|
+
# START CONCURRENT: 1
|
57
|
+
# Start: app.bravo.1
|
58
|
+
# Create $PIDDIR/bravo.1.pid
|
59
|
+
su - $USERNAME -c 'cd /tmp/app; export PORT=5100; ./bravo >> /var/log/app/bravo-1.log 2>&1 & echo $!' > $PIDDIR/bravo.1.pid
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
#
|
66
|
+
# Function that stops the daemon/service
|
67
|
+
#
|
68
|
+
do_stop()
|
69
|
+
{
|
70
|
+
# STOP APPLICATION: app
|
71
|
+
|
72
|
+
# STOP PROCESS: alpha
|
73
|
+
|
74
|
+
# STOP CONCURRENT: 1
|
75
|
+
# Stop: app.alpha.1
|
76
|
+
kill `cat $PIDDIR/alpha.1.pid`
|
77
|
+
rm $PIDDIR/alpha.1.pid
|
78
|
+
|
79
|
+
|
80
|
+
# STOP PROCESS: bravo
|
81
|
+
|
82
|
+
# STOP CONCURRENT: 1
|
83
|
+
# Stop: app.bravo.1
|
84
|
+
kill `cat $PIDDIR/bravo.1.pid`
|
85
|
+
rm $PIDDIR/bravo.1.pid
|
86
|
+
|
87
|
+
|
88
|
+
rmdir $PIDDIR
|
89
|
+
}
|
90
|
+
|
91
|
+
case "$1" in
|
92
|
+
start)
|
93
|
+
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
|
94
|
+
do_start
|
95
|
+
case "$?" in
|
96
|
+
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
97
|
+
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
98
|
+
esac
|
99
|
+
;;
|
100
|
+
stop)
|
101
|
+
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
|
102
|
+
do_stop
|
103
|
+
case "$?" in
|
104
|
+
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
105
|
+
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
106
|
+
esac
|
107
|
+
;;
|
108
|
+
status)
|
109
|
+
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
|
110
|
+
;;
|
111
|
+
#reload|force-reload)
|
112
|
+
#
|
113
|
+
# If do_reload() is not implemented then leave this commented out
|
114
|
+
# and leave 'force-reload' as an alias for 'restart'.
|
115
|
+
#
|
116
|
+
#log_daemon_msg "Reloading $DESC" "$NAME"
|
117
|
+
#do_reload
|
118
|
+
#log_end_msg $?
|
119
|
+
#;;
|
120
|
+
restart|force-reload)
|
121
|
+
#
|
122
|
+
# If the "reload" option is implemented then remove the
|
123
|
+
# 'force-reload' alias
|
124
|
+
#
|
125
|
+
log_daemon_msg "Restarting $DESC" "$NAME"
|
126
|
+
do_stop
|
127
|
+
case "$?" in
|
128
|
+
0|1)
|
129
|
+
do_start
|
130
|
+
case "$?" in
|
131
|
+
0) log_end_msg 0 ;;
|
132
|
+
1) log_end_msg 1 ;; # Old process is still running
|
133
|
+
*) log_end_msg 1 ;; # Failed to start
|
134
|
+
esac
|
135
|
+
;;
|
136
|
+
*)
|
137
|
+
# Failed to stop
|
138
|
+
log_end_msg 1
|
139
|
+
;;
|
140
|
+
esac
|
141
|
+
;;
|
142
|
+
*)
|
143
|
+
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
|
144
|
+
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
|
145
|
+
exit 3
|
146
|
+
;;
|
147
|
+
esac
|
148
|
+
|
149
|
+
:
|
@@ -0,0 +1,148 @@
|
|
1
|
+
#! /bin/sh
|
2
|
+
### BEGIN INIT INFO
|
3
|
+
# Provides: app
|
4
|
+
# Required-Start: $remote_fs $syslog
|
5
|
+
# Required-Stop: $remote_fs $syslog
|
6
|
+
# Default-Start: 2 3 4 5
|
7
|
+
# Default-Stop: 0 1 6
|
8
|
+
# Short-Description: Generated initscript for app
|
9
|
+
# Description: This file starts app. It should be placed in /etc/init.d
|
10
|
+
### END INIT INFO
|
11
|
+
|
12
|
+
# Author: Foreman generator
|
13
|
+
#
|
14
|
+
|
15
|
+
# Do NOT "set -e"
|
16
|
+
|
17
|
+
# PATH should only include /usr/* if it runs after the mountnfs.sh script
|
18
|
+
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
19
|
+
DESC="Runs app"
|
20
|
+
NAME=app
|
21
|
+
PIDDIR=/var/run/$NAME
|
22
|
+
SCRIPTNAME=/etc/init.d/$NAME
|
23
|
+
USERNAME=app
|
24
|
+
|
25
|
+
# Read configuration variable file if it is present
|
26
|
+
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
|
27
|
+
|
28
|
+
# Load the VERBOSE setting and other rcS variables
|
29
|
+
[ -r /lib/init/vars.sh ] && . /lib/init/vars.sh
|
30
|
+
|
31
|
+
# Define LSB log_* functions.
|
32
|
+
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
|
33
|
+
# and status_of_proc is working.
|
34
|
+
[ -r /lib/lsb/init-functions ] &&. /lib/lsb/init-functions
|
35
|
+
|
36
|
+
#
|
37
|
+
# Function that starts the daemon/service
|
38
|
+
#
|
39
|
+
do_start()
|
40
|
+
{
|
41
|
+
mkdir -p $PIDDIR
|
42
|
+
mkdir -p /var/log/app
|
43
|
+
chown $USERNAME: /var/log/app
|
44
|
+
# START APPLICATION: app
|
45
|
+
|
46
|
+
# START PROCESS: alpha
|
47
|
+
|
48
|
+
# START CONCURRENT: 1
|
49
|
+
# Start: app.alpha.1
|
50
|
+
# Create $PIDDIR/alpha.1.pid
|
51
|
+
su - $USERNAME -c 'cd /tmp/app; export PORT=5000; ./alpha >> /var/log/app/alpha-1.log 2>&1 & echo $!' > $PIDDIR/alpha.1.pid
|
52
|
+
|
53
|
+
|
54
|
+
# START CONCURRENT: 2
|
55
|
+
# Start: app.alpha.2
|
56
|
+
# Create $PIDDIR/alpha.2.pid
|
57
|
+
su - $USERNAME -c 'cd /tmp/app; export PORT=5001; ./alpha >> /var/log/app/alpha-2.log 2>&1 & echo $!' > $PIDDIR/alpha.2.pid
|
58
|
+
|
59
|
+
|
60
|
+
# START PROCESS: bravo
|
61
|
+
|
62
|
+
}
|
63
|
+
|
64
|
+
#
|
65
|
+
# Function that stops the daemon/service
|
66
|
+
#
|
67
|
+
do_stop()
|
68
|
+
{
|
69
|
+
# STOP APPLICATION: app
|
70
|
+
|
71
|
+
# STOP PROCESS: alpha
|
72
|
+
|
73
|
+
# STOP CONCURRENT: 1
|
74
|
+
# Stop: app.alpha.1
|
75
|
+
kill `cat $PIDDIR/alpha.1.pid`
|
76
|
+
rm $PIDDIR/alpha.1.pid
|
77
|
+
|
78
|
+
|
79
|
+
# STOP CONCURRENT: 2
|
80
|
+
# Stop: app.alpha.2
|
81
|
+
kill `cat $PIDDIR/alpha.2.pid`
|
82
|
+
rm $PIDDIR/alpha.2.pid
|
83
|
+
|
84
|
+
|
85
|
+
# STOP PROCESS: bravo
|
86
|
+
|
87
|
+
rmdir $PIDDIR
|
88
|
+
}
|
89
|
+
|
90
|
+
case "$1" in
|
91
|
+
start)
|
92
|
+
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
|
93
|
+
do_start
|
94
|
+
case "$?" in
|
95
|
+
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
96
|
+
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
97
|
+
esac
|
98
|
+
;;
|
99
|
+
stop)
|
100
|
+
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
|
101
|
+
do_stop
|
102
|
+
case "$?" in
|
103
|
+
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
104
|
+
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
105
|
+
esac
|
106
|
+
;;
|
107
|
+
status)
|
108
|
+
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
|
109
|
+
;;
|
110
|
+
#reload|force-reload)
|
111
|
+
#
|
112
|
+
# If do_reload() is not implemented then leave this commented out
|
113
|
+
# and leave 'force-reload' as an alias for 'restart'.
|
114
|
+
#
|
115
|
+
#log_daemon_msg "Reloading $DESC" "$NAME"
|
116
|
+
#do_reload
|
117
|
+
#log_end_msg $?
|
118
|
+
#;;
|
119
|
+
restart|force-reload)
|
120
|
+
#
|
121
|
+
# If the "reload" option is implemented then remove the
|
122
|
+
# 'force-reload' alias
|
123
|
+
#
|
124
|
+
log_daemon_msg "Restarting $DESC" "$NAME"
|
125
|
+
do_stop
|
126
|
+
case "$?" in
|
127
|
+
0|1)
|
128
|
+
do_start
|
129
|
+
case "$?" in
|
130
|
+
0) log_end_msg 0 ;;
|
131
|
+
1) log_end_msg 1 ;; # Old process is still running
|
132
|
+
*) log_end_msg 1 ;; # Failed to start
|
133
|
+
esac
|
134
|
+
;;
|
135
|
+
*)
|
136
|
+
# Failed to stop
|
137
|
+
log_end_msg 1
|
138
|
+
;;
|
139
|
+
esac
|
140
|
+
;;
|
141
|
+
*)
|
142
|
+
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
|
143
|
+
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
|
144
|
+
exit 3
|
145
|
+
;;
|
146
|
+
esac
|
147
|
+
|
148
|
+
:
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require "fakefs/safe"
|
3
|
+
require "fakefs/spec_helpers"
|
4
|
+
|
5
|
+
require 'foreman-export-initscript'
|
6
|
+
|
7
|
+
def resource_path(filename)
|
8
|
+
File.expand_path("../resources/#{filename}", __FILE__)
|
9
|
+
end
|
10
|
+
|
11
|
+
def write_procfile(procfile="Procfile", alpha_env="")
|
12
|
+
File.open(procfile, "w") do |file|
|
13
|
+
file.puts "alpha: ./alpha" + " #{alpha_env}".rstrip
|
14
|
+
file.puts "\n"
|
15
|
+
file.puts "bravo:\t./bravo"
|
16
|
+
end
|
17
|
+
File.expand_path(procfile)
|
18
|
+
end
|
19
|
+
|
20
|
+
def load_export_templates_into_fakefs(type)
|
21
|
+
FakeFS.deactivate!
|
22
|
+
files = Dir[File.expand_path("../../data/export/#{type}/**", __FILE__)].inject({}) do |hash, file|
|
23
|
+
hash.update(file => File.read(file))
|
24
|
+
end
|
25
|
+
FakeFS.activate!
|
26
|
+
files.each do |filename, contents|
|
27
|
+
#require "debug"
|
28
|
+
FileUtils.mkdir_p RealFile.dirname filename
|
29
|
+
File.open(filename, "w") do |f|
|
30
|
+
f.puts contents
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def example_export_file(filename)
|
36
|
+
FakeFS.deactivate!
|
37
|
+
data = File.read(File.expand_path(resource_path("export/#{filename}"), __FILE__))
|
38
|
+
FakeFS.activate!
|
39
|
+
data
|
40
|
+
end
|
41
|
+
|
42
|
+
def normalize_space(s)
|
43
|
+
s.gsub(/\n[\n\s]*/, "\n")
|
44
|
+
end
|
45
|
+
|
46
|
+
RSpec.configure do |config|
|
47
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
48
|
+
config.color_enabled = true
|
49
|
+
config.order = 'rand'
|
50
|
+
config.include FakeFS::SpecHelpers, :fakefs
|
51
|
+
config.mock_with :rr
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: foreman-export-initscript
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Emile Cantin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rr
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: foreman
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Export foreman Procfile to a init script
|
63
|
+
email:
|
64
|
+
- emile.cantin@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .travis.yml
|
71
|
+
- Gemfile
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- data/export/initscript/master.erb
|
75
|
+
- foreman-export-initscript.gemspec
|
76
|
+
- lib/foreman-export-initscript.rb
|
77
|
+
- lib/foreman-export-initscript/version.rb
|
78
|
+
- lib/foreman/export/initscript.rb
|
79
|
+
- spec/foreman/export/initscript_spec.rb
|
80
|
+
- spec/resources/export/initscript/app
|
81
|
+
- spec/resources/export/initscript/app-concurrency
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
homepage: ''
|
84
|
+
licenses: []
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project: foreman-export-initscript
|
103
|
+
rubygems_version: 1.8.23
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: Export foreman Procfile to a init script
|
107
|
+
test_files:
|
108
|
+
- spec/foreman/export/initscript_spec.rb
|
109
|
+
- spec/resources/export/initscript/app
|
110
|
+
- spec/resources/export/initscript/app-concurrency
|
111
|
+
- spec/spec_helper.rb
|