pinafore/bin/run-mastodon.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

import { restoreMastodonData } from './restore-mastodon-data.js'
2018-03-06 04:51:42 +00:00
import childProcessPromise from 'child-process-promise'
import fs from 'fs'
import { waitForMastodonUiToStart, waitForMastodonApiToStart } from './wait-for-mastodon-to-start.js'
import cloneMastodon from './clone-mastodon.js'
import installMastodon from './install-mastodon.js'
import { mastodonDir, env } from './mastodon-config.js'
2018-03-06 04:51:42 +00:00
const spawn = childProcessPromise.spawn
let childProc
2018-02-18 23:30:42 +00:00
async function runMastodon () {
console.log('Running mastodon...')
2019-08-03 20:49:37 +00:00
const cwd = mastodonDir
const promise = spawn('foreman', ['start'], { cwd, env })
// don't bother writing to mastodon.log in CI; we can't read the file anyway
const logFile = process.env.CI ? '/dev/null' : 'mastodon.log'
const log = fs.createWriteStream(logFile, { flags: 'a' })
childProc = promise.childProcess
childProc.stdout.pipe(log)
childProc.stderr.pipe(log)
2018-04-11 02:43:36 +00:00
promise.catch(err => {
console.error('foreman start failed, see mastodon.log for details')
console.error(err)
shutdownMastodon()
process.exit(1)
})
2018-02-18 18:42:27 +00:00
}
2018-02-18 23:30:42 +00:00
async function main () {
await cloneMastodon()
await installMastodon()
await runMastodon()
2018-03-06 05:21:28 +00:00
await waitForMastodonApiToStart()
2018-03-06 17:04:09 +00:00
await restoreMastodonData()
2018-03-06 05:58:29 +00:00
await waitForMastodonUiToStart()
}
2018-03-07 07:57:06 +00:00
function shutdownMastodon () {
if (childProc) {
console.log('killing child process')
childProc.kill()
}
2018-03-06 17:03:59 +00:00
}
process.on('SIGINT', function () {
shutdownMastodon()
process.exit(0)
})
2018-02-18 18:42:27 +00:00
main().catch(err => {
console.error(err)
2018-03-06 17:03:59 +00:00
shutdownMastodon()
2018-02-18 18:42:27 +00:00
process.exit(1)
})