This guide explains how to set up automatic shutdown for a Pod using systemd. systemd is a system and service manager for Linux that provides a reliable and flexible way to manage services and tasks, including scheduled shutdowns.

We advise against using this feature for Pods running long-duration or overnight scripts, as it will forcibly terminate the Pod while the script is in progress.
  1. To initiate a hard shutdown, create a systemd service unit file named /etc/systemd/system/force-shutoff.service with the following content:
# /etc/systemd/system/force-shutoff.service
Description=Forcedly shut off this pod


ExecStart=/usr/bin/env bash -c ' \
    curl \
    -H "Content-Type: application/json" \
    -H "Authorization: Latch-SDK-Token $(cat /root/.latch/token)" \
    --data "{\\"pod_id\\": $(cat /root/.latch/id)}" \
  1. Next, create a systemd timer unit file named /etc/systemd/system/force-shutoff.timer to specify the shutdown schedule:
# /etc/systemd/system/force-shutoff.timer
Description=Forcedly shut off this pod at 5pm

OnCalendar=*-*-* 17:00:00 America/Los_Angeles

  1. Enable and start the timer service using the following command:
systemctl enable --now force-shutoff.timer
  1. If you need to change the shutdown time in the future, update the time in /etc/systemd/system/force-shutoff.timer, and then reload all systemd configurations within the Pod by running:
systemctl daemon-reload
  1. If you want to disable the scheduled shutdown in the future, use the following command:
systemctl disable force-shutoff.timer

By following these steps, you can configure your Pod to perform a scheduled hard shutdown using systemd. This ensures that your Pod shuts down automatically at the specified time, helping you manage resources efficiently.