Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to create a script that forces a Debian Lenny install to install the latest version of CRAN R. During the install it appears libc6 is upgraded and the install wants interactive confirm that it's OK to restart three services (mysql, exim4, cron). This process HAS to be unattended as it runs on Amazon's Elastic Map Reduce (EMR) machines. But I'm running out of options. Here's a few things I've tried:

This previous question appears to be exactly what I'm looking for. So I set up my install script as follows:

# set my CRAN repos... yes, I know there's a new convention where to put these. 
echo "deb http://cran.r-project.org/bin/linux/debian lenny-cran/" | sudo tee -a /etc/apt/sources.list
echo "deb-src http://cran.r-project.org/bin/linux/debian lenny-cran/" | sudo tee -a /etc/apt/sources.list

# set the dpkg.cfg options per the previous SuperUser question
echo "force-confold" | sudo tee -a  /etc/dpkg/dpkg.cfg
echo "force-confdef" | sudo tee -a  /etc/dpkg/dpkg.cfg
export DEBIAN_FRONTEND=noninteractive

# add key to keyring so it doesn't complain 
gpg --keyserver pgp.mit.edu --recv-key 381BA480
gpg -a --export 381BA480 > jranke_cran.asc
sudo apt-key add jranke_cran.asc

sudo apt-get update

# install the latest R
sudo apt-get install --yes --force-yes r-base 

But this script hangs with the following request for input:

enter image description here

OK, so I tried stopping the services using the following script:

sudo /etc/init.d/mysql stop
sudo /etc/init.d/exim4 stop
sudo /etc/init.d/cron stop
sudo apt-get install --yes --force-yes libc6

This does not work and the interactive screen comes back, but this time with only cron listed as the service that must be restarted.

So is there a way to make libc6 just restart these services with no user input? Or is there a way to stop cron so it does not cause an interactive prompt? Maybe a creative option I've never thought of?

Keep in mind that this system is brought up, some Hadoop code is run, and then it's torn down. So I can put up with side effects and bad behavior that we might not want in a production desktop machine or web server.

share|improve this question

6 Answers 6

up vote 7 down vote accepted

I'm not positive on the settings in Lenny but I know that in Squeeze, sudo is configured with env_reset meaning it will strip out all but a very few select env variables before running the command.

This means the DEBIAN_FRONTEND variable you set is never actually making it to the apt-get install --yes --force-yes r-base. If you have full access to sudo, meaning you are in the sudoers files with ALL = ALL permissions, then you can override this behavior.

Try using the following instead.

sudo DEBIAN_FRONTEND=noninteractive apt-get install --yes --force-yes r-base

Edit: Note that rewriting the script to not use sudo everywhere and instead run the script as root would also work. But doing that would just be avoiding the real problem I pointed out instead of solving it and learning from it.

share|improve this answer
    
I voted up, but also recommend changing the command to sudo sh -c "DEBIAN_FRONTEND=noninteractive apt-get install --yes --force-yes r-base" –  bahamat Feb 23 '11 at 0:28
    
@bahamat, I tested both @arrowmaster's solution as yours. Both work for me. Thank you both very much. What's the advantage of passing the command to sh -c? –  JD Long Feb 24 '11 at 15:48
    
@JD Long: The sh -c method is assured to work as long as you are allowed to run sh through sudo. The one I used can be rejected by sudo depending on the sudo config, but I find it highly unlikely that would happen in a situation that you could use sh -c as an alternative. –  Arrowmaster Feb 24 '11 at 21:01

A more concise variant of the debconf solution mentioned in another answer is the following:

echo 'libc6 libraries/restart-without-asking boolean true' | sudo debconf-set-selections

I just used this solution successfully when upgrading glibc on Debian 7 (wheezy).

For the curious, the way I found the right configuration variable to set was as follows:

sudo apt-get install debconf-utils

sudo apt-get install -y libc6 # answer prompt interactively

debconf-get-selections | grep libc6

