sprinkle-tool / sprinkle

Sprinkle is a software provisioning tool you can use to build remote servers with. eg. to install a Rails, or Sinatra stack on a brand new slice directly after its been created
https://github.com/sprinkle-tool/sprinkle
MIT License
1.15k stars 138 forks source link

Installing mysql hangs #105

Closed alse closed 11 years ago

alse commented 11 years ago

I thought the mysql password prompt is causing it, but preseeding the passwords doesn't work either. It hangs right after entering the sudo password

package :mysql, :provides => :database do
  apt 'mysql-server'
end
# mysql install sequence: env DEBCONF_TERSE='yes' DEBIAN_PRIORITY='critical' DEBIAN_FRONTEND=noninteractive sudo -p 'sudo password: ' apt-get --force-yes -qyu install mysql-server for roles: app

# Or with preseeding:
package :mysql, :provides => :database do
  apt 'mysql-server' do
    pre :install, "echo mysql-server mysql-server/root_password password newpass | sudo debconf-set-selections"
    pre :install, "echo mysql-server mysql-server/root_password_again password newpass | sudo debconf-set-selections"
  end
end
# mysql install sequence: echo mysql-server mysql-server/root_password password newpass | sudo debconf-set-selections; echo mysql-server mysql-server/root_password_again password newpass | sudo debconf-set-selections; env DEBCONF_TERSE='yes' DEBIAN_PRIORITY='critical' DEBIAN_FRONTEND=noninteractive sudo -p 'sudo password: ' apt-get --force-yes -qyu install mysql-server for roles: app
ghost commented 11 years ago

A quick and dirty workaround would be to add "debconf-set-selections" as a command that the deployment user can execute without asking for a password in /etc/sudoers.

My question is: isn't it supposed that pre and post install commands are executed as root? There is not much that can be done under a different user account when installing stuff using apt.

joshgoebel commented 11 years ago

You're calling sudo multiple times, maybe you're second sudo without the sudo -p'sudo password' is causing the hang. Can you try this with the code in the master branch and see if it works any better?

Pre and post commands are run with the same permissions as the installer... if it's sudo then they should be sudo... if no sudo then they aren't sudo.

Which actor are you using?

alse commented 11 years ago

I am using the master branch and capistrano

# deploy.rb
server "1.1.1.1", :web, :app, :db, :primary => true
set :user, "user"

set :application, "newapp"

ssh_options[:forward_agent] = true
default_run_options[:pty] = true
set :use_sudo, true

The normal package without preseeding also hangs on the password prompt

# install.rb
$:<< File.join(File.dirname(__FILE__), 'stack')

package :mysql do
  apt 'mysql-server'
end

policy :stack, :roles => :app do
  requires :mysql
end

deployment do
  # mechanism for deployment
  delivery :capistrano do
    recipes 'Capfile'
  end
  # source based package installer defaults
  source do
    prefix   '/usr/local'           # where all source packages will be configured to install
    archives '/usr/local/sources'   # where all source packages will be downloaded to
    builds   '/usr/local/build'     # where all source packages will be built
  end
end

# mysql install sequence: env DEBCONF_TERSE='yes' 
# DEBIAN_PRIORITY='critical' DEBIAN_FRONTEND=noninteractive 
# sudo -p 'sudo password: ' apt-get --force-yes -qyu install 
# mysql-server for roles: app
joshgoebel commented 11 years ago

In your first example it's equally likely your own "sudo"s are causing the hang... you need to call sudo_cmd to get the correct sudo command that Capistrano knows how to respond to.

pre :install, "echo mysql-server mysql-server/root_password password newpass | #{sudo_cmd} debconf-set-selections"
alse commented 11 years ago

The #{sudo_cmd} didn't appear to do anything. I got a permissions error as if there was no sudo

The preseeding isn't too important, I'm just curious why installing mysql the normal way doesn't work.

joshgoebel commented 11 years ago

If you got an error it would help to paste it here.

I don't know what you mean by "normal" way. Anything that prompts for input will hang.

alse commented 11 years ago

Sorry, by normal I meant without preseeding, the way it's installed in the examples.

I just found the problem. DEBIAN_FRONTEND=noninteractive has to come after the sudo, otherwise it's ignored. I'm using ubuntu 12.04.

package :mysql do
  runner "sudo DEBIAN_FRONTEND=noninteractive apt-get --force-yes -qyu install mysql-server"
end

Here's the error I got before with the preseeding:

=begin
--> Cloud hierarchy for policy stack
  * requires package mysql
--> Normalized installation order for all packages: mysql

  * mysql
mysql install sequence: echo mysql-server mysql-server/root_password password newpass |  debconf-set-selections; echo mysql-server mysql-server/root_password_again password newpass |  debconf-set-selections; env DEBCONF_TERSE='yes' DEBIAN_PRIORITY='critical' DEBIAN_FRONTEND=noninteractive sudo -p 'sudo password: ' apt-get --force-yes -qyu install mysql-server for roles: app

    --> Running Sprinkle::Installers::Apt for roles: app
Password:
------------------------------------------------------
|      Package 'mysql' returned error code ??.       |
------------------------------------------------------

Command
---------
echo mysql-server mysql-server/root_password password newpass |  debconf-set-selections

Hosts
-------
1.1.1.1

STDOUT
--------
debconf: DbDriver "passwords" warning: could not open /var/cache/debconf/passwords.dat: Permission denied

error: Cannot find a question for mysql-server/root_password
debconf: DbDriver "templatedb": could not write /var/cache/debconf/templates.dat-new: Permission denied

Actor error message
---------------------
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'default' -c 'sudo -p '\\''sudo password: '\\'' echo mysql-server mysql-server/root_password password newpass |  debconf-set-selections'" on 1.1.1.1
=end
joshgoebel commented 11 years ago

Awesome. Can you patch and submit a pull request?

joshgoebel commented 11 years ago

Closed: https://github.com/sprinkle-tool/sprinkle/pull/106