Prima che starter-core possa tenere history e labels serve un database MariaDB o MySQL. Questo tutorial installa il server per la tua distribuzione, crea lo schema e punta il Core con gsettings.

Dovresti già avere i pacchetti installati — vedi Installazione da sorgente se non l’hai ancora fatto.

1. Installare il server

Scegli la famiglia di distribuzione. Quando il server è in esecuzione, continua con i passi SQL sotto (sono uguali ovunque).

Debian, Ubuntu e derivati free software come Trisquel e PureOS (apt).

sudo apt update
sudo apt install --no-install-recommends mariadb-server
sudo systemctl enable --now mariadb
sudo systemctl status mariadb --no-pager

Va bene anche default-mysql-server se preferisci MySQL. Shell SQL di root:

sudo mysql

2. Creare utente e schema STARTER

Nella shell SQL di root dalla tab della tua distro, crea il database e un utente dedicato. Sostituisci la password con un tuo segreto:

CREATE DATABASE STARTER
  CHARACTER SET utf8mb4
  COLLATE utf8mb4_unicode_ci;

CREATE USER 'starter'@'localhost' IDENTIFIED BY 'change-me';
GRANT ALL PRIVILEGES ON STARTER.* TO 'starter'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Se il Core si collegherà da un altro host, crea un utente per quel host (o '%' con cautela) e apri il server di conseguenza. Per una prima installazione locale basta localhost.

3. Creare le tabelle

Il Core si aspetta almeno tre tabelle: labels, history e stats. Applicale come utente starter (o come root su STARTER):

mysql -u starter -p STARTER <<'SQL'
CREATE TABLE labels (
    id INT NOT NULL AUTO_INCREMENT,
    name VARCHAR(100) NOT NULL UNIQUE,
    description TEXT NOT NULL,
    type VARCHAR(50) NOT NULL,
    unit INT NOT NULL,
    min DOUBLE NOT NULL,
    max DOUBLE NOT NULL,
    step DOUBLE NOT NULL,
    PRIMARY KEY (id),
    INDEX idx_labels_type (type)
);

CREATE TABLE history (
    id BIGINT NOT NULL AUTO_INCREMENT,
    timestamp DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    source VARCHAR(100) NOT NULL,
    label_id INT NOT NULL,
    value DOUBLE NOT NULL,
    flags BIGINT UNSIGNED NOT NULL,
    PRIMARY KEY (id),
    FOREIGN KEY (label_id) REFERENCES labels(id),
    INDEX idx_label_time (label_id, timestamp),
    INDEX idx_history_source (source)
);

CREATE TABLE stats (
    id                INTEGER PRIMARY KEY AUTO_INCREMENT,
    service_name      VARCHAR(100) NOT NULL UNIQUE,
    updated_at        TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,

    vmsize_min        REAL NOT NULL,
    vmsize_max        REAL NOT NULL,
    vmsize_last       REAL NOT NULL,

    vmrss_min         REAL NOT NULL,
    vmrss_max         REAL NOT NULL,
    vmrss_last        REAL NOT NULL,

    vmswap_min        REAL NOT NULL,
    vmswap_max        REAL NOT NULL,
    vmswap_last       REAL NOT NULL,

    io_read_min       REAL NOT NULL,
    io_read_max       REAL NOT NULL,
    io_read_last      REAL NOT NULL,

    io_write_min      REAL NOT NULL,
    io_write_max      REAL NOT NULL,
    io_write_last     REAL NOT NULL,

    cpu_min           REAL NOT NULL,
    cpu_max           REAL NOT NULL,
    cpu_last          REAL NOT NULL,

    icswitch_min      REAL NOT NULL,
    icswitch_max      REAL NOT NULL,
    icswitch_last     REAL NOT NULL,

    priority_min      REAL NOT NULL,
    priority_max      REAL NOT NULL,
    priority_last     REAL NOT NULL,

    threads_min       REAL NOT NULL,
    threads_max       REAL NOT NULL,
    threads_last      REAL NOT NULL,
    INDEX idx_service_name (service_name)
);
SQL

Verifica:

mysql -u starter -p -e 'SHOW TABLES FROM STARTER;'

Dovresti vedere history, labels e stats.

4. Puntare starter-core al database

Il Core legge la connessione da GSettings sotto org.starter.core (i flag --db-* in riga di comando li sovrascrivono se serve un one-off).

gsettings set org.starter.core db-host '127.0.0.1'
gsettings set org.starter.core db-port 3306
gsettings set org.starter.core db-user 'starter'
gsettings set org.starter.core db-pass 'change-me'
gsettings set org.starter.core db-name 'STARTER'

Usa la stessa password impostata in SQL. Opzionale ma consigliato in un impianto reale:

# Auth peer (vuoto = aperto; metti un segreto condiviso quando indurisci l’impianto)
gsettings set org.starter.core auth-token ''
# Segreto del canale debug (indipendente dall’auth peer)
gsettings set org.starter.core debug-auth-token ''

Verifica le chiavi:

gsettings list-recursively org.starter.core | grep '^org.starter.core db-'

Se gsettings non trova lo schema, assicurati che starter-core sia installato e che gli schema siano compilati (un make install normale del core esegue glib-compile-schemas).

5. Controllo rapido di connessione

Con starter-db dagli addons (se l’hai installato):

starter-db --host 127.0.0.1 --port 3306 \
  --user starter --password 'change-me' --database STARTER \
  -c 'SHOW TABLES;'

Oppure con il client MySQL:

mysql -h 127.0.0.1 -P 3306 -u starter -p STARTER -e 'SELECT COUNT(*) FROM labels;'

Quando funziona, il Core può usare il database. Poi: abilita e avvia starter-core, collega i peer — vedi Documentazione e altri tutorial.

6. Risoluzione problemi

Sintomo Cosa controllare
Access denied for user Password, host (localhost vs 127.0.0.1) e GRANT su STARTER.*.
Unknown database 'STARTER' Riesegui CREATE DATABASE; controlla db-name in gsettings.
Il Core parte ma non c’è history L’utente deve poter scrivere; verifica le tabelle; guarda i log del Core.
Schema gsettings mancante Reinstalla il core; esegui sudo glib-compile-schemas /usr/local/share/glib-2.0/schemas (o il tuo prefisso).
Guix: servizio non trovato Aggiungi (service mysql-service-type) e guix system reconfigure; poi herd start mysql.

Se resti bloccato, chiedi sul forum con un estratto SQL o del log del Core (senza password).