import { copyFile } from "node:fs/promises"; import { Alpine } from "../../alpine.js"; import { Runit } from "../../runit/index.js"; import { buildLoki } from "./build.js"; export async function setupLoki(alpine: Alpine, runit: Runit): Promise { const bin = await buildLoki(); await copyFile(bin, alpine.path("/usr/local/bin/loki")); const user = await alpine.userAdd("loki"); // TODO: data // await alpine.fstab.addTmpfs("/var/lib/grafana", { // uid: user.uid, // gid: user.gid, // mode: "700", // }); const configPath = "/etc/loki/loki-local-config.yaml"; await alpine.writeFile( configPath, ` auth_enabled: false server: http_listen_port: 3100 http_listen_address: 127.0.0.1 # grpc_listen_port: 9096 grpc_listen_address: 127.0.0.1 common: instance_addr: 127.0.0.1 path_prefix: /tmp/loki storage: filesystem: chunks_directory: /tmp/loki/chunks rules_directory: /tmp/loki/rules replication_factor: 1 ring: kvstore: store: inmemory query_range: results_cache: cache: embedded_cache: enabled: true max_size_mb: 100 schema_config: configs: - from: 2020-10-24 store: boltdb-shipper object_store: filesystem schema: v11 index: prefix: index_ period: 24h # ruler: # alertmanager_url: http://localhost:9093 analytics: reporting_enabled: false`, user ); // await alpine.sudoWriteExecutable( // "/usr/local/sbin/nulo-grafana-cli", // `#!/bin/sh // cd / // exec chpst -u grafana:grafana grafana-cli --homepath /usr/share/grafana --config /etc/grafana.ini "$@"` // ); await runit.addService( "loki", `#!/bin/sh exec chpst -u ${user.name}:${user.name} /usr/local/bin/loki -config.file='${configPath}' ` ); }