Browse files

Disable the services that may or may not be started depending on the …

…current roles (nginx, mysql, memcached) by removing the rc.d symlinks, instead of by changing the x bit. This way the change will be kept if the package is upgraded (the init.d script might be replaced), and the init.d scripts can still be run normally (by god or manually)
  • Loading branch information...
1 parent 24ca329 commit fcef45cead8086ffe8a8f6577326187cf9f628d5 @pauldowman committed Mar 31, 2009
8 lib/ec2onrails/capistrano_utils.rb
@@ -6,8 +6,12 @@ def run_local(command)
def run_init_script(script, arg)
- # since init scripts might have the execute bit unset by the set_roles script we need to check
- sudo "sh -c 'if [ -x /etc/init.d/#{script} ] ; then /etc/init.d/#{script} #{arg}; fi'"
+ # TODO only restart a service if it's already started.
+ # Aside from being smarter and more efficient, This will make sure we
+ # aren't starting a service that shouldn't be started for the current
+ # roles (e.g. don't start nginx when we're not in the web role)
+ # How? Maybe need another param with the process name?
+ sudo "/etc/init.d/#{script} #{arg}"
# return hostnames for the role named role_sym that has the specified options
9 lib/ec2onrails/recipes/server.rb
@@ -395,15 +395,12 @@
(use the deploy_files task).
task :enable_ssl, :roles => :web do
- #TODO: enable for nginx
- sudo "a2enmod ssl"
- sudo "a2enmod headers" # the headers module is necessary to forward a header so that rails can detect it is handling an SSL connection. NPG 7/11/08
- sudo "a2ensite default-ssl"
- run_init_script("nginx", "restart")
+ # TODO: enable for nginx
+ # run_init_script("nginx", "restart")
desc <<-DESC
- Restrict the main user's sudo access.
+ Restrict the app user's sudo access.
Defaults the user to only be able to \
sudo to god
6 server/files/usr/local/ec2onrails/bin/init_services.rb
@@ -22,12 +22,6 @@
include Ec2onrails::RolesHelper
-# if not in a role, we want to make sure that the service is stopped....
-# it gets a little tricky with the web_proxy, which is not enabled if it is
-# not already in a web role. Leave as is, as all it does is throw an error
-# until GOD is in the picture, at which case it should be easy to enable
-# and let it handle it instead of the init.d script....
APP_ROOT = "/mnt/app/current"
RAILS_ENV = `/usr/local/ec2onrails/bin/rails_env`.strip
28 server/rakefile.rb
@@ -205,7 +205,19 @@
# Create symlinks to run scripts on startup
run_chroot "update-rc.d ec2-first-startup start 91 S ."
run_chroot "update-rc.d ec2-every-startup start 92 S ."
- run_chroot "update-rc.d set_roles start 99 S ."
+ run_chroot "update-rc.d init_services start 99 S ."
+ # Disable the services that will be managed by god, depending on the roles
+ %w(nginx mysql memcached).each do |service|
+ run_chroot "update-rc.d -f #{service} remove"
+ run_chroot "update-rc.d #{service} stop 20 2 3 4 5 ."
+ end
+ # God is started by upstart so that it will be restarted automatically if it dies,
+ # see /etc/event.d/god
+ # Create the mail aliases db
+ run_chroot "postalias /etc/aliases"
@@ -236,20 +248,6 @@ def run(command, ignore_error = false)
raise("error: #{$?}") unless result || ignore_error
-# def mount(type, mount_point)
-# unless mounted?(mount_point)
-# puts
-# puts "********** Mounting #{type} on #{mount_point}..."
-# puts
-# run "mount -t #{type} none #{mount_point}"
-# end
-# end
-# def mounted?(mount_point)
-# mount_point_regex = mount_point.gsub(/\//, "\\/")
-# `mount`.select {|line| line.match(/#{mount_point_regex}/) }.any?
-# end
def replace_line(file, newline, linenum)
contents =, 'r').readlines
contents[linenum - 1] = newline

1 comment on commit fcef45c


Sorry, this commit has a few extra things in it that should have been in previous commits. The last few commits were a bit messy because I was in “git add -i” hell, trying to untangle a bunch of unrelated uncommitted changes.

Please sign in to comment.