share|improve this answer
    
It is nice that you provided the tools you used to get the answer. That could help the next guy find the answer to a different problem. –  Slartibartfast Mar 10 at 6:09
    
smart, thanks!! –  ufotds Apr 28 at 21:31

Step 1

On the host that had the package installed manually (interactive option selection) run:

apt-get install debconf-utils
debconf-get-selections > answers.conf


Step 2 (Optional)

At this point you may want to filter answers.conf to include the configuration answers only for specific package(s). I tested without filtering.


Step 3

When creating a new host, include answers.conf along with your automatic installation script. Before running apt-get install, in the script, run:

debconf-set-selections --verbose < answers.conf


Result

This will fill the debconf database with predefined answers. The interactive questions will not be asked when you run apt-get install.

share|improve this answer
    
Thanks for all your help. I've got an ugly, but working solution. But I'm keepign the debconf options you point out in the back of my mind. I may need those next time. –  JD Long Feb 22 '11 at 17:02

I was able to deduce that the libc6 installer was prompting to restart cron even if cron was not running which seems odd. At any rate I was able to get around that by renaming the cron init.d scripts so that the package installer was fooled into not thinking cron was present. Ugh. What a mess:

sudo /etc/init.d/mysql stop
sudo /etc/init.d/exim4 stop
sudo /etc/init.d/cron stop
sudo mv /etc/init.d/cron /etc/init.d/cron.bak
sudo apt-get install --yes --force-yes libc6
sudo mv /etc/init.d/cron.bak /etc/init.d/cron
sudo /etc/init.d/mysql start
sudo /etc/init.d/exim4 start
sudo /etc/init.d/cron start

After that little kabuki dance I can install the latest R.

share|improve this answer
    
Yay. Good enough for government, err, modeling work as we say. –  Dirk Eddelbuettel Feb 22 '11 at 17:26

You can try:

printf "\n" | sudo apt-get install --yes --force-yes libc6 
share|improve this answer
    
I suggested that earlier to JD; it is what leads to the libc6 upgrade creating the trouble he is having. –  Dirk Eddelbuettel Feb 22 '11 at 15:30
    
the pringf "\n" | bit is novel. I like it, but I tried it and, for some reason it did not cause the confirm page to go away. God only knows what ate the \n. –  JD Long Feb 22 '11 at 15:59
    
Try putting multiple \n's –  Aleksandr Levchuk Feb 22 '11 at 16:01
    
oddly enough it does something weird at the blue screen. If I add the printf "\n" then the cursor is no longer in the box and I can't navigate the screen at all. Really odd. I was hopeful for this hack. –  JD Long Feb 22 '11 at 16:31

Besides what we discussed in email, there is also the saying

If you can't beat'em, join'em.

so you could create a virtual machine on your laptop which corresponds to the (base) packages on the cloud instance, and then rebuild your own local R 2.12.1 .deb against those packages. As no upgraded libc6 is involved, you'd sidestep the issue.

Or, in line with your comment on possible side-effects being permitted, you could uninstall exim4, mysql and cron. Your R jobs won't need them. Something like

sudo dpkg --force-depends --remove ...names of your packages here...

but I can't really believe I recommend this :) You may need a trial and error to get all related exim and mysql packages.

share|improve this answer
    
Now we're talking brute force! ;) I tried uninstalling cron and it makes me type a confirm phrase, something like, "I know I am insane, but it's OK" –  JD Long Feb 22 '11 at 15:55
    
Ah, damn, yes. I think packages of a certain Priority: may get that. So back to building a custom / local R .deb package? Or can't you just bloody run R from lenny (and fetch the corresponding CRAN packages 'manually' from the Archive section on CRAN? –  Dirk Eddelbuettel Feb 22 '11 at 16:22
    
This was a way bigger pain in my ass than I ever imagined it would be. The kludge below has bought me some time... for now. Thanks again for helping me brainstorm ideas. –  JD Long Feb 22 '11 at 17:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.