@@ -19,6 +19,8 @@ NODE_ROLE="${NODE_ROLE:-instance}"
1919REGISTRY_URL=" ${REGISTRY_URL:- } "
2020REGISTRY_AUTH=" ${REGISTRY_AUTH:- } "
2121TOMATO_VERSION=" ${TOMATO_VERSION:- 1.0.0} "
22+ LOKI_URL=" ${LOKI_URL:- } "
23+ LOKI_PUSH_TOKEN=" ${LOKI_PUSH_TOKEN:- } "
2224
2325RED=' \033[0;31m'
2426GREEN=' \033[0;32m'
301303
302304install_completions () {
303305 local bin=" $1 "
304- local shell_name
305306
306307 # bash
307308 if command -v bash & > /dev/null; then
@@ -450,6 +451,63 @@ dployrd ALL=(ALL) NOPASSWD: $docker *
450451EOF
451452}
452453
454+ render_vector_config_node () {
455+ local loki_url=" $1 " push_token=" $2 " instance_tag=" $3 "
456+ cat << EOF
457+ [api]
458+ enabled = true
459+ address = "127.0.0.1:8686"
460+
461+ [sources.docker_logs]
462+ type = "docker_logs"
463+
464+ [sinks.loki]
465+ type = "loki"
466+ inputs = ["docker_logs"]
467+ endpoint = "${loki_url} "
468+ encoding.codec = "json"
469+
470+ [sinks.loki.auth]
471+ strategy = "bearer"
472+ token = "${push_token} "
473+
474+ [sinks.loki.labels]
475+ host = "${instance_tag} "
476+ container = "{{ container_name }}"
477+ serviceId = "{{ container_name }}"
478+ source = "dployrd"
479+ EOF
480+ }
481+
482+ setup_vector () {
483+ [[ -z " $LOKI_URL " || -z " $LOKI_PUSH_TOKEN " ]] && return
484+
485+ if ! command -v vector > /dev/null 2>&1 ; then
486+ info " Installing Vector..."
487+ curl -1sLf ' https://setup.vector.dev' | bash > /dev/null 2>&1
488+ apt-get install -y vector > /dev/null 2>&1
489+ else
490+ info " Vector already installed: $( vector --version 2>&1 | head -1) "
491+ fi
492+ rm -f /etc/vector/vector.yaml
493+ rm -rf /etc/vector/examples
494+
495+ local instance_tag
496+ instance_tag=" $( tomato get ' instance_id' " $CONFIG_FILE " 2> /dev/null || echo " " ) "
497+ [[ -z " $instance_tag " ]] && { warn " instance_id not set in config — Vector not configured" ; return ; }
498+
499+ mkdir -p /etc/vector
500+ render_vector_config_node " $LOKI_URL " " $LOKI_PUSH_TOKEN " " $instance_tag " > /etc/vector/vector.toml
501+ echo ' VECTOR_CONFIG=/etc/vector/vector.toml' > /etc/default/vector
502+
503+ usermod -aG docker vector > /dev/null 2>&1 || true
504+
505+ systemctl daemon-reload
506+ systemctl enable vector > /dev/null 2>&1
507+ systemctl restart vector
508+ info " Vector configured → ${LOKI_URL} "
509+ }
510+
453511main () {
454512 local START_TIME
455513 START_TIME=$( date +%s)
@@ -530,6 +588,16 @@ main() {
530588 REGISTRY_AUTH=" $2 "
531589 shift 2
532590 ;;
591+ --loki-url)
592+ [[ -z " $2 " ]] && error " Missing value for $1 "
593+ LOKI_URL=" $2 "
594+ shift 2
595+ ;;
596+ --loki-push-token)
597+ [[ -z " $2 " ]] && error " Missing value for $1 "
598+ LOKI_PUSH_TOKEN=" $2 "
599+ shift 2
600+ ;;
533601 -h|--help)
534602 show_help
535603 exit 0
918986 info " dployrd service started"
919987
920988 [[ -n " $TOKEN " ]] && { sleep 1; register_instance " $TOKEN " || true ; }
989+
990+ setup_vector
921991 ;;
922992 darwin)
923993 if ! dscl . -read /Users/_dployrd & > /dev/null; then
0 commit comments