{"id":213,"date":"2022-10-30T15:08:56","date_gmt":"2022-10-30T15:08:56","guid":{"rendered":"https:\/\/marshallpdavis.com\/?page_id=213"},"modified":"2022-10-30T15:08:56","modified_gmt":"2022-10-30T15:08:56","slug":"scripts-services-and-timers-oh-my","status":"publish","type":"page","link":"https:\/\/marshallpdavis.com\/?page_id=213","title":{"rendered":"Scripts, services, and timers &#8211; OH, MY!"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Blank lines removed &#8211; they should probably be added back as desired for readability.<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\/usr\/lib\/systemd\/system\/updatewordpress.service:<br><code>[Unit]<br>Description=Run WordPress update script<br>[Service]<br>Type=oneshot<br>ExecStart=\/root\/updatewp.sh<\/code><\/p>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\/usr\/lib\/systemd\/system\/updatewordpress.timer:<br><code>[Unit]<br>Description=Check for wordpress update daily<br>[Timer]<br>OnCalendar=daily<br>Persistent=true<br>[Install]<br>WantedBy=timers.target<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\/usr\/lib\/systemd\/system\/certbot-renew.service:<br><code>[Unit]<br>Description=Update SSL certs<br>[Service]<br>Type=oneshot<br>ExecStart=\/usr\/bin\/sleep $((RANDOM % 86400)) &amp;&amp; \/usr\/bin\/certbot renew<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\/usr\/lib\/systemd\/system\/certbot-renew.timer:<br><code>[Unit]<br>Description=Update SSL certs monthly<br>[Timer]<br>OnCalendar=<em>*-*<\/em>-26 00:00:00<br>Persistent=true<br>[Install]<br>WantedBy=timers.target<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\/usr\/lib\/systemd\/system\/webbackups.service:<br><code>[Unit]<br>Description=Run WordPress backup script<br>[Service]<br>Type=oneshot<br>ExecStart=\/root\/backups.sh<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\/usr\/lib\/systemd\/system\/webbackups.timer:<br><code>[Unit]<br>Description=Run webbackups script weekly<br>[Timer]<br>OnCalendar=Sun *<em>-*<\/em>-* 06:00:00<br>Persistent=true<br>[Install]<br>WantedBy=timers.target<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">updatewp.sh:<br><code>rm \/root\/latest.tar.gz<br>wget -O \/root\/latest.tar.gz https:\/\/wordpress.org\/latest.tar.gz<br>if ! cmp \/root\/latest.tar.gz \/srv\/http\/wordpress.tar.gz >\/dev\/null 2>&amp;1; then<br>  rm \/srv\/http\/wordpress.tar.gz<br>  rm -rf \/srv\/http\/wordpress<br>  cp \/root\/latest.tar.gz \/srv\/http\/wordpress.tar.gz<br>  tar xf \/srv\/http\/wordpress.tar.gz -C \/srv\/http\/<br>  cp -R \/srv\/http\/wordpress\/* \/srv\/http\/wp_site1\/<br>  chown -R http:http \/srv\/http\/wp_site1<br>  cp -R \/srv\/http\/wordpress\/* \/srv\/http\/wp_site2\/<br>  chown -R http:http \/srv\/http\/wp_site2<br>  echo \"Updated wp at \" >> \/root\/wpstatus.log<br>  date >> \/root\/wpstatus.log<br>else<br>  echo \"No update needed at \" >> \/root\/wpstatus.log<br>  date >> \/root\/wpstatus.log<br>fi<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">backups.sh:<br><code>mkdir \/backups\/uncomp$(date +%Y%m%d)<br>cp -r \/srv\/http \/backups\/uncomp$(date +%Y%m%d)<br>cp -r \/etc\/httpd \/backups\/uncomp$(date +%Y%m%d)<br>cp -r \/etc\/letsencrypt \/backups\/uncomp$(date +%Y%m%d)<br>\/usr\/bin\/mysqldump -u backmeup -p### --databases wordpress1 > \/backups\/uncomp$(date +%Y%m%d)\/wordpress1.sql<br>\/usr\/bin\/mysqldump -u backmeup -p### --databases wordpress2 > \/backups\/uncomp$(date +%Y%m%d)\/wordpress2.sql<br>tar czf \/backups\/comp$(date +%Y%m%d).tar.gz \/backups\/uncomp$(date +%Y%m%d)<br>tar ztvf \/backups\/comp$(date +%Y%m%d).tar.gz > \/dev\/null &amp;&amp;<br>rm -rf \/backups\/uncomp$(date +%Y%m%d)<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And on my home workstation, this runs a couple of hours after the backups.sh script:<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">receivebackups.sh:<br><code>for x in ssh root@server ls \/backups\/; do<br>  scp root@server:\/backups\/$x \/webbackups<br>  tar ztvf \/webbackups\/$x > \/dev\/null &amp;&amp;<br>  ssh root@server rm \/backups\/$x<br>done<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Blank lines removed &#8211; they should probably be added back as desired for readability. \/usr\/lib\/systemd\/system\/updatewordpress.service:[Unit]Description=Run WordPress update script[Service]Type=oneshotExecStart=\/root\/updatewp.sh \/usr\/lib\/systemd\/system\/updatewordpress.timer:[Unit]Description=Check for wordpress update daily[Timer]OnCalendar=dailyPersistent=true[Install]WantedBy=timers.target \/usr\/lib\/systemd\/system\/certbot-renew.service:[Unit]Description=Update SSL certs[Service]Type=oneshotExecStart=\/usr\/bin\/sleep $((RANDOM % 86400)) &amp;&amp; \/usr\/bin\/certbot renew \/usr\/lib\/systemd\/system\/certbot-renew.timer:[Unit]Description=Update SSL certs monthly[Timer]OnCalendar=*-*-26 00:00:00Persistent=true[Install]WantedBy=timers.target \/usr\/lib\/systemd\/system\/webbackups.service:[Unit]Description=Run WordPress backup script[Service]Type=oneshotExecStart=\/root\/backups.sh \/usr\/lib\/systemd\/system\/webbackups.timer:[Unit]Description=Run webbackups script weekly[Timer]OnCalendar=Sun *-*-* 06:00:00Persistent=true[Install]WantedBy=timers.target updatewp.sh:rm \/root\/latest.tar.gzwget -O \/root\/latest.tar.gz https:\/\/wordpress.org\/latest.tar.gzif ! cmp \/root\/latest.tar.gz &hellip; <a href=\"https:\/\/marshallpdavis.com\/?page_id=213\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Scripts, services, and timers &#8211; OH, MY!<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":211,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-213","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/marshallpdavis.com\/index.php?rest_route=\/wp\/v2\/pages\/213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/marshallpdavis.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/marshallpdavis.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/marshallpdavis.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/marshallpdavis.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=213"}],"version-history":[{"count":1,"href":"https:\/\/marshallpdavis.com\/index.php?rest_route=\/wp\/v2\/pages\/213\/revisions"}],"predecessor-version":[{"id":214,"href":"https:\/\/marshallpdavis.com\/index.php?rest_route=\/wp\/v2\/pages\/213\/revisions\/214"}],"up":[{"embeddable":true,"href":"https:\/\/marshallpdavis.com\/index.php?rest_route=\/wp\/v2\/pages\/211"}],"wp:attachment":[{"href":"https:\/\/marshallpdavis.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}