diff --git a/scripts/deb/post-install.sh b/scripts/deb/post-install.sh index f146b7bcd902d..e9a86e862970e 100644 --- a/scripts/deb/post-install.sh +++ b/scripts/deb/post-install.sh @@ -289,8 +289,9 @@ if pidof dockerd >/dev/null 2>&1; then if getent group docker >/dev/null 2>&1; then usermod -aG docker telegraf else - if [[ -e "/var/run/docker.sock" ]]; then - setfacl -m g:telegraf:rw /var/run/docker.sock + sockf=$(netstat -axp | grep docker.sock | awk '{print $NF}' | tail -n 1) + if [[ -e "$sockf" ]]; then + setfacl -m g:telegraf:rw $sockf else echo "Warn - no docker user or setfacl error" echo "Warn - need add telegraf user to read docker unix group(eg: /var/run/docker.sock)" diff --git a/scripts/rpm/post-install.sh b/scripts/rpm/post-install.sh index c6ec24605b9fa..ea6adaf30a175 100644 --- a/scripts/rpm/post-install.sh +++ b/scripts/rpm/post-install.sh @@ -297,8 +297,9 @@ if pidof dockerd >/dev/null 2>&1; then if getent group docker >/dev/null 2>&1; then usermod -aG docker telegraf else - if [[ -e "/var/run/docker.sock" ]]; then - setfacl -m g:telegraf:rw /var/run/docker.sock + sockf=$(netstat -axp | grep docker.sock | awk '{print $NF}' | tail -n 1) + if [[ -e "$sockf" ]]; then + setfacl -m g:telegraf:rw $sockf else echo "Warn - no docker user or setfacl error" echo "Warn - need add telegraf user to read docker unix group(eg: /var/run/docker.sock)" diff --git a/scripts/telegraf-discover b/scripts/telegraf-discover index 09a5e31235547..7b15004637d49 100755 --- a/scripts/telegraf-discover +++ b/scripts/telegraf-discover @@ -207,6 +207,10 @@ else { } my $disconf = Disconf->new( (update => $update, force => $force_overwrite) ); + +# hook actions before running +$disconf->pre_check(); + my $results = $disconf->get_server_list(); my $sects = Utils::parsecfg($discover); $| = 1; # enforce flush for print @@ -1671,6 +1675,14 @@ sub new { return bless $self, $class; } +sub pre_check { + my $self = shift; + if ($self->is_support("docker")) { + perm_docker(); + } + # ...... +} + sub is_support { my $self = shift; my $type = shift; @@ -1815,8 +1827,8 @@ sub get_server_list { return \%results; } -sub _perm_docker { - my $sockf = shift; +sub perm_docker { + my $sockf = shift || _find_docker_sock(); my $id = getgrnam("docker"); if (defined $id and $id > 0) { @@ -1836,6 +1848,7 @@ sub _perm_docker { Utils::time_print("error - setfacl to $sockf error! high: $high, low: $low"); } else { + Utils::time_print("setfacl to $sockf ok"); return 1; } } @@ -1848,7 +1861,7 @@ sub _replace_docker { my $temp = shift; my $sockf = shift; - if (-e $sockf && _perm_docker($sockf)) { + if (-e $sockf && perm_docker($sockf)) { my $socks = "unix://$sockf"; $temp =~ s/docker_sock_path/$socks/g; } @@ -1859,6 +1872,13 @@ sub _replace_docker { return $temp; } +sub _find_docker_sock { + my $cmd = "netstat -axp | grep docker.sock | awk '{print \$NF}' | tail -n 1"; + my $res = Utils::exec_cmd_return("$cmd") || ''; + + return $res; +} + sub disc_docker { my $self = shift; my $secs = shift; @@ -1904,7 +1924,7 @@ sub disc_docker { tag_env = ["JAVA_HOME", "HEAP_SIZE"] TEMP_END - return _replace_docker($temp, "/var/run/docker.sock") + return _replace_docker($temp, _find_docker_sock()); } sub disc_iptables {