Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added support for starting passenger under sudo/rvmsudo #1

Merged
merged 1 commit into from

3 participants

@andrewtimberlake

This allows running passenger on port 80 in development

@thibaudgg thibaudgg merged commit c25b3e9 into guard:master
@thibaudgg
Owner

Great pull request, thanks!

@andrewtimberlake

Glad I could help

@mordaroso
Collaborator

Thanks Andrew.

Your pull request is now in the 0.4.0 release.
https://github.com/mordaroso/guard-passenger/tree/v0.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
3  README.rdoc
@@ -52,8 +52,9 @@ Guard::Passenger accepts some options for configuration.
# :cli string options to pass to passenger command (default: '--daemonize')
# :notification boolean Notifications enabled (default: true)
# :ping boolean or string ping localhost after Passenger restart (default: false)
+ # :sudo boolean or string start Passenger under sudo (default: false)
- guard 'passenger', :standalone => false, :cli => '--daemonize --port 3001 --address my_app.local --environment production', :ping => '/foo' do
+ guard 'passenger', :standalone => false, :cli => '--daemonize --port 3001 --address my_app.local --environment production', :ping => '/foo', :sudo => 'rvmsudo' do
end
== Development
View
9 lib/guard/passenger.rb
@@ -8,7 +8,7 @@ class Passenger < Guard
autoload :Runner, 'guard/passenger/runner'
autoload :Pinger, 'guard/passenger/pinger'
- attr_reader :cli_start, :cli_stop, :ping, :notification
+ attr_reader :cli_start, :cli_stop, :ping, :notification, :sudo
def standalone?
@standalone
@@ -34,18 +34,21 @@ def initialize(watchers = [], options = {})
options[:ping]
end
@ping = ping_opt.eql?(true) ? '/' : ping_opt
+
+ @sudo = options[:sudo] || ''
+ @sudo = @sudo.eql?(true) ? 'sudo' : @sudo
end
# Call once when guard starts
def start
UI.info 'Guard::Passenger is running!'
- standalone? ? Runner.start_passenger(cli_start) : true
+ standalone? ? Runner.start_passenger(cli_start, @sudo) : true
end
# Call with Ctrl-C signal (when Guard quit)
def stop
UI.info 'Stopping Passenger...'
- Runner.stop_passenger(cli_stop) if standalone?
+ Runner.stop_passenger(cli_stop, @sudo) if standalone?
true
end
View
8 lib/guard/passenger/runner.rb
@@ -13,9 +13,9 @@ def restart_passenger
succeed
end
- def start_passenger(cli)
+ def start_passenger(cli, sudo = '')
if passenger_standalone_installed?
- succeed = system("passenger start #{cli}")
+ succeed = system("#{sudo} passenger start #{cli}".strip)
if succeed
UI.info "Passenger standalone started."
else
@@ -28,8 +28,8 @@ def start_passenger(cli)
end
end
- def stop_passenger(cli)
- succeed = system("passenger stop #{cli}")
+ def stop_passenger(cli, sudo = '')
+ succeed = system("#{sudo} passenger stop #{cli}".strip)
if succeed
UI.info "Passenger standalone stopped."
else
View
19 spec/guard/passenger/runner_spec.rb
@@ -26,6 +26,12 @@
subject.start_passenger('--port 1337 --daemonize').should be_true
end
+ it 'should start passenger under sudo if sudo option set' do
+ subject.should_receive(:system).with('rvmsudo passenger start --port 80 --daemonize').and_return(true)
+ Guard::UI.should_receive(:info).with("Passenger standalone started.")
+ quietly { subject.start_passenger('--port 80 --daemonize', 'rvmsudo').should be_true }
+ end
+
it 'should fail to start passenger in development environment on the port 1' do
subject.should_receive(:system).with('passenger start --port 1 --daemonize').and_return(false)
Guard::UI.should_receive(:error).with("Passenger standalone failed to start!")
@@ -60,7 +66,7 @@
describe '#stop_passenger' do
it 'should call "passenger stop --port 3000" by default' do
- subject.should_receive(:system).with('passenger stop ').and_return(true)
+ subject.should_receive(:system).with('passenger stop').and_return(true)
subject.stop_passenger('')
end
@@ -69,14 +75,19 @@
subject.stop_passenger("--port 3001")
end
+ it 'should call "rvmsudo passenger stop --port 80" if port has been changed and sudo is set' do
+ subject.should_receive(:system).with('rvmsudo passenger stop --port 80').and_return(true)
+ subject.stop_passenger("--port 80", 'rvmsudo')
+ end
+
it 'should display info message if stop succeeds' do
- subject.should_receive(:system).with('passenger stop ').and_return(true)
+ subject.should_receive(:system).with('passenger stop').and_return(true)
Guard::UI.should_receive(:info).with("Passenger standalone stopped.")
subject.stop_passenger('')
end
it 'should display error message if stop fails' do
- subject.should_receive(:system).with('passenger stop ').and_return(false)
+ subject.should_receive(:system).with('passenger stop').and_return(false)
Guard::UI.should_receive(:error).with("Passenger standalone failed to stop!")
subject.stop_passenger('')
end
@@ -115,4 +126,4 @@
end
end
-end
+end
View
48 spec/guard/passenger_spec.rb
@@ -75,6 +75,28 @@
subject.ping.should == 'foo'
end
end
+
+ describe 'sudo' do
+ it 'should be blank by default' do
+ subject = Guard::Passenger.new([])
+ subject.sudo.should == ''
+ end
+
+ it 'should be blank if set to false' do
+ subject = Guard::Passenger.new([], { :sudo => false })
+ subject.sudo.should == ''
+ end
+
+ it 'should be "sudo" if set to true' do
+ subject = Guard::Passenger.new([], { :sudo => true })
+ subject.sudo.should == 'sudo'
+ end
+
+ it 'should be "rvmsudo" if set to "rvmsudo"' do
+ subject = Guard::Passenger.new([], { :sudo => 'rvmsudo' })
+ subject.sudo.should == 'rvmsudo'
+ end
+ end
end
describe 'port' do
@@ -131,19 +153,26 @@
end
it 'should call `passenger start\' command if standalone is set' do
- Guard::Passenger::Runner.should_receive(:start_passenger).with('--daemonize').and_return(true)
+ Guard::Passenger::Runner.should_receive(:start_passenger).with('--daemonize', '').and_return(true)
subject.start
end
it 'should call `passenger start -p 1337\' command if standalone is set and port is set to 1337' do
subject.should_receive(:cli_start).and_return('--daemonize --port 1337')
- Guard::Passenger::Runner.should_receive(:start_passenger).with('--daemonize --port 1337').and_return(true)
+ Guard::Passenger::Runner.should_receive(:start_passenger).with('--daemonize --port 1337', '').and_return(true)
subject.start
end
it 'should call `passenger start -p 1337\' command if standalone is set, port is set to 1337 and environment is production' do
subject.should_receive(:cli_start).and_return('--daemonize --port 1337 --environment production')
- Guard::Passenger::Runner.should_receive(:start_passenger).with('--daemonize --port 1337 --environment production').and_return(true)
+ Guard::Passenger::Runner.should_receive(:start_passenger).with('--daemonize --port 1337 --environment production', '').and_return(true)
+ subject.start
+ end
+
+ it 'should call `rvmsudo passenger start -p 80` command if sudo is set to "rvmsudo" and port is set to 80' do
+ subject = Guard::Passenger.new([], { :sudo => 'rvmsudo' })
+ subject.should_receive(:cli_start).and_return('--daemonize --port 80')
+ Guard::Passenger::Runner.should_receive(:start_passenger).with('--daemonize --port 80', 'rvmsudo').and_return(true)
subject.start
end
end
@@ -162,13 +191,20 @@
it 'should call `passenger stop\' command if standalone is set and port is 1337' do
subject.should_receive(:cli_stop).and_return('--port 1337')
- Guard::Passenger::Runner.should_receive(:stop_passenger).with('--port 1337').and_return(true)
+ Guard::Passenger::Runner.should_receive(:stop_passenger).with('--port 1337', '').and_return(true)
subject.stop
end
it 'should call `passenger stop\' command if standalone is set and port is 1337' do
subject.should_receive(:cli_stop).and_return('--pid-file "/usr/passenger.pid"')
- Guard::Passenger::Runner.should_receive(:stop_passenger).with('--pid-file "/usr/passenger.pid"').and_return(true)
+ Guard::Passenger::Runner.should_receive(:stop_passenger).with('--pid-file "/usr/passenger.pid"', '').and_return(true)
+ subject.stop
+ end
+
+ it 'should call `rvmsudo passenger stop` command if standalone is set and sudo is set to "rvmsudo"' do
+ subject = Guard::Passenger.new([], { :sudo => 'rvmsudo' })
+ subject.should_receive(:cli_stop).and_return('--pid-file "/usr/passenger.pid"')
+ Guard::Passenger::Runner.should_receive(:stop_passenger).with('--pid-file "/usr/passenger.pid"', 'rvmsudo').and_return(true)
subject.stop
end
end
@@ -219,4 +255,4 @@
end
end
-end
+end
Something went wrong with that request. Please try again.