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