I maintain a file server for a research lab, and I need to figure out how to automate shutting down the server while incorporating a delayed reboot. The electricity is being serviced in our building, and we have shut downs scheduled a couple days a week for the next month. The down times vary from an hour to six hours, all in the middle of the night - a time when I wont be around to manually shut down and reboot the computer. Ideally, I'd like to programmatically do this so our files are available to all lab members without increased delays on my part, and because I think it would a very useful piece of code learn. For example, lets say the power will be out this Friday from 2am to 7am, Saturday from 4am to 6am, and again the following Wednesday from 2am to 3am. Is there a way I can programmatically shut my server down 30 minutes before the power goes out, and have it reboot 45 minutes after the power turns back on?

Im using ubuntu desktop 18.04 with samba.

Thanks in advance.

  • 1
    Will the server accept WOL (Wake on LAN) packets for booting? Some will. Does the server BIOS have options for boot-after-power-restore? Or can boot be scheduled in the server BIOS? – user535733 Aug 20 at 1:47
  • Those are all good questions, and dont know any of the answers. I'll get back to you tomorrow. – Phil_T Aug 20 at 2:26
  • sorry for the delay. I don't have these options available to me. Any other options? – Phil_T Aug 22 at 22:03
  • 1
    Not that I know of. Powering down Ubuntu at a set time is easy, but Ubuntu cannot poweron itself (thermodynamics - it's the law). Many BIOS can poweron at a certain time, but that has nothing to do with Ubuntu and you say you cannot use that feature anyway. Looks like you are setting your alarm early for a few days. – user535733 Aug 22 at 22:07
  • 1
    Depends. My services are all organized so I just march down the line sudo systemctl stop service1 then 2, 3, 4, etc. My shutdowns usually include a backup (I like backups. Backups are our friend). Then I verify that each shutdown is complete systemctl status service1 then 2, 3, 4, etc. After all the services have safely brushed teeth and are tucked in bed, then I shut down the system: sudo shutdown --poweroff now. Alternately, you can leave everything up, let systemd handle stopping all the services like a grown-up, and simply tell it when: sudo shutdown --poweroff 17:45 (5:45 pm). – user535733 Aug 23 at 0:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.