A simple, powerful CLI tool to spin up OpenIndiana virtual machines with QEMU
at main 43 lines 1.1 kB view raw
1import _ from "@es-toolkit/es-toolkit/compat"; 2import chalk from "chalk"; 3import { getInstanceState, updateInstanceState } from "../state.ts"; 4 5export default async function (name: string) { 6 const vm = await getInstanceState(name); 7 if (!vm) { 8 console.error( 9 `Virtual machine with name or ID ${chalk.greenBright(name)} not found.`, 10 ); 11 Deno.exit(1); 12 } 13 14 console.log( 15 `Stopping virtual machine ${chalk.greenBright(vm.name)} (ID: ${ 16 chalk.greenBright(vm.id) 17 })...`, 18 ); 19 20 const cmd = new Deno.Command(vm.bridge ? "sudo" : "kill", { 21 args: [ 22 ..._.compact([vm.bridge && "kill"]), 23 "-TERM", 24 vm.pid.toString(), 25 ], 26 stdin: "inherit", 27 stdout: "inherit", 28 stderr: "inherit", 29 }); 30 31 const status = await cmd.spawn().status; 32 33 if (!status.success) { 34 console.error( 35 `Failed to stop virtual machine ${chalk.greenBright(vm.name)}.`, 36 ); 37 Deno.exit(status.code); 38 } 39 40 await updateInstanceState(vm.name, "STOPPED"); 41 42 console.log(`Virtual machine ${chalk.greenBright(vm.name)} stopped.`); 43}