Last active 1700047249

a script to touch/rm a file based on ping result, and an nginx conf

offline-check.sh Raw
1#!/bin/bash
2# offline-check [ip number of host]
3# e.g `offline-check 2` generates /var/www/html/offline.check.2
4# example crontab: * * * * * $HOME/.local/bin/offline-check
5ping -w1 -c1 10.8.0.$1 | grep "64 bytes from" 2>&1 >/dev/null && rm -f /var/www/html/offline.check.$1 2>/dev/null || touch /var/www/html/offline.check.$1
offline.html Raw
1<!-- /var/www/html/offline.html -->
2<!doctype html>
3<html>
4<head>
5 <title>Site Maintenance</title>
6
7 <link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet"/>
8 <meta content="width=device-width, initial-scale=1" name="viewport" />
9 <style>
10 body {
11 text-align: center;
12 font-family: "Poppins", sans-serif;
13 color: #0C1231;
14 }
15
16 .logo {
17 margin-top: 3rem;
18 max-height: 35px;
19 width: auto;
20 }
21
22 .content {
23 margin: 0 auto;
24 max-width: 1000px;
25 width: 90%;
26 }
27
28 .info {
29 margin: 0 auto;
30 margin-top: 3rem;
31 max-width: 500px;
32 }
33
34 h1 {
35 font-weight: 600;
36 font-size: 1.8rem;
37 }
38
39 .image-main {
40 margin-top: 3rem;
41 max-width: 90%;
42 }
43
44 hr {
45 border: 1px solid rgba(0, 0, 0, 0.08);
46
47 margin: 0 auto;
48 margin-top: 2rem;
49 margin-bottom: 1rem;
50 max-width: 90%;
51 }
52
53 a {
54 text-decoration: none;
55 color: #535353
56 }
57
58 a:hover {
59 color: #0C1231;
60 }
61
62 @media (min-width: 968px) {
63 .logo {
64 max-height: 45px;
65 }
66
67 h1 {
68 font-size: 2.5rem;
69 }
70
71 .info {
72 margin-top: 6rem;
73 }
74
75 hr {
76 margin-top: 6rem;
77 margin-bottom: 3rem;
78 }
79 }
80 </style>
81</head>
82
83<body>
84 <div class="content">
85 <div class="info">
86 <h1>Down for maintenance</h1>
87 <p>Nothing here right now. Check back later!</p>
88 </div>
89 <img class="image-main" src="https://sfiles.aly.pet/0uJkCM8.png" alt="Maintenance image">
90 </div>
91</body>
92</html>
93
snippets-offline.nginxconf Raw
1# server { include /etc/nginx/snippets/offline.conf; }
2error_page 502 503 @offline;
3location @offline {
4 root /var/www/html;
5 rewrite ^(.*)$ /offline.html break;
6}
snippets-offlineloc.nginxconf Raw
1# location { include /etc/nginx/snippets/offlineloc.conf; }
2# change the number after offline.check. to the ip number of the dest server on the vpn
3 if (-f /var/www/html/offline.check.2) {
4 return 503;
5 }
6# proxy_pass http://10.8.0.2:1234/;