Created
July 7, 2024 23:12
-
-
Save harr1424/3c1fe0260eb2667d55d1097644111ca0 to your computer and use it in GitHub Desktop.
systemd scheduled script execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Run Script | |
[Service] | |
Type=simple | |
ExecStart=/home/ec2-user/script.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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