| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | #!/bin/bash
 | 
					
						
							| 
									
										
										
										
											2017-06-20 00:30:06 +03:00
										 |  |  | # Using `+e` so that all checks are run and we get a complete report (even if some checks failed). | 
					
						
							|  |  |  | set +e -u -o pipefail | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Variables | 
					
						
							|  |  |  | exitCode=0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Helpers | 
					
						
							| 
									
										
										
										
											2020-05-02 16:14:09 +03:00
										 |  |  | function checkCert { | 
					
						
							|  |  |  |   local certPath=$1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if [[ ! -f "$certPath" ]]; then | 
					
						
							|  |  |  |     echo "Certificate '$certPath' does not exist. Skipping expiration check..." | 
					
						
							|  |  |  |     return | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   openssl x509 -checkend 0 -in "$certPath" -noout > /dev/null | 
					
						
							|  |  |  |   reportStatus "Certificate '$certPath'" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if [[ $? -ne 0 ]]; then | 
					
						
							|  |  |  |     echo "  [WARN]" | 
					
						
							|  |  |  |     echo "  If you did not provide the certificate explicitly, try running the" | 
					
						
							|  |  |  |     echo "  'docker build' command again with the '--no-cache' option to generate" | 
					
						
							|  |  |  |     echo "  a new self-signed certificate." | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | function reportStatus { | 
					
						
							|  |  |  |   local lastExitCode=$? | 
					
						
							| 
									
										
										
										
											2020-05-02 16:14:09 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |   echo "$1: $([[ $lastExitCode -eq 0 ]] && echo OK || echo NOT OK)" | 
					
						
							|  |  |  |   [[ $lastExitCode -eq 0 ]] || exitCode=1 | 
					
						
							| 
									
										
										
										
											2020-05-02 16:14:09 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return $lastExitCode | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Check services | 
					
						
							|  |  |  | services=( | 
					
						
							|  |  |  |   rsyslog | 
					
						
							|  |  |  |   cron | 
					
						
							|  |  |  |   nginx | 
					
						
							| 
									
										
										
										
											2017-03-02 00:05:59 +02:00
										 |  |  |   pm2-root | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | for s in ${services[@]}; do | 
					
						
							|  |  |  |   service $s status > /dev/null | 
					
						
							|  |  |  |   reportStatus "Service '$s'" | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-02 16:14:09 +03:00
										 |  |  | # Check SSL/TLS certificates expiration | 
					
						
							|  |  |  | certs=( | 
					
						
							|  |  |  |   "$AIO_LOCALCERTS_DIR/$AIO_DOMAIN_NAME.crt" | 
					
						
							|  |  |  |   "$TEST_AIO_LOCALCERTS_DIR/$TEST_AIO_DOMAIN_NAME.crt" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | for c in ${certs[@]}; do | 
					
						
							|  |  |  |   checkCert $c | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | # Check servers | 
					
						
							|  |  |  | origins=( | 
					
						
							| 
									
										
										
										
											2018-08-15 13:47:45 +01:00
										 |  |  |   http://$AIO_PREVIEW_SERVER_HOSTNAME:$AIO_PREVIEW_SERVER_PORT | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |   http://$AIO_NGINX_HOSTNAME:$AIO_NGINX_PORT_HTTP | 
					
						
							|  |  |  |   https://$AIO_NGINX_HOSTNAME:$AIO_NGINX_PORT_HTTPS | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | for o in ${origins[@]}; do | 
					
						
							|  |  |  |   curl --fail --silent $o/health-check > /dev/null | 
					
						
							|  |  |  |   reportStatus "Server '$o'" | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-27 11:38:22 +02:00
										 |  |  | # Check resolution of external URLs | 
					
						
							|  |  |  | origins=( | 
					
						
							|  |  |  |   https://google.com | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | for o in ${origins[@]}; do | 
					
						
							|  |  |  |   curl --fail --silent $o > /dev/null | 
					
						
							|  |  |  |   reportStatus "External URL '$o'" | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | # Exit | 
					
						
							|  |  |  | exit $exitCode |