summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorKonstantinos Natsakis <5933427+knatsakis@users.noreply.github.com>2019-10-18 16:56:20 +0300
committerGitHub <noreply@github.com>2019-10-18 16:56:20 +0300
commiteb01440d2a88fd162f4063a11cd476e185f913ee (patch)
tree21bfc691208dedf48f7318883e5672ddd510a118 /contrib
parent8f1ee072f151a1a553959af27b7ae42cff7b311b (diff)
Fix upgrade path from v1.17.1 to v1.18.x for deb packages (#7118)
Diffstat (limited to 'contrib')
-rw-r--r--contrib/debian/control1
-rw-r--r--contrib/debian/control.buster1
-rw-r--r--contrib/debian/control.jessie1
-rw-r--r--contrib/debian/control.trusty1
-rw-r--r--contrib/debian/control.xenial1
-rw-r--r--contrib/debian/netdata.postinst.in13
-rw-r--r--contrib/debian/netdata.postrm13
-rw-r--r--contrib/debian/netdata.preinst16
8 files changed, 47 insertions, 0 deletions
diff --git a/contrib/debian/control b/contrib/debian/control
index be9a778606..b4dfa683d4 100644
--- a/contrib/debian/control
+++ b/contrib/debian/control
@@ -50,6 +50,7 @@ Depends: adduser,
libprotoc10,
${misc:Depends},
${shlibs:Depends}
+Pre-Depends: dpkg (>= 1.17.14)
Description: real-time charts for system monitoring
Netdata is a daemon that collects data in realtime (per second)
and presents a web site to view and analyze them. The presentation
diff --git a/contrib/debian/control.buster b/contrib/debian/control.buster
index 1166883be3..6b9d0dc501 100644
--- a/contrib/debian/control.buster
+++ b/contrib/debian/control.buster
@@ -50,6 +50,7 @@ Depends: adduser,
libprotoc17,
${misc:Depends},
${shlibs:Depends}
+Pre-Depends: dpkg (>= 1.17.14)
Description: real-time charts for system monitoring
Netdata is a daemon that collects data in realtime (per second)
and presents a web site to view and analyze them. The presentation
diff --git a/contrib/debian/control.jessie b/contrib/debian/control.jessie
index 79db7839c8..4ffd25b551 100644
--- a/contrib/debian/control.jessie
+++ b/contrib/debian/control.jessie
@@ -48,6 +48,7 @@ Depends: adduser,
libprotoc10,
${misc:Depends},
${shlibs:Depends}
+Pre-Depends: dpkg (>= 1.17.14)
Description: real-time charts for system monitoring
Netdata is a daemon that collects data in realtime (per second)
and presents a web site to view and analyze them. The presentation
diff --git a/contrib/debian/control.trusty b/contrib/debian/control.trusty
index 918d2ad35f..5edcb95fb2 100644
--- a/contrib/debian/control.trusty
+++ b/contrib/debian/control.trusty
@@ -48,6 +48,7 @@ Depends: adduser,
libprotoc8,
${misc:Depends},
${shlibs:Depends}
+Pre-Depends: dpkg (>= 1.17.14)
Description: real-time charts for system monitoring
Netdata is a daemon that collects data in realtime (per second)
and presents a web site to view and analyze them. The presentation
diff --git a/contrib/debian/control.xenial b/contrib/debian/control.xenial
index 412b389e8d..c562e8ef9c 100644
--- a/contrib/debian/control.xenial
+++ b/contrib/debian/control.xenial
@@ -50,6 +50,7 @@ Depends: adduser,
libprotoc9v5,
${misc:Depends},
${shlibs:Depends}
+Pre-Depends: dpkg (>= 1.17.14)
Description: real-time charts for system monitoring
Netdata is a daemon that collects data in realtime (per second)
and presents a web site to view and analyze them. The presentation
diff --git a/contrib/debian/netdata.postinst.in b/contrib/debian/netdata.postinst.in
index 44b53ccfbd..602f21c722 100644
--- a/contrib/debian/netdata.postinst.in
+++ b/contrib/debian/netdata.postinst.in
@@ -2,6 +2,19 @@
set -e
+dpkg-maintscript-helper dir_to_symlink \
+ /var/lib/netdata/www/.well-known /usr/share/netdata/www/.well-known 1.18.1~ netdata -- "$@"
+dpkg-maintscript-helper dir_to_symlink \
+ /var/lib/netdata/www/css /usr/share/netdata/www/css 1.18.1~ netdata -- "$@"
+dpkg-maintscript-helper dir_to_symlink \
+ /var/lib/netdata/www/fonts /usr/share/netdata/www/fonts 1.18.1~ netdata -- "$@"
+dpkg-maintscript-helper dir_to_symlink \
+ /var/lib/netdata/www/images /usr/share/netdata/www/images 1.18.1~ netdata -- "$@"
+dpkg-maintscript-helper dir_to_symlink \
+ /var/lib/netdata/www/lib /usr/share/netdata/www/lib 1.18.1~ netdata -- "$@"
+dpkg-maintscript-helper dir_to_symlink \
+ /var/lib/netdata/www/static /usr/share/netdata/www/static 1.18.1~ netdata -- "$@"
+
case "$1" in
configure)
if [ -z "$2" ]; then
diff --git a/contrib/debian/netdata.postrm b/contrib/debian/netdata.postrm
index 94e82bcd45..de93dad1ae 100644
--- a/contrib/debian/netdata.postrm
+++ b/contrib/debian/netdata.postrm
@@ -2,6 +2,19 @@
set -e
+dpkg-maintscript-helper dir_to_symlink \
+ /var/lib/netdata/www/.well-known /usr/share/netdata/www/.well-known 1.18.1~ netdata -- "$@"
+dpkg-maintscript-helper dir_to_symlink \
+ /var/lib/netdata/www/css /usr/share/netdata/www/css 1.18.1~ netdata -- "$@"
+dpkg-maintscript-helper dir_to_symlink \
+ /var/lib/netdata/www/fonts /usr/share/netdata/www/fonts 1.18.1~ netdata -- "$@"
+dpkg-maintscript-helper dir_to_symlink \
+ /var/lib/netdata/www/images /usr/share/netdata/www/images 1.18.1~ netdata -- "$@"
+dpkg-maintscript-helper dir_to_symlink \
+ /var/lib/netdata/www/lib /usr/share/netdata/www/lib 1.18.1~ netdata -- "$@"
+dpkg-maintscript-helper dir_to_symlink \
+ /var/lib/netdata/www/static /usr/share/netdata/www/static 1.18.1~ netdata -- "$@"
+
case "$1" in
remove)
;;
diff --git a/contrib/debian/netdata.preinst b/contrib/debian/netdata.preinst
new file mode 100644
index 0000000000..c4da80fcca
--- /dev/null
+++ b/contrib/debian/netdata.preinst
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+set -e
+
+dpkg-maintscript-helper dir_to_symlink \
+ /var/lib/netdata/www/.well-known /usr/share/netdata/www/.well-known 1.18.1~ netdata -- "$@"
+dpkg-maintscript-helper dir_to_symlink \
+ /var/lib/netdata/www/css /usr/share/netdata/www/css 1.18.1~ netdata -- "$@"
+dpkg-maintscript-helper dir_to_symlink \
+ /var/lib/netdata/www/fonts /usr/share/netdata/www/fonts 1.18.1~ netdata -- "$@"
+dpkg-maintscript-helper dir_to_symlink \
+ /var/lib/netdata/www/images /usr/share/netdata/www/images 1.18.1~ netdata -- "$@"
+dpkg-maintscript-helper dir_to_symlink \
+ /var/lib/netdata/www/lib /usr/share/netdata/www/lib 1.18.1~ netdata -- "$@"
+dpkg-maintscript-helper dir_to_symlink \
+ /var/lib/netdata/www/static /usr/share/netdata/www/static 1.18.1~ netdata -- "$@"
'n472' href='#n472'>472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
# -*- coding: utf-8 -*-
# Description: netdata python modules framework
# Author: Pawel Krupa (paulfantom)

# Remember:
# ALL CODE NEEDS TO BE COMPATIBLE WITH Python > 2.7 and Python > 3.1
# Follow PEP8 as much as it is possible
# "check" and "create" CANNOT be blocking.
# "update" CAN be blocking
# "update" function needs to be fast, so follow:
#   https://wiki.python.org/moin/PythonSpeed/PerformanceTips
# basically:
#  - use local variables wherever it is possible
#  - avoid dots in expressions that are executed many times
#  - use "join()" instead of "+"
#  - use "import" only at the beginning
#
# using ".encode()" in one thread can block other threads as well (only in python2)

import time
# import sys
import os
import socket
import select
try:
    import urllib.request as urllib2
except ImportError:
    import urllib2

from subprocess import Popen, PIPE

import threading
import msg

try:
    PATH = os.getenv('PATH').split(':')
except AttributeError:
    PATH = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'.split(':')


# class BaseService(threading.Thread):
class SimpleService(threading.Thread):
    """
    Prototype of Service class.
    Implemented basic functionality to run jobs by `python.d.plugin`
    """
    def __init__(self, configuration=None, name=None):
        """
        This needs to be initialized in child classes
        :param configuration: dict
        :param name: str
        """
        threading.Thread.__init__(self)
        self._data_stream = ""
        self.daemon = True
        self.retries = 0
        self.retries_left = 0
        self.priority = 140000
        self.update_every = 1
        self.name = name
        self.override_name = None
        self.chart_name = ""
        self._dimensions = []
        self._charts = []
        self.__chart_set = False
        self.__first_run = True
        self.order = []
        self.definitions = {}
        if configuration is None:
            self.error("BaseService: no configuration parameters supplied. Cannot create Service.")
            raise RuntimeError
        else:
            self._extract_base_config(configuration)
            self.timetable = {}
            self.create_timetable()

    # --- BASIC SERVICE CONFIGURATION ---

    def _extract_base_config(self, config):
        """
        Get basic parameters to run service
        Minimum config:
            config = {'update_every':1,
                      'priority':100000,
                      'retries':0}
        :param config: dict
        """
        pop = config.pop
        try:
            self.override_name = pop('name')
        except KeyError:
            pass
        self.update_every = int(pop('update_every'))
        self.priority = int(pop('priority'))
        self.retries = int(pop('retries'))
        self.retries_left = self.retries
        self.configuration = config

    def create_timetable(self, freq=None):
        """
        Create service timetable.
        `freq` is optional
        Example:
            timetable = {'last': 1466370091.3767564,
                         'next': 1466370092,
                         'freq': 1}
        :param freq: int
        """
        if freq is None:
            freq = self.update_every
        now = time.time()
        self.timetable = {'last': now,
                          'next': now - (now % freq) + freq,
                          'freq': freq}

    # --- THREAD CONFIGURATION ---

    def _run_once(self):
        """
        Executes self.update(interval) and draws run time chart.
        Return value presents exit status of update()
        :return: boolean
        """
        t_start = float(time.time())
        chart_name = self.chart_name

        since_last = int((t_start - self.timetable['last']) * 1000000)
        if self.__first_run:
            since_last = 0

        if not self.update(since_last):
            self.error("update function failed.")
            return False

        # draw performance graph
        run_time = int((time.time() - t_start) * 1000)
        print("BEGIN netdata.plugin_pythond_%s %s\nSET run_time = %s\nEND\n" %
              (self.chart_name, str(since_last), str(run_time)))

        self.debug(chart_name, "updated in", str(run_time), "ms")
        self.timetable['last'] = t_start
        self.__first_run = False
        return True

    def run(self):
        """
        Runs job in thread. Handles retries.
        Exits when job failed or timed out.
        :return: None
        """
        step = float(self.timetable['freq'])
        penalty = 0
        self.timetable['last'] = float(time.time() - step)
        self.debug("starting data collection - update frequency:", str(step), " retries allowed:", str(self.retries))
        while True:  # run forever, unless something is wrong
            now = float(time.time())
            next = self.timetable['next'] = now - (now % step) + step + penalty

            # it is important to do this in a loop
            # sleep() is interruptable
            while now < next:
                self.debug("sleeping for", str(next - now), "secs to reach frequency of", str(step), "secs, now:", str(now), " next:", str(next), " penalty:", str(penalty))
                time.sleep(next - now)
                now = float(time.time())

            # do the job
            try:
                status = self._run_once()
            except Exception as e:
                status = False

            if status:
                # it is good
                self.retries_left = self.retries
                penalty = 0
            else:
                # it failed
                self.retries_left -= 1
                if self.retries_left <= 0:
                    if penalty == 0:
                        penalty = float(self.retries * step) / 2
                    else:
                        penalty *= 1.5

                    if penalty > 60