Restarting server automatically

Discussion in 'Server Operation' started by DrMartinus, May 28, 2018.

  1. DrMartinus

    DrMartinus Member HowtoForge Supporter

    as I have configured the server to get updates to software automatically, I want to make sure that it is restarted from time to time, since kernel updates e.g. require a reboot. I have two questions:
    1. Is this a meaningful plan, or should I rather do it manually and check the server daily? (But I do not want to reboot the server in the middle of the day...)
    2. How to go about it? (I'm pretty sure there are scripts already - the cron thing to execute it would be no problem)
    Thanks in advance!
  2. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    Since I have no idea what operating system you use I can not give definite advice. Debian GNU/Linux has unattended-upgrades package which can be configured to reboot at desired time if upgrade needs rebooting.
    ahrasis likes this.
  3. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    The above suggestion by @Taleman is good already.

    @DrMartinus, you can also check my autopdate script in my github which basically sets a cron to run an update at minute 40 every hour and reboots only when it is required.

    apt-get update && apt-get -y upgrade && apt-get -y autoremove && apt-get -y autoclean
    if [ -f /var/run/reboot-required ]; then
      shutdown -r now
    Edited: I updated my autopdate readme at github to include the following code in its instruction so that if you may boot at a preferred fixed time. In the sample code, it is 3.30am so change it accordingly to your need.

    sed -i "s/shutdown -r now/shutdown -r 3:30/" /usr/share/autopdate
    Note: The script is meant for Ubuntu, Debian and other similar derivatives of Debian. Linux users that using other OS might need to check what is the similar path to /var/run/reboot-required and change that accordingly.
    Last edited: May 29, 2018
  4. Stephan Ververda

    Stephan Ververda Member HowtoForge Supporter

    Personally, i don't do any automatic updates/upgrades that involve a required reboot. For the simple reason of it being live servers with customers on it. If something goes wrong after a reboot it might be a too long downtime before i can even fix it (servers are in a datacenter far from where i live with serial port access for me to be able to access them if all other fails). So anything involving a reboot or huge expected impact on live servers are scheduled for maintenance on weekend/late hours.
    Basically i bring the server down, snapshot the disks, bring it up again, update/upgrade, reboot and test. If things fail i can quickly recover from snapshot, do more extensive research on what have might gone wrong and reschedule. Clients in most cases never noticed any or much downtime.
  5. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    Your advice are good and right in business sense but not all servers are meant for business or have clients.
  6. Stephan Ververda

    Stephan Ververda Member HowtoForge Supporter

    True... that's also why i said "being live servers with customers on it."... but for clarity it probably should have been emphasized bit more. And it was meant as such, just an advice to be carefull when you are working with live servers that could impact customers/operations etc. :)
  7. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    Right indeed.

Share This Page