Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 174 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
9  
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
1  
FWIW, update-notifier-common is not installed on Lucid server by default. – Marius Gedminas Jul 29 '10 at 14:37
1  
Thanks! and the file /var/run/reboot-required.pkgs will list the packages that require the reboot. – nealmcb Feb 22 '15 at 17:21

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
8  
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

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

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

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

If you have the reboot-notifier or update-notifier-common packages installed, then you get the files /var/run/reboot-required and /var/run/reboot-required.pkgs

reboot-notifier is newer in Ubuntu Wily and Xenial. Debian stretch, but in jessie-backports

update-notifier-common Is older, in all Ubuntu versions including Xenial and Debian Wheezy. Not in Debian Stretch or Jessie.

( There is some background to the reboot-notifier package at https://feeding.cloud.geek.nz/posts/introducing-reboot-notifier/ )

If you don't have these packages installed then you can compare the version of the linux package installed, with the version running:

tim@tramp:~$ dpkg -l linux-image-*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                              Version               Architecture          Description
+++-=================================-=====================-=====================-=======================================================================
ii  linux-image-3.16.0-4-amd64        3.16.7-ckt20-1+deb8u4 amd64                 Linux 3.16 for 64-bit PCs
ii  linux-image-amd64                 3.16+63               amd64                 Linux for 64-bit PCs (meta-package)
tim@tramp:~$ more /proc/version
Linux version 3.16.0-4-amd64 (debian-kernel@lists.debian.org) (gcc version 4.8.4 (Debian 4.8.4-1) ) #1 SMP Debian <b>3.16.7-ckt20-1+deb8u3</b> (2016-01-17)

You can see here that the latest installed kernel is 3.16.7-ckt20-1+deb8u4 but the kernel running is 3.16.7-ckt20-1+deb8u3. So this system needs a reboot. The u4 vs u3 right at the end.

You might need to scroll the box above. In the /proc/version, it is the version near the end of the line that matters.

The very minor version code change is typical of a Debian security kernel update.

needrestart

Another option is to install the needrestart package.

sudo apt-get install needrestart
sudo needrestart -k

Seems to work even if needrestart was installed after the kernel was upgraded.

share|improve this answer
1  
How does your first paragraph correlate with Ubuntu versions? – muru Mar 6 at 22:16
    
Good point. Thanks. I'd spent so long testing and trying the packages I missed that bit out. I've editted to make clearer and include ubuntu package info. – Tim Bray Mar 7 at 23:52
    
Way back on 8.04, after an update that required a restart, the Cog would turn red. How do I get that behavior back? – PenguinCSC Jun 14 at 8:53

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.