Add systemd service/timer
This commit is contained in:
14
server-pages.service
Normal file
14
server-pages.service
Normal file
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=Update server page statuses
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/sh -c 'node /home/kevin/server-pages/server-status.js > /home/kevin/my-site/public/server-apps.json'
|
||||
User=kevin
|
||||
Group=kevin
|
||||
Environment=PATH=/usr/bin:/usr/local/bin
|
||||
Environment=NODE_ENV=production
|
||||
WorkingDirectory=/home/kevin/server-pages
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
9
server-pages.timer
Normal file
9
server-pages.timer
Normal file
@@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Update server page statuses
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*:0
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
@@ -2,19 +2,17 @@ const urlMetadata = require('url-metadata')
|
||||
const csv = require('csvtojson')
|
||||
const log = console.log
|
||||
const { spawnSync } = require( 'child_process' ),
|
||||
// uptime = spawnSync( 'uptime', [ '-p' ] )
|
||||
uptime = spawnSync( 'uptime', [ '-s' ] )
|
||||
|
||||
const csvFilePath = 'server-pages.csv'
|
||||
// const csvFilePath = 'server-pages-test.csv'
|
||||
|
||||
// consider webpage to be up if stored title matches fetched title
|
||||
const checkIfTitleMatches = obj => {
|
||||
return urlMetadata(obj['url']).then(metadata => { // success handler
|
||||
if (metadata.title == obj['siteTitle']) {
|
||||
// log(obj['shortUrl'])
|
||||
obj['status'] = 'up'
|
||||
} else {
|
||||
// console.log(metadata)
|
||||
obj['status'] = 'down'
|
||||
}
|
||||
return true
|
||||
@@ -24,6 +22,7 @@ const checkIfTitleMatches = obj => {
|
||||
})
|
||||
}
|
||||
|
||||
// update all sites' status in JSON
|
||||
const updateSiteStatus = json => {
|
||||
const promiseArray = []
|
||||
json.forEach(async function (obj) {
|
||||
@@ -37,6 +36,7 @@ const updateSiteStatus = json => {
|
||||
}
|
||||
|
||||
csv().fromFile(csvFilePath).then(async function (json) {
|
||||
// finish updating all sites' status before outputting JSON
|
||||
Promise.all(updateSiteStatus(json)).then(results => {
|
||||
const statusJson = {
|
||||
"sites": json,
|
||||
|
||||
Reference in New Issue
Block a user