Commit 83806457 authored by Mathias Ettinger's avatar Mathias Ettinger

Update debconf on the collector to only ask question when using dpkg-reconfigure

parent b72c2647
......@@ -31,6 +31,9 @@ configure(){
5)
db_beginblock
db_input high opensand-collector/kibana/port || true
;;
6)
db_input high opensand-collector/chronograf/port || true
db_endblock
;;
*)
......@@ -62,20 +65,34 @@ configure(){
fi
}
reset(){
db_reset opensand-collector/collector/stats/port
db_reset opensand-collector/collector/logs/port
db_reset opensand-collector/elasticsearch/port
db_reset opensand-collector/influxdb/port
db_reset opensand-collector/kibana/port
db_reset opensand-collector/chronograf/port
db_reset opensand-collector/configured
}
unseen(){
db_fset opensand-collector/collector/stats/port seen false
db_fset opensand-collector/collector/logs/port seen false
db_fset opensand-collector/elasticsearch/port seen false
db_fset opensand-collector/influxdb/port seen false
db_fset opensand-collector/kibana/port seen false
db_fset opensand-collector/chronograf/port seen false
}
db_capb backup
if [ "$#" -gt 0 ]; then
if [ "$1" = "configure" ]; then
configure
reset
db_stop
elif [ "$1" = "reconfigure" ]; then
unseen
db_set opensand-collector/configured true
configure
else
usage
......
......@@ -19,7 +19,8 @@ Depends: ${misc:Depends}, python (>= 2.7), python (<<3.0),
logstash (= 1:6.2.4-1),
influxdb (= 1.7.1-1),
elasticsearch (= 6.2.4),
kibana (= 6.2.4)
kibana (= 6.2.4),
chronograf
Provides: opensand-env-plane
Conflicts: opensand-env-plane
Replaces: opensand-env-plane
......
......@@ -20,26 +20,25 @@ set -e
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
create_opensand_db(){
create_influxdb_conf(){
db_get opensand-collector/influxdb/port
INFLUXDB_PORT="${RET}"
echo "Waiting for influxdb starts to accepting requests..."
timeout 120 bash -c "until echo > /dev/tcp/localhost/${INFLUXDB_PORT}; do sleep 0.5; done" > /dev/null 2>&1
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Failed to connect to localhost port ${INFLUXDB_PORT}: Influxdb connection refused"
echo "Please check your connection settings and ensure 'influxd' is running. If so, increasing the 'timeout' in postinst script will solve this issue."
exit $exit_code
fi
curl -i -XPOST http://localhost:${INFLUXDB_PORT}/query --data-urlencode "q=CREATE DATABASE opensand"
CONFIG_FILE="/etc/influxdb/influxdb.conf"
sed -i "/bind-address = \":8086\"/c\ bind-address = \":${INFLUXDB_PORT}\"" "${CONFIG_FILE}"
}
create_influxdb_conf(){
create_chronograf_conf(){
db_get opensand-collector/influxdb/port
INFLUXDB_PORT="${RET}"
CONFIG_FILE="/etc/influxdb/influxdb.conf"
db_get opensand-collector/chronograf/port
CHRONOGRAF_PORT="${RET}"
CONFIG_FILE="/etc/default/chronograf"
sed -i "/bind-address = \":8086\"/c\ bind-address = \":${INFLUXDB_PORT}\"" "${CONFIG_FILE}"
cat << EOF > "${CONFIG_FILE}"
INFLUXDB_URL=http://localhost:${INFLUXDB_PORT}
PORT=${CHRONOGRAF_PORT}
EOF
}
create_kibana_conf(){
......@@ -156,35 +155,62 @@ output {
EOF
}
fail_opensand_db(){
INFLUXDB_PORT="$1"
echo "Failed to connect to local InfluxDB server on port ${INFLUXDB_PORT}"
echo "This may be due to a lack of available memory. Check the status of the influxdb service and restart it."
echo "The database to hold OpenSAND probes could no be created. Please run:"
echo -e "\tcurl -i -XPOST http://localhost:${INFLUXDB_PORT}/query --data-urlencode \"q=CREATE DATABASE opensand\""
echo "once the problem is solved to create it."
}
create_opensand_db(){
db_get opensand-collector/influxdb/port
INFLUXDB_PORT="${RET}"
echo "Waiting for influxdb starts to accepting requests..."
timeout 120 bash -c "until echo > /dev/tcp/localhost/${INFLUXDB_PORT}; do sleep 0.5; done" > /dev/null 2>&1 && curl -i -XPOST http://localhost:${INFLUXDB_PORT}/query --data-urlencode "q=CREATE DATABASE opensand" || fail_opensand_db ${INFLUXDB_PORT}
}
install_logstash_plugin(){
cd /usr/share/logstash
bin/logstash-plugin install logstash-output-influxdb || true
}
restart_services(){
systemctl daemon-reload
systemctl enable elasticsearch.service
systemctl enable influxdb.service
systemctl enable logstash.service
systemctl enable kibana.service
systemctl enable chronograf.service
systemctl restart elasticsearch.service
systemctl restart influxdb.service
systemctl restart logstash.service
systemctl restart kibana.service
systemctl restart chronograf.service
}
case "$1" in
configure)
chown -R elasticsearch:elasticsearch /usr/share/elasticsearch
db_get opensand-collector/configured
RECONFIGURE="${RET}"
db_reset opensand-collector/configured
if [ "${RECONFIGURE}" = "true" ]; then
chown -R elasticsearch:elasticsearch /usr/share/elasticsearch
install_logstash_plugin
fi
create_logstash_conf
create_influxdb_conf
create_elasticsearch_conf
create_kibana_conf
create_logstash_conf
install_logstash_plugin
create_chronograf_conf
restart_services
create_opensand_db
if [ "${RECONFIGURE}" = "true" ]; then
create_opensand_db
fi
;;
abort-upgrade|abort-remove|abort-deconfigure)
......
......@@ -33,10 +33,12 @@ stop_services(){
systemctl disable influxdb.service || true
systemctl disable logstash.service || true
systemctl disable kibana.service || true
systemctl disable chronograf.service || true
systemctl stop elasticsearch.service || true
systemctl stop influxdb.service || true
systemctl stop logstash.service || true
systemctl stop kibana.service || true
systemctl stop chronograf.service || true
}
case "$1" in
......
......@@ -31,3 +31,16 @@ Type: string
Default: 5601
Description: Kibana HTTP Port
Port that Kibana will use to publish its HTTP service.
Template: opensand-collector/chronograf/port
Type: string
Default: 8888
Description: Kibana HTTP Port
Port that Chronograf will use to publish its HTTP service.
Template: opensand-collector/configured
Type: boolean
Default: false
Description: Has this packet already been configured ?
Helper variable that keep track of whether the packet
is being installed or reconfigured.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment