#!/bin/sh : ${icinga_threads:="$nproc"} : ${icinga_dbname:='icinga'} : ${icinga_dbhost:="$postgres_host"} : ${icinga_password:='changeme'} : ${icinga_ticket_salt:='changeme'} : ${icingaweb_api_password:='changeme'} : ${icingaweb_dbhost:="$postgres_host"} : ${icingaweb_dbname:='icingaweb'} : ${icingaweb_access_role:='icinga-access'} # Note that icinga does not support nested groups. : ${icingaweb_admin_groups:=''} icinga_local_user=icinga icinga_dn="uid=${icinga_username},${robots_basedn}" icinga_conf_dir=/usr/local/etc/icinga2 icinga_data_dir=/var/lib/icinga2 icinga_cert_dir="${icinga_data_dir}/certs" icinga_ca_dir="${icinga_data_dir}/ca" icingadb_conf_dir=/usr/local/etc/icingadb icingaweb_api_username=icingaweb2 icingaweb_https_cert="${nginx_conf_dir}/icingaweb.crt" icingaweb_https_key="${nginx_conf_dir}/icingaweb.key" icingaweb_install_dir=/usr/local/www/icingaweb2 icingaweb_webroot="${icingaweb_install_dir}/public" icingaweb_conf_dir=/usr/local/etc/icingaweb2 icingaweb_fpm_socket=/var/run/fpm-icingaweb.sock icingaweb_client_keytab="${keytab_dir}/icingaweb.client.keytab" nginx_keytab="${keytab_dir}/nginx.keytab" redis_user=redis redis_data_dir=/var/db/redis redis_sock=/var/run/redis/redis.sock redis_port=6379 redis_data_dir=/var/db/redis icinga_psql(){ KRB5CCNAME=MEMORY: KRB5_CLIENT_KTNAME="$icingaweb_client_keytab" \ psql \ --quiet --no-align --tuples-only --echo-all \ --host="$icinga_dbhost" \ --dbname="$icinga_dbname" \ --username="$icinga_username" \ --no-password \ "$@" } icingaweb_psql(){ KRB5CCNAME=MEMORY: KRB5_CLIENT_KTNAME="$icingaweb_client_keytab" \ psql \ --quiet --no-align --tuples-only --echo-all \ --host="$icingaweb_dbhost" \ --dbname="$icingaweb_dbname" \ --username="$icinga_username" \ --no-password \ "$@" } # Install packages. pkg install -y \ icinga2 \ icingadb \ icingaweb2-php${php_version} \ icingaweb2-module-icingadb-php${php_version} \ nginx \ redis # Create dataset for icinga state directory create_dataset -o "mountpoint=${icinga_data_dir}" "${state_dataset}/icinga" install_directory -m 0755 -o "$icinga_local_user" -g "$icinga_local_user" "$icinga_data_dir" # Create icinga LDAP user, principal, and keytab. # Note that we have a separate userPassword attribute in LDAP because icingadb is # written in golang, and it's pq library does not build with GSSAPI support. # GSSAPI is supported by icingaweb2 via PHP's PDO, however, so we use it there. # We also need a userPassword attribute for icingaweb2 authn/authz. ldap_add "$icinga_dn" < /usr/local/etc/php-fpm.d/www.conf # Copy TLS certificate for nginx. install_certificate nginx "$icingaweb_https_cert" install_certificate_key nginx "$icingaweb_https_key" # Icinga spawns a number of threads based on the core count of the machine. On machines # with a large number of CPU cores, this can be undesirable (especially if run from a jail # with cpuset()). # # The thread count can be overriden with the -DConcurrency=N argument to icinga2. # Unfortunately, icinga2 rc script from ports does not have a way to override the # daemon arguments. So we have to copy over a custom one ("myicinga2"). # # https://icinga.com/docs/icinga-2/latest/doc/15-troubleshooting/#try-reducing-concurrency-threads install_file -m 0555 /usr/local/etc/rc.d/myicinga2 # Enable and start daemons. sysrc -v \ nginx_enable=YES \ php_fpm_enable=YES \ redis_enable=YES \ icingadb_enable=YES \ myicinga2_enable=YES \ icinga2_flags="-DConfiguration.Concurrency=${icinga_threads}" service nginx restart service php_fpm restart service redis restart service icingadb restart > /dev/null 2>&1 service myicinga2 restart # Create access role. ldap_add "cn=${icingaweb_access_role},${roles_basedn}" <