Knowledge Base:Shutdown after emerge

From Gentoo Wiki
Jump to: navigation, search

Emerge is not running

This command shuts down the computer only if emerge finishes successfully, it also saves output to a emerge-log.log file in the current directory that you can reviewed next time the computer boots. For example for updating and shutting down we have:

root #emerge --verbose --deep --newuse --update --with-bdeps=y @world | tee emerge-log.log && shutdown -h now

If you want to turn off the computer only if emerge quits successfully:

root #emerge --verbose --deep --newuse --update --with-bdeps=y @world | tee emerge-log.log ; shutdown -h now

KDE

If you are using KDE, it may be a good idea to have KDE logout first before the shutdown process begins. To do this, type:

root #emerge PACKAGE && kdeinit_shutdown && poweroff

Emerge is already running

If emerge is already running, press ctrl-z. The process will be paused

[1]+ Stopped emerge kdebase-meta

Now type

root #bg && wait && poweroff

bg resumes executing of emerge in the background. wait waits for last command sent to background to terminate. When emerge finishes with success, poweroff command will be executed.

Alternatives

This can be accomplish in a similar way by pausing the process with ctrl-z as described above and then typing this:

root #fg; poweroff

or

root #fg && poweroff

This continues the paused process and after this process finishes it continues the next command (poweroff) ...

It is important to notice that && will only continue with the next command, if the first command completed successfully. && is the logical AND operator of the shell. By using ; the next command will be executed no matter what happened earlier. ; is only a command separator.

A variant of this can be used to play a sound when emerge is done.

root #fg; aplay whateversoundfile

The fg variant is a little more straight forward probably.

External resources