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