server: git-serve fixups

This commit is contained in:
Koushik Dutta
2021-10-20 01:10:08 -07:00
parent a89d578ef9
commit 9d870a4086

View File

@@ -10,17 +10,19 @@ async function sleep(ms: number) {
const EXIT_FILE = '.exit';
const UPDATE_FILE = '.update';
async function runCommand(command: string) {
const cp = child_process.exec(command);
async function runCommand(command: string, ...args: string[]) {
const cp = child_process.spawn(command, args, {
stdio: 'inherit'
});
await once(cp, 'exit');
}
async function runCommandEatError(command: string) {
async function runCommandEatError(command: string, ...args: string[]) {
try {
await runCommand(command);
await runCommand(command, ...args);
}
catch (e) {
console.warn(command, 'command exited with error, ignoring', e)
console.warn(command, args, 'command exited with error, ignoring', e)
}
}
@@ -31,7 +33,7 @@ async function main() {
try {
console.log('starting scrypted main...');
await runCommand('npm run serve-no-build')
await runCommand('npm', 'run', 'serve-no-build')
}
catch (e) {
console.error('scrypted server exited with error', e);
@@ -44,14 +46,14 @@ async function main() {
if (fs.existsSync(UPDATE_FILE)) {
console.log(`${UPDATE_FILE} found. pulling and rebuilding.`);
await runCommandEatError('git reset --hard');
await runCommandEatError('git pull');
await runCommandEatError('npm install');
await runCommandEatError('npm run build');
await runCommandEatError('git', 'reset', '--hard');
await runCommandEatError('git', 'pull');
await runCommandEatError('npm', 'install');
await runCommandEatError('npm', 'run', 'build');
}
console.log(`${EXIT_FILE} not found. restarting momentarily.`);
sleep(10000);
await sleep(10000);
}
}