From fbb1944c97627876d52a60c3fb2c5c4fe2c9616f Mon Sep 17 00:00:00 2001 From: Jan Pavlinec Date: Tue, 8 Oct 2019 18:03:20 +0200 Subject: [PATCH 1/2] atlas-probe: fix version file name --- net/atlas-probe/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/atlas-probe/Makefile b/net/atlas-probe/Makefile index bf0706ad4..5b5eb625f 100644 --- a/net/atlas-probe/Makefile +++ b/net/atlas-probe/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=atlas-probe PKG_VERSION:=2.0.0 -PKG_RELEASE=1 +PKG_RELEASE=2 PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://github.com/RIPE-NCC/ripe-atlas-probe-busybox.git @@ -59,7 +59,7 @@ define Package/atlas-probe/install $(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \ $(MAKE_FLAGS) CONFIG_PREFIX=$(1)/usr/libexec/atlas-probe install $(INSTALL_DIR) $(1)/usr/libexec/atlas-probe/state - echo $(PKG_VERSION) > $(1)/usr/libexec/atlas-probe/state/FIRMWARE_APPS_VERSION + echo $(PKG_VERSION) > $(1)/usr/libexec/atlas-probe/state/VERSION endef $(eval $(call BuildPackage,atlas-probe)) -- GitLab From 2295c05d3967afcc1cf6749039a60b1f17f1610f Mon Sep 17 00:00:00 2001 From: Jan Pavlinec Date: Tue, 8 Oct 2019 18:03:49 +0200 Subject: [PATCH 2/2] atlas-sw-probe: add new package --- net/atlas-probe/Makefile | 2 +- net/atlas-sw-probe/Makefile | 102 +++++++++++++++ net/atlas-sw-probe/files/atlas.conf | 4 + net/atlas-sw-probe/files/atlas.init | 122 ++++++++++++++++++ .../patches/001-fix-config-path.patch | 14 ++ 5 files changed, 243 insertions(+), 1 deletion(-) create mode 100644 net/atlas-sw-probe/Makefile create mode 100644 net/atlas-sw-probe/files/atlas.conf create mode 100644 net/atlas-sw-probe/files/atlas.init create mode 100644 net/atlas-sw-probe/patches/001-fix-config-path.patch diff --git a/net/atlas-probe/Makefile b/net/atlas-probe/Makefile index 5b5eb625f..77d3884ed 100644 --- a/net/atlas-probe/Makefile +++ b/net/atlas-probe/Makefile @@ -1,5 +1,5 @@ # -# Copyright (C) 2018 CZ.NIC +# Copyright (C) 2019 CZ.NIC z.s.p.o. (https://www.nic.cz/) # # This is free software, licensed under the GNU General Public License v2. # See /LICENSE for more information. diff --git a/net/atlas-sw-probe/Makefile b/net/atlas-sw-probe/Makefile new file mode 100644 index 000000000..bee2bc9a8 --- /dev/null +++ b/net/atlas-sw-probe/Makefile @@ -0,0 +1,102 @@ +# +# Copyright (C) 2019 CZ.NIC z.s.p.o. (https://www.nic.cz/) +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# +include $(TOPDIR)/rules.mk + +PKG_NAME:=atlas-sw-probe +PKG_VERSION:=1.0.0 +PKG_RELEASE:=1 + +PKG_SOURCE_PROTO:=git +PKG_SOURCE_URL:=https://gitlab.labs.nic.cz/turris/ripe-atlas-software-probe +PKG_SOURCE_VERSION:=ffbf0d77cd8124a568175c0b3d1004c0b1b803e1 +PKG_SOURCE:=ripe-atlas-software-probe-$(PKG_VERSION).tar.gz + +PKG_MAINTAINER:=CZ.NIC +PKG_LICENSE:=GPL-3.0-or-later +PKG_LICENSE_FILES:=LICENSE + +PKG_INSTALL:=1 + +include $(INCLUDE_DIR)/package.mk + +define Package/atlas-sw-probe + SECTION:=net + CATEGORY:=Network + TITLE:=RIPE Atlas software probe + URL:=https://atlas.ripe.net/about/probes/ + DEPENDS:=+atlas-probe +endef + +define Package/atlas-sw-probe/description + RIPE Atlas SW probe is software variant of RIPE Atlas Probe. + It contains utilities which helps actively measure + Internet connectivity through ping, traceroute, DNS, SSL/TLS, NTP, and HTTP. + Data are then collected, aggregated and published by the RIPE NCC. +endef + +define Build/Compile + true +endef + +define Build/Install + true +endef + +define Package/atlas-sw-probe/postinst + true +endef + +define Package/atlas-sw-probe/conffiles +/etc/config/atlas +/usr/libexec/atlas-probe-scripts/state/config.txt +endef + +TMP_BASE_DIR:=/tmp/ripe_atlas_probe +SCRIPTS_DIR:=/usr/libexec/atlas-probe-scripts + +define Package/atlas-sw-probe/install + $(INSTALL_DIR) $(1)/$(SCRIPTS_DIR) + $(INSTALL_DIR) $(1)/$(SCRIPTS_DIR)/{etc,state,bin/arch,bin/bin} + + # Copy config + $(CP) $(PKG_BUILD_DIR)/atlas-config/etc/* $(1)/$(SCRIPTS_DIR)/etc/ + + # Copy firmware version + $(CP) $(PKG_BUILD_DIR)/atlas-config/state/FIRMWARE_APPS_VERSION $(1)/$(SCRIPTS_DIR)/state/ + # Set probe mode + echo "prod" > $(1)/$(SCRIPTS_DIR)/state/mode + + # Copy scripts + $(CP) $(PKG_BUILD_DIR)/bin/{ATLAS,common-pre.sh,common.sh,reginit.sh,resolvconf} $(1)/$(SCRIPTS_DIR)/bin/ + $(CP) $(PKG_BUILD_DIR)/bin/arch/{linux,turris-sw-probe} $(1)/$(SCRIPTS_DIR)/bin/arch/ + + # Create config info + echo "DEVICE_NAME=turris-sw-probe" > $(1)/$(SCRIPTS_DIR)/bin/config.sh + echo "ATLAS_BASE=$(SCRIPTS_DIR)" >> $(1)/$(SCRIPTS_DIR)/bin/config.sh + echo "SUB_ARCH=turris-$(ARCH)-$(PKG_VERSION)-$(PKG_RELEASE)" >> $(1)/$(SCRIPTS_DIR)/bin/bin/config.sh + + # Enable sending interface traffic statistics as Atlas measurement results + echo "RXTXRPT=yes" > $(1)/$(SCRIPTS_DIR)/state/config.txt + + # Fix permision + chmod 755 $(1)/$(SCRIPTS_DIR)/bin + + # Create softlinks for writable dirs + $(LN) $(TMP_BASE_DIR)/crons $(1)/$(SCRIPTS_DIR)/crons + $(LN) $(TMP_BASE_DIR)/data $(1)/$(SCRIPTS_DIR)/data + $(LN) $(TMP_BASE_DIR)/run $(1)/$(SCRIPTS_DIR)/run + $(LN) $(TMP_BASE_DIR)/status $(1)/$(SCRIPTS_DIR)/status + + # Copy init and config + $(INSTALL_DIR) $(1)/etc/init.d/ + $(INSTALL_BIN) ./files/atlas.init $(1)/etc/init.d/atlas + + $(INSTALL_DIR) $(1)/etc/config/ + $(CP) ./files/atlas.conf $(1)/etc/config/atlas +endef + +$(eval $(call BuildPackage,atlas-sw-probe)) diff --git a/net/atlas-sw-probe/files/atlas.conf b/net/atlas-sw-probe/files/atlas.conf new file mode 100644 index 000000000..d2a12a523 --- /dev/null +++ b/net/atlas-sw-probe/files/atlas.conf @@ -0,0 +1,4 @@ +config atlas 'common' + option log_stderr '1' + option log_stdout '0' + option rxtxrpt '1' diff --git a/net/atlas-sw-probe/files/atlas.init b/net/atlas-sw-probe/files/atlas.init new file mode 100644 index 000000000..ca124dcfc --- /dev/null +++ b/net/atlas-sw-probe/files/atlas.init @@ -0,0 +1,122 @@ +#!/bin/sh /etc/rc.common + +USE_PROCD=1 +START=30 +EXTRA_COMMANDS="get_key probeid log" +EXTRA_HELP=" get_key print probe public key (used for probe registration) + probeid print probe id + log print probe status log +" + +SCRIPTS_DIR="/usr/libexec/atlas-probe-scripts" +TMP_BASE_DIR="/tmp/ripe_atlas_probe" +PUB_KEY_FILE="$SCRIPTS_DIR/etc/probe_key.pub" +PROBE_ID_FILE="$TMP_BASE_DIR/status/reg_init_reply.txt" +LOG_FILE="/tmp/log/ripe_sw_probe" +STATE_CONFIG="$SCRIPTS_DIR/state/config.txt" + +log() { + if [ -f "$LOG_FILE" ];then + tail "$LOG_FILE" + else + print_msg "Error. No log file found. Probe isn't probably running" + exit 1 + fi +} + +get_key() { + if [ -f "$PUB_KEY_FILE" ]; then + echo "Probe public key (use for registration)" + echo "==========================================" + cat "$PUB_KEY_FILE" + else + print_msg "Error! Pub. key not found" + exit 1 + fi +} + +probeid() { + if [ -f "$PROBE_ID_FILE" ]; then + probe_id="$(cat "$PROBE_ID_FILE" |grep "PROBE_ID"|awk '{print $2}')" + if [ -z "$probe_id" ]; then + print_msg "Probe ID not found SW probe isn't probably registered yet" + exit 1 + else + print_msg "Probe ID is $probe_id" + fi + else + print_msg "Probe ID not found. SW probe is not running or probe_key isn't registered yet" + exit 1 + fi +} + +print_msg() { + echo "$1" >&2 + logger -t atlas-sw-probe "$1" +} + +stop_service() { + + print_msg "Stopping atlas sw probe" + run_pids="$(ls -1 $SCRIPTS_DIR/run/*.vol 2>/dev/null | wc -l)" + if [ "$run_pids" != "0" ]; then + print_msg "Kill all atlas processes" + kill $(cat $SCRIPTS_DIR/run/*.vol) + fi + + if [ -f "$SCRIPTS_DIR/status/con_keep_pid.vol" ]; then + print_msg "Kill ssh tunnel" + kill "$(cat $SCRIPTS_DIR/status/con_keep_pid.vol)" + fi +} + +safe_mkdir() { + local dir="$1" + if [ -e "$dir" ] && [ ! -d "$dir" -o -L "$dir" ]; then + rm -rf "$dir" + fi + mkdir -p "$dir" + chmod 700 "$dir" + chown root:root "$dir" +} + +create_tmp_dirs() { + local dirs + + chown -R atlas:atlas "$SCRIPTS_DIR/bin" + chmod 755 "$SCRIPTS_DIR/bin" + dirs='crons data run status' + + safe_mkdir "$TMP_BASE_DIR" + for i in $dirs; do + safe_mkdir "$TMP_BASE_DIR/$i" + done +} + +start_service() { + local log_stderr + local log_stdout + local rxtxrpt + local test_setting + + create_tmp_dirs + + config_load atlas + config_get_bool log_stderr "common" log_stderr "0" + config_get_bool log_stdout "common" log_stdout "0" + config_get_bool rxtxrpt "common" rxtxrpt "1" + test_setting=$(grep "^[ ]*RXTXRPT=yes" "$STATE_CONFIG") + + # Decide if we should write to permanent storage + if [ "$rxtxrpt" == "1" ] && [ -z "$test_setting" ]; then + echo "RXTXRPT=yes">$STATE_CONFIG + elif [ "$rxtxrpt" == "0" ] && [ ! -z "$test_setting" ]; then + echo "RXTXRPT=no">$STATE_CONFIG + fi + + procd_open_instance + procd_set_param command "$SCRIPTS_DIR/bin/ATLAS" + procd_set_param stdout "$log_stdout" + procd_set_param stderr "$log_stderr" + procd_close_instance +} diff --git a/net/atlas-sw-probe/patches/001-fix-config-path.patch b/net/atlas-sw-probe/patches/001-fix-config-path.patch new file mode 100644 index 000000000..394f89416 --- /dev/null +++ b/net/atlas-sw-probe/patches/001-fix-config-path.patch @@ -0,0 +1,14 @@ +--- a/bin/ATLAS ++++ b/bin/ATLAS +@@ -8,9 +8,9 @@ + #set -x + + DEVICE_NAME= +-if [ -f bin/config.sh ] ++if [ -f /usr/libexec/atlas-probe-scripts/bin/config.sh ] + then +- . bin/config.sh ++ . /usr/libexec/atlas-probe-scripts/bin/config.sh + export DEVICE_NAME SUB_ARCH + elif [ -f /etc/board.json ] + then -- GitLab