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 run the following command across all OpenVZ containers to update/upgrade:

vzctl exec2 $VM "apt-get update & apt-get upgrade"

In all cases, I get the following error:

dpkg-preconfigure: unable to re-open stdin: No such file or directory

And when there are updates available, the prompt "Do you want to continue" is skipped. Also, dpkg cannot set a lock:

E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

How can I fix this?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Try this:

vzctl enter $VM --exec "apt-get update && apt-get upgrade"

The && means "If the previous command completes successfully, continue to the next."

From http://wiki.openvz.org/Man/vzctl.8:

exec CTID command

Executes command in a container. Environment variables are not set inside the container. Signal handlers may differ from default settings. If command is -, commands are read from stdin.

exec2 CTID command

The same as exec, but return code is that of command.

On the other hand

enter CTID [--exec command [arg ...]]

Enters into a container (giving a container’s root shell).

Option --exec is used to run command with arguments after entering into container. This is useful if command to be run requires a terminal

share|improve this answer
    
Wow, now that was easy. Thanks! I added a "&& exit" to make it quit the VZ container to match the exec2 command. –  mo. Sep 17 '13 at 23:35
    
Yes, the correct one is using "&&", sorry, it was a typo copied from the original question. Thanks for pointing out. –  javix Apr 10 at 22:19

Do not use this idiom "apt-get update & apt-get upgrade" as the upgrade will proceed simultaneously with the update which will cause the update to lock the database and the upgrade will fail.

One of the following will be correct:

vzctl enter $VM --exec "apt-get update && apt-get -y upgrade" [note: edited Javix's answer above]

or

vzctl enter $VM --exec "apt-get update; apt-get -y upgrade"

In the first command, the upgrade will proceed only if the update was successful. In the second, it will be attempted anyway.

For each, I've also added a -y for the upgrade to answer "yes" to any questions, which is useful for unattended upgrades such as this.

share|improve this answer

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.