Skip to content

Instantly share code, notes, and snippets.

@harr1424
Created July 7, 2024 23:12
Show Gist options
  • Save harr1424/3c1fe0260eb2667d55d1097644111ca0 to your computer and use it in GitHub Desktop.
Save harr1424/3c1fe0260eb2667d55d1097644111ca0 to your computer and use it in GitHub Desktop.
systemd scheduled script execution
[Unit]
Description=Run Script
[Service]
Type=simple
ExecStart=/home/ec2-user/script.sh
#!/bin/bash
container_id=$(docker ps -a --filter ancestor=<my_container> --format "{{.ID}}")
if [ -n "$container_id" ]; then
docker kill "$container_id"
docker rm "$container_id"
fi
docker run -d -p <port>:<port> --restart always <my_container>
[Unit]
Description=Run Script Weekly
[Timer]
OnCalendar=weekly
Persistent=true
[Install]
WantedBy=timers.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment