Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

When you install certain updates (e.g. a new kernel) in Ubuntu Desktop, you get an indication that a reboot is required (in Lucid, the logout icon turns red).

How can I check, from the command line, whether an Ubuntu server requires a reboot?

I could grep for 'System restart required' in /etc/motd, but I'd like a solution that's more elegant. Also, I want a solution that works in older releases, e.g. Hardy (8.04 LTS).

share|improve this question
    
If you are maintaining server you will soon also develop sense wether or not update require restart. Most updates needs no restart or only restart of service (witch it should do automatically). –  eXlin Nov 18 '10 at 11:45
add comment

5 Answers

up vote 104 down vote accepted

You can simply check if the file /var/run/reboot-required exists or not.

For example, any of these would tell you "no such file" or "file not found" if you do not need to reboot, otherwise they will show information about the file:

file /var/run/reboot-required
stat /var/run/reboot-required
ls /var/run/reboot-required

In a bash script, you can use:

#!/bin/bash
if [ -f /var/run/reboot-required ]; then
  echo 'reboot required'
fi
share|improve this answer
1  
This works, and it works on Hardy too. (Doesn't work on Dapper -- 6.06 -- which I still have on one machine. Tough.) Incidentally, the /var/run/reboot-required file is created by /usr/share/update-notifier/notify-reboot-required which is invoked from various packages' maintainer scripts. –  Marius Gedminas Jul 29 '10 at 14:23
1  
It would work on Dapper too if I installed the update-notifier package, except that it wants to pull down 120 megs' worth of GNOME stuff into my ancient server. –  Marius Gedminas Jul 29 '10 at 14:27
    
Same deal on Debian lenny: if you have update-notifier installed, then (and only then) you can check for /var/run/reboot-required. –  Marius Gedminas Jul 29 '10 at 14:31
8  
Better install update-notifier-common, it doesn't depend on any GUI stuff (but doesn't exist for Dapper). –  Marius Gedminas Jul 29 '10 at 14:35
    
FWIW, update-notifier-common is not installed on Lucid server by default. –  Marius Gedminas Jul 29 '10 at 14:37
add comment

Normally if the file

/var/run/reboot-required 

exists you should reboot. You can see if this file is there by using this simple command in gnome-terminal.

ls /var/run/reboot-required
share|improve this answer
add comment

Aswell as the most direct methods written by others there is a handy indication if you use byobu - a set of scripts to make GNU screen a little more user friendly. It shows a set of information at the bottom of the screen, and that can include whether a reboot is required - along with whether updates are available, the time, uptime, memory used ...

In this screenshot you can see from the 199! on the bottom line with the red background that there are 199 updates available, and the ! means that some are security updates. The menu in the foreground is selecting which status notifications should be displayed.

If a reboot is required then this will be indicated by the symbol (R) displayed in the lower bar with white text on a blue background. More details and other indicators can be read about in the byobu man page.

byobu screenshot

share|improve this answer
add comment

In the package debian-goodies is a command named checkrestart which is quite useful. Its output can help you avoid a full reboot.

share|improve this answer
    
How can it make me avoid a full reboot? –  Oxwivi Sep 9 '11 at 15:03
4  
It tells you, which running applications have loaded shared libraries that were upgraded while the application was running. You then restart the applications and services manually and avoid a full reboot. Does not help with kernel upgrades, though. –  aquaherd Sep 15 '11 at 20:38
    
This should be the top answer. Very helpful. OpenSUSE got a tool built-in (and also helps you how can you run it). Shame Ubuntu just goes "restart, restart". For example colord needed a restart here. Hence, no need to restart. –  Shiki Mar 11 '13 at 14:22
add comment

The /etc/motd file gets its information about whether a reboot is required from /var/run/reboot-required file.

You can check the content of this file in terminal by using cat /etc/motd command

share|improve this answer
add comment

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.