5.26. Scheduled VPS shutdown

To perform maintenance, it is sometimes necessary to shut down the server at a specific time. The shutdown process can be automated using the at service.

  1. Connect to the server via SSH.
  2. Check that the system time on the server is set correctly:
    TZ='Europe/Kyiv' date

    If the time is set incorrectly, please correct it:

    ntpdate ptbtime1.ptb.de && hwclock -w

    Note To execute this command, the ntpdate or netdate package must be installed on the server.

  3. Check whether the at service is running in the list of processes (displayed as atd):
    ps ax | grep atd

    If the service isn't running, start it:

    /etc/init.d/atd start

    Note The at package must be installed on the server to execute this command.

  4. Create a task with a command to shut down the server at the specified time on the specified day. For example, to shut down the server on December 8, 2022, at 9:15 a.m., the command to create the task looks like this:
    echo "/sbin/shutdown -h now"  |  at  09:15  08.12.2022
  5. Check if the task you created appears in the task list:
    atq

When the time specified in the task arrives, the server will automatically execute the shutdown command. You can restart the server after it has been shut down by performing a forced reboot.

Змест