Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

implemented play:daemonize:upstart

  • Loading branch information...
commit c41a2c0694820d5ff4d7d38f9a3c002c37237ca4 1 parent e1c28fd
Yamashita Yuu authored
Showing with 56 additions and 2 deletions.
  1. +1 −0  commands.py
  2. +46 −2 conf/play-recipes.rb
  3. +9 −0 conf/templates/upstart.erb
View
1  commands.py
@@ -43,6 +43,7 @@ def execute(**kargs):
shutil.copyfile(os.path.join(module, "Capfile"), os.path.join(app.path, "Capfile"))
print "Copying Capistrano Play recipes..."
shutil.copyfile(os.path.join(module, "conf", "play-recipes.rb"), os.path.join(app.path, "conf", "play-recipes.rb"))
+ shutil.copytree(os.path.join(module, "conf", "templates"), os.path.join(app.path, "conf", "templates"))
if(not os.path.exists(os.path.join(app.path, "conf", "deploy.rb"))):
print "Copying Capistrano Play deploy config..."
View
48 conf/play-recipes.rb
@@ -57,6 +57,7 @@
File.join(play_path, 'play')
end
_cset :play_preserve_zip, true
+ _cset :play_modules, []
_cset :play_daemonize_method, :play
_cset :play_daemon do
daemonize.__send__(play_daemonize_method)
@@ -67,6 +68,9 @@
task :default do
transaction {
install_play
+ install_modules
+ }
+ transaction {
play_daemon.setup
}
end
@@ -86,6 +90,12 @@
E
run "rm -f #{play_zip_file}" unless play_preserve_zip
end
+
+ task :install_modules do
+ if 0 < play_modules.length
+ run "#{play_cmd} install #{play_modules.join(' ')}"
+ end
+ end
end
namespace :daemonize do
@@ -108,14 +118,48 @@
start
end
- desc "view play status"
task :status do
run "cd #{app_path} && #{play_cmd} status --pid_file=#{app_pid}"
end
end
namespace :upstart do
- # not implemented yet
+ _cset :play_upstart_service do
+ application
+ end
+ _cset :play_upstart_config do
+ File.join('/etc', 'init', "#{play_upstart_service}.cfg")
+ end
+ _cset :play_upstart_config_template, File.join(File.dirname(__FILE__), 'templates', 'upstart.erb')
+ _cset :play_upstart_options, %w(--deps)
+ _cset :play_upstart_runner do
+ user
+ end
+
+ task :setup do
+ template = File.read(play_upstart_config_template)
+ result = ERB.new(template).result(binding)
+
+ tempfile = File.join('/tmp', File.basename(play_upstart_config))
+ put result, tempfile
+ run "diff #{tempfile} #{play_upstart_config} || #{sudo} mv -f #{tempfile} #{play_upstart_config}"
+ end
+
+ task :start do
+ run "#{sudo} service #{play_upstart_service} start"
+ end
+
+ task :stop do
+ run "#{sudo} service #{play_upstart_service} stop"
+ end
+
+ task :restart do
+ run "#{sudo} service #{play_upstart_service} restart || #{sudo} service #{play_upstart_service} start"
+ end
+
+ task :status do
+ run "#{sudo} service #{play_upstart_service} status"
+ end
end
end
View
9 conf/templates/upstart.erb
@@ -0,0 +1,9 @@
+description <%= play_upstart_service.dump %>
+
+start on runlevel [2345]
+stop on [016]
+
+respawn
+
+chdir <%= current_path %>
+exec su <%= play_upstart_runner.dump %> -c '<%= play_cmd %> run <%= play_upstart_options.join(" ") %>'
Please sign in to comment.
Something went wrong with that request. Please try again.