diff --git a/data/export/initscript/master.erb b/data/export/initscript/master.erb index bde3963..5d46499 100644 --- a/data/export/initscript/master.erb +++ b/data/export/initscript/master.erb @@ -1,4 +1,4 @@ -#! /bin/sh +#! /bin/bash ### BEGIN INIT INFO # Provides: <%= app %> # Required-Start: $remote_fs $syslog @@ -18,7 +18,7 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin DESC="Runs <%= app %>" NAME=<%= app %> -PIDDIR=/var/run/$NAME +PIDDIR=<%= run %>/pid/$NAME SCRIPTNAME=/etc/init.d/$NAME USERNAME=<%= user %> @@ -48,8 +48,14 @@ do_start() # START CONCURRENT: <%= num %> # Start: <%= app %>.<%= name %>.<%= num %> # Create $PIDDIR/<%= name %>.<%= num %>.pid - 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 - <% end %> + if [ "$UID" -eq 0 ]; then + 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 + chown -R $USERNAME $PIDDIR + chown -R $USERNAME <%= log %> + else + 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 + fi + <% end %> <% end %> } diff --git a/foreman-export-initscript.gemspec b/foreman-export-initscript.gemspec index 2f84532..69f5d26 100644 --- a/foreman-export-initscript.gemspec +++ b/foreman-export-initscript.gemspec @@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__) Gem::Specification.new do |s| s.name = "foreman-export-initscript" - s.version = "0.0.1" + s.version = "0.0.2" s.authors = ["Emile Cantin"] s.email = ["emile.cantin@gmail.com"] s.homepage = "" diff --git a/lib/foreman/export/initscript.rb b/lib/foreman/export/initscript.rb index 6006b79..56d866a 100644 --- a/lib/foreman/export/initscript.rb +++ b/lib/foreman/export/initscript.rb @@ -5,10 +5,10 @@ class Foreman::Export::Initscript < Foreman::Export::Base def export - #super - error("Must specify a location") unless location - FileUtils.mkdir_p(location) rescue error("Could not create: #{location}") - FileUtils.mkdir_p(log) rescue error("Could not create: #{log}") + super +# error("Must specify a location") unless location +# FileUtils.mkdir_p(location) rescue error("Could not create: #{location}") +# FileUtils.mkdir_p(log) rescue error("Could not create: #{log}") # begin # FileUtils.chown(user, nil, log) # rescue Exception => e @@ -24,7 +24,7 @@ def export path = File.read(matchers.detect { |m| File.exists?(m) }) compiled = ERB.new(path).result(binding) write_file "#{app}", compiled - FileUtils.chmod(755, "#{app}") + FileUtils.chmod(0755, "#{File.join location, app}") # path = export_template name # write_template "initscript/master.erb", "#{app}", binding end