Created
January 13, 2021 06:36
-
-
Save neggles/50f64f9809052eb14840206101b4e658 to your computer and use it in GitHub Desktop.
certbot systemd unit creation
This file contains hidden or 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 | |
set -e | |
# create service unit file | |
cat << EOF > /etc/systemd/system/certbot.service | |
[Unit] | |
Description=Certbot | |
Documentation=file:///usr/share/doc/python-certbot-doc/html/index.html | |
Documentation=https://certbot.eff.org/docs | |
[Service] | |
Type=oneshot | |
ExecStart=/usr/bin/certbot -q renew | |
PrivateTmp=true | |
EOF | |
# create timer unit file | |
cat << EOF > /etc/systemd/system/certbot.timer | |
[Unit] | |
Description=Run certbot daily | |
After=network-online.target | |
[Timer] | |
OnCalendar=*-*-* 02:00:00 | |
RandomizedDelaySec=7200 | |
Persistent=true | |
[Install] | |
WantedBy=timers.target | |
EOF | |
# ask systemd to reload unit files | |
systemctl daemon-reload | |
# enable units and start timer | |
systemctl enable certbot.timer certbot.service | |
systemctl start certbot.timer | |
# check state | |
systemctl status certbot.timer certbot.service | |
# revert above setting | |
set +e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment