How to upgrade icinga2 and its web-interface

Upgrade icinga2 and its web-interface using official/dedicated repository and PostgreSQL database.

Remember about backups.

Update package index.

$ sudo apt-get update

I will upgrade icinga2 from version 2.7.1-2 to 2.8.0-1.

$ apt-cache policy icinga2-ido-pgsql
icinga2-ido-pgsql:
  Installed: 2.7.1-2.stretch
  Candidate: 2.8.0-1.stretch
  Version table:
     2.8.0-1.stretch 500
        500 http://packages.icinga.com/debian icinga-stretch/main amd64 Packages
     2.7.2-1.stretch 500
        500 http://packages.icinga.com/debian icinga-stretch/main amd64 Packages
 *** 2.7.1-2.stretch 500
        500 http://packages.icinga.com/debian icinga-stretch/main amd64 Packages
        100 /var/lib/dpkg/status
     2.7.1-1.stretch 500
        500 http://packages.icinga.com/debian icinga-stretch/main amd64 Packages
     2.7.0-1.stretch 500
        500 http://packages.icinga.com/debian icinga-stretch/main amd64 Packages
     2.6.3-1.stretch 500
        500 http://packages.icinga.com/debian icinga-stretch/main amd64 Packages
     2.6.0-2 500
        500 http://ftp.task.gda.pl/debian stretch/main amd64 Packages

I will upgrade icingaweb2 from version 2.4.2-1 to 2.5.0-1.

$ apt-cache policy icingaweb2
icingaweb2:
  Installed: 2.4.2-1.stretch
  Candidate: 2.5.0-1.stretch
  Version table:
     2.5.0-1.stretch 500
        500 http://packages.icinga.com/debian icinga-stretch/main amd64 Packages
 *** 2.4.2-1.stretch 500
        500 http://packages.icinga.com/debian icinga-stretch/main amd64 Packages
        100 /var/lib/dpkg/status
     2.4.1-2.stretch 500
        500 http://packages.icinga.com/debian icinga-stretch/main amd64 Packages
     2.4.1-1 500
        500 http://ftp.task.gda.pl/debian stretch/main amd64 Packages

Upgrade these packages.

$ sudo apt-get upgrade -o Dpkg::Options::="--force-confold" -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
  linux-image-amd64
The following packages will be upgraded:
  icinga2 icinga2-bin icinga2-common icinga2-doc icinga2-ido-pgsql icingacli icingaweb2 icingaweb2-common icingaweb2-module-doc icingaweb2-module-monitoring libicinga2 php-icinga
12 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
Need to get 9,448 kB of archives.
After this operation, 1,080 kB of additional disk space will be used.
Get:1 http://packages.icinga.com/debian icinga-stretch/main amd64 icinga2-ido-pgsql amd64 2.8.0-1.stretch [179 kB]
Get:2 http://packages.icinga.com/debian icinga-stretch/main amd64 icinga2 amd64 2.8.0-1.stretch [83.3 kB]
Get:3 http://packages.icinga.com/debian icinga-stretch/main amd64 icinga2-bin amd64 2.8.0-1.stretch [152 kB]
Get:4 http://packages.icinga.com/debian icinga-stretch/main amd64 libicinga2 amd64 2.8.0-1.stretch [2,405 kB]
Get:5 http://packages.icinga.com/debian icinga-stretch/main amd64 icinga2-common all 2.8.0-1.stretch [128 kB]
Get:6 http://packages.icinga.com/debian icinga-stretch/main amd64 icinga2-doc all 2.8.0-1.stretch [1,502 kB]
Get:7 http://packages.icinga.com/debian icinga-stretch/main amd64 icingaweb2-module-monitoring all 2.5.0-1.stretch [666 kB]
Get:8 http://packages.icinga.com/debian icinga-stretch/main amd64 icingaweb2-module-doc all 2.5.0-1.stretch [42.0 kB]
Get:9 http://packages.icinga.com/debian icinga-stretch/main amd64 icingaweb2-common all 2.5.0-1.stretch [365 kB]
Get:10 http://packages.icinga.com/debian icinga-stretch/main amd64 icingacli all 2.5.0-1.stretch [26.6 kB]
Get:11 http://packages.icinga.com/debian icinga-stretch/main amd64 icingaweb2 all 2.5.0-1.stretch [3,149 kB]
Get:12 http://packages.icinga.com/debian icinga-stretch/main amd64 php-icinga all 2.5.0-1.stretch [750 kB]
Fetched 9,448 kB in 1s (5,861 kB/s)
apt-listchanges: Reading changelogs...
Preconfiguring packages ...
(Reading database ... 42122 files and directories currently installed.)
Preparing to unpack .../00-icinga2-ido-pgsql_2.8.0-1.stretch_amd64.deb ...
Unpacking icinga2-ido-pgsql (2.8.0-1.stretch) over (2.7.1-2.stretch) ...
Preparing to unpack .../01-icinga2_2.8.0-1.stretch_amd64.deb ...
Unpacking icinga2 (2.8.0-1.stretch) over (2.7.1-2.stretch) ...
Preparing to unpack .../02-icinga2-bin_2.8.0-1.stretch_amd64.deb ...
Unpacking icinga2-bin (2.8.0-1.stretch) over (2.7.1-2.stretch) ...
Preparing to unpack .../03-libicinga2_2.8.0-1.stretch_amd64.deb ...
Unpacking libicinga2 (2.8.0-1.stretch) over (2.7.1-2.stretch) ...
Preparing to unpack .../04-icinga2-common_2.8.0-1.stretch_all.deb ...
Unpacking icinga2-common (2.8.0-1.stretch) over (2.7.1-2.stretch) ...
dpkg: warning: unable to delete old directory '/etc/icinga2/repository.d': Directory not empty
Preparing to unpack .../05-icinga2-doc_2.8.0-1.stretch_all.deb ...
Unpacking icinga2-doc (2.8.0-1.stretch) over (2.7.1-2.stretch) ...
Preparing to unpack .../06-icingaweb2-module-monitoring_2.5.0-1.stretch_all.deb ...
Unpacking icingaweb2-module-monitoring (2.5.0-1.stretch) over (2.4.2-1.stretch) ...
Preparing to unpack .../07-icingaweb2-module-doc_2.5.0-1.stretch_all.deb ...
Unpacking icingaweb2-module-doc (2.5.0-1.stretch) over (2.4.2-1.stretch) ...
Preparing to unpack .../08-icingaweb2-common_2.5.0-1.stretch_all.deb ...
Unpacking icingaweb2-common (2.5.0-1.stretch) over (2.4.2-1.stretch) ...
Preparing to unpack .../09-icingacli_2.5.0-1.stretch_all.deb ...
Unpacking icingacli (2.5.0-1.stretch) over (2.4.2-1.stretch) ...
Preparing to unpack .../10-icingaweb2_2.5.0-1.stretch_all.deb ...
Unpacking icingaweb2 (2.5.0-1.stretch) over (2.4.2-1.stretch) ...
Preparing to unpack .../11-php-icinga_2.5.0-1.stretch_all.deb ...
Unpacking php-icinga (2.5.0-1.stretch) over (2.4.2-1.stretch) ...
Setting up icinga2-common (2.8.0-1.stretch) ...
Installing new version of config file /etc/icinga2/conf.d/timeperiods.conf ...

Configuration file '/etc/icinga2/features-available/api.conf'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
 ==> Using current old file as you requested.
Installing new version of config file /etc/icinga2/icinga2.conf ...
Setting up libicinga2 (2.8.0-1.stretch) ...
Setting up icinga2-bin (2.8.0-1.stretch) ...
Setting up icinga2 (2.8.0-1.stretch) ...
Setting up php-icinga (2.5.0-1.stretch) ...
Processing triggers for systemd (232-25+deb9u1) ...
Setting up icingacli (2.5.0-1.stretch) ...
Setting up icingaweb2-common (2.5.0-1.stretch) ...
Processing triggers for man-db (2.7.6.1-2) ...
Setting up icingaweb2 (2.5.0-1.stretch) ...
Setting up icinga2-ido-pgsql (2.8.0-1.stretch) ...
dbconfig-common: writing config to /etc/dbconfig-common/icinga2-ido-pgsql.conf
dbconfig-common: flushing administrative password
Setting up icinga2-doc (2.8.0-1.stretch) ...
Setting up icingaweb2-module-doc (2.5.0-1.stretch) ...
Setting up icingaweb2-module-monitoring (2.5.0-1.stretch) ...

icinga2 daemon will not work due to database schema change.

$ sudo tail /var/log/icinga2/icinga2.log
[2017-12-21 12:00:12 -0600] warning/IdoPgsqlConnection: Exception during database operation: Verify that your database is operational!                                                                             
[2017-12-21 12:00:22 -0600] critical/IdoPgsqlConnection: Schema version '1.14.2' does not match the required version '1.14.3' (or newer)! Please check the upgrade documentation at https://docs.icinga.com/icinga2
/latest/doc/module/icinga2/chapter/upgrading-icinga-2#upgrading-postgresql-db                                                                                                                                      
Context:                                                                                                                                                                                                           
        (0) Reconnecting to PostgreSQL IDO database 'ido-pgsql'     

Inspect the number of database upgrades you need to perform for icinga2.

There is only one this time.

$ ls /usr/share/icinga2-ido-pgsql/schema/upgrade/
2.0.2.sql  2.1.0.sql  2.2.0.sql  2.3.0.sql  2.4.0.sql  2.5.0.sql  2.6.0.sql  2.8.0.sql

Display database configuration.

$ sudo cat /etc/icinga2/features-enabled/ido-pgsql.conf
/**
 * The db_ido_pgsql library implements IDO functionality
 * for PostgreSQL.
 */

library "db_ido_pgsql"

object IdoPgsqlConnection "ido-pgsql" {
  user = "icinga_ido",
  password = "icinga_ido_pwd",
  host = "localhost",
  database = "icinga_ido"
}

Upgrade database.

$ PGHOST="localhost" PGUSER="icinga_ido" PGPASSWORD="icinga_ido_pwd" PGDATABASE="icinga_ido" \
  psql < /usr/share/icinga2-ido-pgsql/schema/upgrade/2.8.0.sql
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
 updatedbversion 
-----------------
 
(1 row)

Inspect the number of database upgrades you need to perform for icingaweb2.

There is only one this time.

$ ls /usr/share/icingaweb2/etc/schema/pgsql-upgrades/
2.0.0beta3-2.0.0rc1.sql  2.5.0.sql

Display database configuration.

$ sudo cat /etc/icingaweb2/resources.ini
[icingaweb_db]
type = "db"
db = "pgsql"
host = "localhost"
port = "5432"
dbname = "icinga_web"
username = "icinga_web"
password = "icinga_web_pwd"
charset = "UTF-8"
persistent = "0"

[...]

Upgrade database.

$ PGHOST="localhost" PGUSER="icinga_web" PGPASSWORD="icinga_web_pwd" PGDATABASE="icinga_web" \
  psql < /usr/share/icingaweb2/etc/schema/pgsql-upgrades/2.5.0.sql
ALTER TABLE
ALTER TABLE
ALTER TABLE

icinga2 daemon should be operational at this moment.

Read Upgrading Icinga 2 and Upgrading Icinga Web 2 documents to perform additional steps.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system. He is also open for new opportunities and challenges.

Gdansk, Poland https://sleeplessbeastie.eu