commit 6f459df0f21a9550170c3dccebe8afba023d23a9 Author: CrazyMax Date: Sat Jul 7 13:38:51 2018 +0200 Initial version based on LibreNMS 1.41 diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..617e694 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +/.dev +/.idea +/*.iml + +/.git +/.res +/examples +/.editorconfig +/.gitignore +/.travis.yml +/CHANGELOG.md +/LICENSE +/README.md diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..acb43f7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +# editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[{Dockerfile,*.sh,*.yml}] +indent_size = 2 + +[assets/**] +insert_final_newline = false + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..98df5db --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# Jetbrains +/.idea +/*.iml + +# App +/.dev diff --git a/.res/docker-librenms.jpg b/.res/docker-librenms.jpg new file mode 100644 index 0000000..a2bed3a Binary files /dev/null and b/.res/docker-librenms.jpg differ diff --git a/.res/paypal.png b/.res/paypal.png new file mode 100644 index 0000000..76842ea Binary files /dev/null and b/.res/paypal.png differ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..27b4cb7 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,59 @@ +sudo: required + +services: + - docker + +env: + global: + - VERSION=1.41 + - GITHUB_REPO=crazy-max/docker-librenms + - DOCKER_USERNAME=crazymax + - DOCKER_REPONAME=librenms + - QUAY_USERNAME=crazymax + - QUAY_REPONAME=librenms + - secure: GMYFptO3rWVVITjC0Wz8g9uccBjSMBvVt3aFC3Y08/3Hw9CoA/SS51X/2lh0bRn+y49X0742QC7b2LtSWa3eERM1HbzlS1ODK75+P0lGYdtW2Ng5JutI+GRt8xTouY7+iP4qSAbOYMUdM5e61PkRepJvZWVeBkPtAtcGpxZO75h+snFxuzFVZXWLoSKjByKIqy9VXzT2P0Wx+zuUWpeo2qA62ONRJf5RjIKCDxHmWEwhXKmmDjeqo+Db/zsUwGYSwKpKRGBhyPVP0MnKFA2HQ/+dG1NyikXhae5dhjaZvgG9tSpbYdOWCHCunbxm6VWozt/kvkqkbizn+S3aoeeZyco40ZFIUinpypxw/nZpVvfDkwBIhw3nOS4giMKHLLBtnkSZw2szP6zfdLX6MLKWSjcDsBbtqj8aNe8Z1ViEKc2uW+yqJvd6GNnDL+AINe5rJ/cjeseh1ancOaGG8tlGsg/80dhOV3l+E4nINn+1uj354ncH/lv14e4giDNMGRw8gq7HFWxIE1X8SLetK9Hz5kLyMIPlSCO2fL73adrqfJFFluTQ0CbzsOEHSuScHT8i9UJWrqcu25BQ4pKidmDAt0gT7x6cz7zziuTY0hTO05txIP0FCop0qCFoLuAGM/bQg8r6FnfIZu4NbUxutjLiAN5aMB1D3znnymxKdeX/HOc= # DOCKER_PASSWORD + - secure: XMkF9Nz6FjKVB52vv7rZ+fa7vDDRXG7/nDm5Wio4eljYU/+cIZwdbBv2hU2IEmherZBn2jO9V64LYR9yTLALOGMEjqE/0E8KNiibj7VRjeRmtQrTHbUj7XpBmqAVyNek2GxkmtS4meOIcUUxBOfCAiIu2b++iuR70rAHvr+dL8skX7FNG77ZgTRsP9VkCylyfw0qb+50pD+2ukOFHxZ4tSi89F8ZU4UQOiNTBre4NUPCN5DZmglSt4nUYt3iofKs9p4ZjPP0cTBpHhArn37VZJyo1tOcl1jP8x18PVvgxrHO8Z0FQCasnZ6O269FR8lF28yM4CwHxk6ufCuieCCj5f0ez6S8IEv82a8ljmw+a75Gb6+pAmYB8nY49VkrWmA6KoDY+F+Ob30QOOtLCGumGBLZ1++6MOtwFjN5BzAyVl3Qhl+9heUMM3ULkbEV0IGJHL1M3zEBqxkQO6urdgf6cPEf3uldd+T6Ochn2DZ42Ge+yiZiIrgF/p0R3l1vDbyBG6OcnmaEoQWdIgqa6DUV48MBkYHF9Sp0idUbsrOaoVNsZZ4h0P72fRci/rElvoDGJIAdFEEE1ZW/y3a6hJihxvYQM9+S+HvzluI+5SKzdFUJ4hRpaGfIvclKdyaCNSE1B0VrwGXn7pBt5tem0IZnE5BQ9d/6TgVFc+L2Eyf7Mck= # QUAY_PASSWORD + - secure: mLY2C4Ggmg/VUdWoYc8vqYQb7lLSSB/YMvKUzY+z8VGAi5A8J1A6oTgeeThiKPWaNp9GgU1hdHA5WqoSCuOk2SzJoIEhnPU0j3GkDknuXmbhU1UXsuefMF++v2J9RarmC2CkyGiBDzJCrcs9srcS6RjmbK7hQv5EsbkjjyQHQwZlMG+q2aUwNcNxhAeD0+gn8j6eZ6myxt/SJ3LZRLCb+ZpP1NITc6aHjC9glc6ZO7bTy6WG6SVg0SREdxbht+cUrTNQvAcIkoEZQ4vOJBi3kAo6aZz6QYglofaYpTCdmiSSFGHseJ7k1Dl+khCL8OqeOnVCOkcu8SgPV7tI6WId8Dky/YPUsFtjivJqekjs/ctAekOHTzJW9UeOLkCOiqeLmQTDQ01JDLno1znzMOTC3T96I5d2LUnob3QOu32chdzqw0LfcawcuNnLwLdbK4AwPcDuIUl6b1FjU6I8DckHjtvL9Mr9xLhIkNrhdPW0vAj8yZkvGCxvGXh+qK6ejNDt/RdH6wWojh1yTbJSCAQLo1WnJ5YpqLxtu5++/4PfiTLkt7u8QMnau5m+8wZ4ju2RfFrwmEaKkrZSkq7ViQ+RsI/y0bNxUzk3Bb02Wgh9MfpPUXLA+4llYWIPnbgL17N5zhsROp9u0YSbzc3cWJm+0TQZZ0hAjyXBDoT2UCsDNqE= # GITHUB_TOKEN + +before_install: + - sudo apt-get update + - docker --version + - export BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo $TRAVIS_PULL_REQUEST_BRANCH; fi) + - export DOCKER_TAG=$(if [ "$BRANCH" == "master" ]; then echo "latest"; else echo $BRANCH; fi) + - echo "TRAVIS_BRANCH=$TRAVIS_BRANCH, PR=$PR, BRANCH=$BRANCH, DOCKER_TAG=$DOCKER_TAG" + +install: + - | + docker build --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ + --build-arg VCS_REF=${TRAVIS_COMMIT::8} \ + --build-arg VERSION=${VERSION} \ + -t $DOCKER_USERNAME/$DOCKER_REPONAME . + +before_script: + - docker network create -d bridge $DOCKER_REPONAME + - docker run -d --network=$DOCKER_REPONAME --name db mariadb:10.2 + - docker run -d --network=$DOCKER_REPONAME --link db -p 8000:80 -e "DB_HOST=db" --name $DOCKER_REPONAME $DOCKER_USERNAME/$DOCKER_REPONAME + - sleep 20 + - docker logs $DOCKER_REPONAME + +script: + - docker ps | grep $DOCKER_REPONAME + +after_success: + - test $TRAVIS_PULL_REQUEST = false + && echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin + && docker tag $DOCKER_USERNAME/$DOCKER_REPONAME $DOCKER_USERNAME/$DOCKER_REPONAME:$DOCKER_TAG + && docker tag $DOCKER_USERNAME/$DOCKER_REPONAME $DOCKER_USERNAME/$DOCKER_REPONAME:$VERSION + && docker push $DOCKER_USERNAME/$DOCKER_REPONAME + && echo "$QUAY_PASSWORD" | docker login quay.io --username "$QUAY_USERNAME" --password-stdin + && docker tag $DOCKER_USERNAME/$DOCKER_REPONAME quay.io/$DOCKER_USERNAME/$DOCKER_REPONAME:$DOCKER_TAG + && docker tag $DOCKER_USERNAME/$DOCKER_REPONAME quay.io/$DOCKER_USERNAME/$DOCKER_REPONAME:$VERSION + && docker push quay.io/$QUAY_USERNAME/$QUAY_REPONAME + +branches: + except: + - /^[0-9]/ + +notifications: + webhooks: + secure: qy/lFOFGeP0IMvDTJZmPemOtHjkpnYq4sm734rTjBsKFNA8MU4TyWCnx24hljRd4YazAkH6j2Uav3XfmnR+UGfutXRsmktzZoDTlygiJLP/026gvD+VuT8GZIFXRpYhNlfPemFoN2/wO5sf91JGQL4cxVcF9r1A0aUQUtAzvl9UKwk+DRc9Y78oCKRmIaeoFrvKE1SCGPf/drNYeLKJiRiq7VV5jL+1tmZUjYKWVYnWU3yYSyg3OdAvXAVEDagzvAQ0ors9UJeXxAsAls0kTQc8c2+uWfEH411sRrPuqTYYkXIPQpJszLeDhG0ISU5xs5UCJSi7QzTRxD5lWgn8C2QfGS8x3eQK8fHEfN1Q0frqGdCYJcEC2izs91bwZDmFmDj9B0mkuOyHDjWmTIo+HPkb/ryATFD3Bk2pekHWBkuq+KKTQzvgtgokp4V7xRumDh7htyYzr88uk1EQFR7VY05aWFGFsoZ13oKa4UQ4uglH2xmWVW3X9cyf5NCj/t4mUt5223ZM7Q+LKDONSPz/VEDlSOkPapjC4rpn6mn/k6FNN3UyC4hL9+HXSFyCOJZDy3P6lagCWWlzLxt0R4DnptZG+cShW0+bzcecEaGPjyEidACctKl3hfDCiblg05Js0lvW454C4TPnzZ/tDAE6VE8mCFtU/K1ur+wneZuOv2pA= diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..cc352ba --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## 1.41-RC1 (2018/07/07) + +* Initial version based on LibreNMS 1.41 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..eb8387b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,62 @@ +FROM alpine:3.8 +MAINTAINER CrazyMax + +ARG BUILD_DATE +ARG VCS_REF +ARG VERSION + +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name="librenms" \ + org.label-schema.description="LibreNMS based on Alpine Linux and Nginx" \ + org.label-schema.version=$VERSION \ + org.label-schema.url="https://github.com/crazy-max/docker-librenms" \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url="https://github.com/crazy-max/docker-librenms" \ + org.label-schema.vendor="CrazyMax" \ + org.label-schema.schema-version="1.0" + +RUN apk --update --no-cache add \ + binutils ca-certificates coreutils curl fping git graphviz imagemagick mtr mysql-client net-snmp net-snmp-tools \ + nginx nmap openssl python2 rrdtool runit shadow ssmtp supervisor tzdata util-linux whois \ + php7 php7-cli php7-ctype php7-curl php7-fpm php7-gd php7-json php7-mcrypt php7-memcached php7-mbstring php7-mysqli \ + php7-opcache php7-openssl php7-pdo php7-pdo_mysql php7-phar php7-posix php7-session php7-simplexml php7-snmp \ + php7-tokenizer php7-xml php7-zip \ + && sed -i -e "s/;date\.timezone.*/date\.timezone = UTC/" /etc/php7/php.ini \ + && cp -f /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.or \ + && rm -rf /var/cache/apk/* /var/www/* /tmp/* + +ENV LIBRENMS_VERSION="1.41" \ + LIBRENMS_PATH="/opt/librenms" \ + DATA_PATH="/data" \ + CRONTAB_PATH="/var/spool/cron/crontabs" + +RUN mkdir -p /opt \ + && addgroup -g 1000 librenms \ + && adduser -u 1000 -G librenms -h ${LIBRENMS_PATH} -s /sbin/nologin -D librenms \ + && usermod -a -G librenms nginx \ + && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer \ + && git clone --branch ${LIBRENMS_VERSION} https://github.com/librenms/librenms.git ${LIBRENMS_PATH} \ + && chown -R librenms. ${LIBRENMS_PATH} \ + && su - librenms -s /bin/sh -c "composer install --no-dev --no-interaction --no-ansi --working-dir=${LIBRENMS_PATH}" \ + && wget -q https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro -O /usr/bin/distro \ + && chmod +x /usr/bin/distro \ + && rm -rf /tmp/* + +ADD entrypoint.sh /entrypoint.sh +ADD assets / + +RUN mkdir -p /data ${LIBRENMS_PATH}/config.d /var/log/supervisord \ + && chmod a+x /entrypoint.sh \ + && cp ${LIBRENMS_PATH}/snmpd.conf.example /etc/snmp/snmpd.conf \ + && cp ${LIBRENMS_PATH}/config.php.default ${LIBRENMS_PATH}/config.php \ + && echo "foreach (glob(\"${DATA_PATH}/config/*.php\") as \$filename) include \$filename;" >> ${LIBRENMS_PATH}/config.php \ + && echo "foreach (glob(\"${LIBRENMS_PATH}/config.d/*.php\") as \$filename) include \$filename;" >> ${LIBRENMS_PATH}/config.php \ + && chown -R librenms. ${DATA_PATH} ${LIBRENMS_PATH} \ + && chown -R nginx. /var/lib/nginx /var/log/nginx /var/log/php7 /var/tmp/nginx + +EXPOSE 80 +WORKDIR ${LIBRENMS_PATH} +VOLUME [ "${DATA_PATH}" ] + +ENTRYPOINT [ "/entrypoint.sh" ] +CMD [ "/usr/bin/supervisord", "-c", "/etc/supervisord.conf" ] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..29b1e96 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 CrazyMax + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5a636ff --- /dev/null +++ b/README.md @@ -0,0 +1,183 @@ +

+ +

+ Version + Build Status + Docker Stars + Docker Pulls + Docker Repository on Quay + Donate Paypal +

+ +## About + +🐳 [LibreNMS](https://www.librenms.org/) Docker image based on Alpine Linux and Nginx.
+If you are interested, [check out](https://hub.docker.com/r/crazymax/) my other 🐳 Docker images! + +## Features + +### Included + +* Alpine Linux 3.8, Nginx, PHP 7.2 +* Cron tasks as a ["sidecar" container](#cron) +* [SSMTP](https://linux.die.net/man/8/ssmtp) for SMTP relay to send emails +* OPCache enabled to store precompiled script bytecode in shared memory + +### From docker-compose + +* [Traefik](https://github.com/containous/traefik-library-image) as reverse proxy and creation/renewal of Let's Encrypt certificates +* [Memcached](https://github.com/docker-library/memcached) image ready to use for better scalability +* [RRDcached](https://github.com/crazy-max/rrdcached) image ready to use for better scalability +* [MariaDB](https://github.com/docker-library/mariadb) image as database instance +* Cron jobs as a ["sidecar" container](#cron) + +## Docker + +### Environment variables + +| Key | Default | Description +|-----------------------------|-------------------|------------------------------------------- +| `TZ` | `UTC` | Timezone (e.g. `Europe/Paris`) +| `PUID` | `1000` | LibreNMS user id +| `PGID` | `1000` | LibreNMS group id +| `MEMORY_LIMIT` | `256M` | PHP memory limit +| `UPLOAD_MAX_SIZE` | `16M` | Upload max size +| `OPCACHE_MEM_SIZE` | `128` | PHP OpCache memory consumption +| `LIBRENMS_POLLER_THREADS` | `16` | Threads that `poller-wrapper.py` runs +| `LIBRENMS_SNMP_COMMUNITY` | `librenmsdocker` | Your community string +| `DB_HOST` | | MySQL database hostname / IP address +| `DB_PORT` | `3306` | MySQL database port +| `DB_NAME` | `librenms` | MySQL database name +| `DB_USER` | `librenms` | MySQL user +| `DB_PASSWORD` | `librenms` | MySQL password +| `SSMTP_HOST` | | SMTP server host +| `SSMTP_PORT` | `25` | SMTP server port +| `SSMTP_HOSTNAME` | `$(hostname -f)` | Full hostname +| `SSMTP_USER` | | SMTP username +| `SSMTP_PASSWORD` | | SMTP password +| `SSMTP_TLS` | `NO` | SSL/TLS +| `MEMCACHED_HOST` | | Hostname / IP address of a Memcached server +| `RRDCACHED_HOST` | | Hostname / IP address of a RRDcached server + +### Volumes + +* `/data` : Contains configuration, rrd database, logs + +### Ports + +* `80` : HTTP port + +## Use this image + +### Docker Compose + +Docker compose is the recommended way to run this image. Copy the content of folder [examples/compose](examples/compose) in `/var/librenms/` on your host for example. Edit the compose and env files with your preferences and run the following commands : + +```bash +touch acme.json +chmod 600 acme.json +docker-compose up -d +docker-compose logs -f +``` + +### Command line + +You can also use the following minimal command : + +```bash +docker run -d -p 80:80 --name librenms \ + -v $(pwd)/data:/data \ + -e "DB_HOST=db" \ + crazymax/librenms:latest +``` + +> `-e "DB_HOST=db"` +> :warning: `db` must be a running MySQL instance + +## Notes + +### Edit configuration + +You can edit configuration of LibreNMS by placing `*.php` files inside `/data/config` folder. Let's say you want to edit the [WebUI config](https://docs.librenms.org/#Support/Configuration/#webui-settings). Create a file called for example `/data/config/webui.php` with this content : + +```php + `-v librenms:/data` +> :warning: `librenms` must be a valid volume already attached to a LibreNMS container + +## Upgrade + +To upgrade to the latest version of LibreNMS, pull the newer image and launch the container. LibreNMS will upgrade automatically : + +```bash +docker-compose pull +docker-compose up -d +``` + +## How can i help ? + +All kinds of contributions are welcomed :raised_hands:!
+The most basic way to show your support is to star :star2: the project, or to raise issues :speech_balloon:
+But we're not gonna lie to each other, I'd rather you buy me a beer or two :beers:! + +[![Paypal](.res/paypal.png)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=962TPYQKMQ2UE) + +## License + +MIT. See `LICENSE` for more details. diff --git a/assets/etc/php7/conf.d/sendmail-ssmtp.ini b/assets/etc/php7/conf.d/sendmail-ssmtp.ini new file mode 100644 index 0000000..6f1b45e --- /dev/null +++ b/assets/etc/php7/conf.d/sendmail-ssmtp.ini @@ -0,0 +1 @@ +sendmail_path=/usr/sbin/ssmtp -t diff --git a/assets/etc/supervisord.conf b/assets/etc/supervisord.conf new file mode 100644 index 0000000..90df761 --- /dev/null +++ b/assets/etc/supervisord.conf @@ -0,0 +1,21 @@ +[supervisord] +nodaemon = true +user = root +logfile = /var/log/supervisord/supervisord.log +pidfile = /var/run/supervisord.pid +childlogdir = /var/log/supervisord/ +logfile_maxbytes = 50MB +logfile_backups = 10 +loglevel = info + +[supervisorctl] +serverurl = unix:///var/run/supervisor.sock + +[unix_http_server] +file = /var/run/supervisor.sock + +[rpcinterface:supervisor] +supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface + +[include] +files = /etc/supervisord/*.conf diff --git a/assets/etc/supervisord/nginx.conf b/assets/etc/supervisord/nginx.conf new file mode 100644 index 0000000..70a8762 --- /dev/null +++ b/assets/etc/supervisord/nginx.conf @@ -0,0 +1,8 @@ +[program:nginx] +command = /usr/sbin/nginx +stdout_logfile = /dev/stdout +stdout_logfile_maxbytes = 0 +stderr_logfile = /dev/stderr +stderr_logfile_maxbytes = 0 +autorestart = false +startentries = 0 diff --git a/assets/etc/supervisord/php.conf b/assets/etc/supervisord/php.conf new file mode 100644 index 0000000..8ef3a3b --- /dev/null +++ b/assets/etc/supervisord/php.conf @@ -0,0 +1,8 @@ +[program:php] +command = /usr/sbin/php-fpm7 +stdout_logfile = /dev/stdout +stdout_logfile_maxbytes = 0 +stderr_logfile = /dev/stderr +stderr_logfile_maxbytes = 0 +autorestart = false +startentries = 0 diff --git a/assets/etc/supervisord/snmpd.conf b/assets/etc/supervisord/snmpd.conf new file mode 100644 index 0000000..d3a1ef4 --- /dev/null +++ b/assets/etc/supervisord/snmpd.conf @@ -0,0 +1,7 @@ +[program:snmpd] +command = /usr/sbin/snmpd -f -c /etc/snmpd.conf +startentries = 0 +stdout_logfile = /proc/1/fd/1 +stdout_logfile_maxbytes = 0 +stderr_logfile = /proc/1/fd/2 +stderr_logfile_maxbytes = 0 \ No newline at end of file diff --git a/assets/tpls/etc/nginx/nginx.conf b/assets/tpls/etc/nginx/nginx.conf new file mode 100644 index 0000000..d3f22d8 --- /dev/null +++ b/assets/tpls/etc/nginx/nginx.conf @@ -0,0 +1,88 @@ +daemon off; +user nginx; +pid /run/nginx.pid; +worker_processes auto; +error_log /proc/1/fd/2 info; +worker_rlimit_nofile 8192; + +events { + worker_connections 2048; + use epoll; + multi_accept on; +} + +http { + include mime.types; + default_type application/octet-stream; + access_log /proc/1/fd/1; + + aio threads; + sendfile on; + + ## Timeouts + client_body_timeout 60; + client_header_timeout 60; + keepalive_timeout 10 10; + send_timeout 60; + + ## TCP options + tcp_nopush on; + tcp_nodelay on; + + ## Handling of IPs in proxied and load balancing situations + set_real_ip_from 0.0.0.0/32; + real_ip_header X-Forwarded-For; + + ## Hide the Nginx version number + server_tokens off; + + ## Body size + client_max_body_size @UPLOAD_MAX_SIZE@; + client_body_buffer_size 128k; + + ## Compression + gzip on; + gzip_buffers 16 8k; + gzip_comp_level 1; + gzip_http_version 1.1; + gzip_min_length 10; + gzip_types text/css application/javascript text/javascript application/x-javascript image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon; + gzip_vary on; + gzip_proxied any; + gzip_disable "msie6"; + + ## Serve already compressed files directly, bypassing on-the-fly compression + gzip_static on; + + ## FastCGI + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_buffers 256 4k; + fastcgi_intercept_errors on; + fastcgi_read_timeout 14400; + + server { + listen 80; + + root /opt/librenms/html; + index index.php; + + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + location /api/v0 { + try_files $uri $uri/ /api_v0.php?$query_string; + } + + location ~ \.php$ { + fastcgi_pass unix:/var/run/php-fpm7.sock; + } + + location ~ /\.ht { + deny all; + } + } +} diff --git a/assets/tpls/etc/php7/conf.d/opcache.ini b/assets/tpls/etc/php7/conf.d/opcache.ini new file mode 100644 index 0000000..f6a74ca --- /dev/null +++ b/assets/tpls/etc/php7/conf.d/opcache.ini @@ -0,0 +1,7 @@ +opcache.enable=1 +opcache.enable_cli=1 +opcache.fast_shutdown=1 +opcache.memory_consumption=@OPCACHE_MEM_SIZE@ +opcache.interned_strings_buffer=16 +opcache.max_accelerated_files=10000 +opcache.revalidate_freq=60 diff --git a/assets/tpls/etc/php7/php-fpm.d/www.conf b/assets/tpls/etc/php7/php-fpm.d/www.conf new file mode 100644 index 0000000..ef857fe --- /dev/null +++ b/assets/tpls/etc/php7/php-fpm.d/www.conf @@ -0,0 +1,28 @@ +[global] +daemonize = no +error_log = /proc/self/fd/2 + +[www] +user = librenms +group = librenms + +listen = /run/php-fpm7.sock +listen.owner = librenms +listen.group = librenms + +pm = dynamic +pm.max_children = 15 +pm.start_servers = 2 +pm.min_spare_servers = 1 +pm.max_spare_servers = 6 +request_terminate_timeout = 0 + +; if we send this to /proc/self/fd/1, it never appears +access.log = /proc/self/fd/2 + +php_admin_value[post_max_size] = @UPLOAD_MAX_SIZE@ +php_admin_value[upload_max_filesize] = @UPLOAD_MAX_SIZE@ +php_admin_value[max_execution_time] = 10800 +php_admin_value[max_input_time] = 3600 +php_admin_value[expose_php] = Off +php_admin_value[memory_limit] = @MEMORY_LIMIT@ \ No newline at end of file diff --git a/assets/usr/local/bin/cron b/assets/usr/local/bin/cron new file mode 100644 index 0000000..53d6c2c --- /dev/null +++ b/assets/usr/local/bin/cron @@ -0,0 +1,5 @@ +#!/bin/sh + +set -e + +exec busybox crond -f -L /dev/stdout diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..70fd7df --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,205 @@ +#!/bin/sh + +function runas_librenms() { + su - librenms -s /bin/sh -c "$1" +} + +TZ=${TZ:-"UTC"} +PUID=${PUID:-1000} +PGID=${PGID:-1000} + +MEMORY_LIMIT=${MEMORY_LIMIT:-"256M"} +UPLOAD_MAX_SIZE=${UPLOAD_MAX_SIZE:-"16M"} +OPCACHE_MEM_SIZE=${OPCACHE_MEM_SIZE:-"128"} + +LIBRENMS_POLLER_THREADS=${LIBRENMS_POLLER_THREADS:-"16"} +LIBRENMS_SNMP_COMMUNITY=${LIBRENMS_SNMP_COMMUNITY:-"librenmsdocker"} + +DB_PORT=${DB_PORT:-"3306"} +DB_NAME=${DB_NAME:-"librenms"} +DB_USER=${DB_USER:-"librenms"} +DB_PASSWORD=${DB_PASSWORD:-"asupersecretpassword"} + +SSMTP_PORT=${SSMTP_PORT:-"25"} +SSMTP_HOSTNAME=${SSMTP_HOSTNAME:-"$(hostname -f)"} +SSMTP_TLS=${SSMTP_TLS:-"NO"} + +# Timezone +echo "Setting timezone to ${TZ}..." +ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime +echo ${TZ} > /etc/timezone +sed -i -e "s|date\.timezone.*|date\.timezone = ${TZ}|" /etc/php7/php.ini \ + +# Change librenms UID / GID +echo "Checking if librenms UID / GID has changed..." +if [ $(id -u librenms) != ${PUID} ]; then + usermod -u ${PUID} librenms +fi +if [ $(id -g librenms) != ${PGID} ]; then + groupmod -g ${PGID} librenms +fi + +# PHP +echo "Setting PHP-FPM configuration..." +sed -e "s/@MEMORY_LIMIT@/$MEMORY_LIMIT/g" \ + -e "s/@UPLOAD_MAX_SIZE@/$UPLOAD_MAX_SIZE/g" \ + /tpls/etc/php7/php-fpm.d/www.conf > /etc/php7/php-fpm.d/www.conf + +# OpCache +echo "Setting OpCache configuration..." +sed -e "s/@OPCACHE_MEM_SIZE@/$OPCACHE_MEM_SIZE/g" \ + /tpls/etc/php7/conf.d/opcache.ini > /etc/php7/conf.d/opcache.ini + +# Nginx +echo "Setting Nginx configuration..." +sed -e "s/@UPLOAD_MAX_SIZE@/$UPLOAD_MAX_SIZE/g" \ + /tpls/etc/nginx/nginx.conf > /etc/nginx/nginx.conf + +# SSMTP +echo "Setting SSMTP configuration..." +if [ -z "$SSMTP_HOST" ] ; then + echo "WARNING: SSMTP_HOST must be defined if you want to send emails" + cp -f /etc/ssmtp/ssmtp.conf.or /etc/ssmtp/ssmtp.conf +else + cat > /etc/ssmtp/ssmtp.conf <&2 echo "ERROR: DB_HOST must be defined" + exit 1 +fi +cat > ${LIBRENMS_PATH}/config.d/database.php < ${LIBRENMS_PATH}/config.d/fping.php < ${LIBRENMS_PATH}/config.d/autoupdate.php < ${LIBRENMS_PATH}/config.d/email.php < ${LIBRENMS_PATH}/config.d/memcached.php < ${LIBRENMS_PATH}/config.d/rrdcached.php <>" + echo ">> Sidecar cron container detected" + echo ">>" + + # Init + rm -rf ${CRONTAB_PATH} + mkdir -m 0644 -p ${CRONTAB_PATH} + touch ${CRONTAB_PATH}/librenms + + # Add crons + cat ${LIBRENMS_PATH}/librenms.nonroot.cron > ${CRONTAB_PATH}/librenms + sed -i -e "s/ librenms //" ${CRONTAB_PATH}/librenms + sed -i -e "s/poller-wrapper.py 16/poller-wrapper.py ${LIBRENMS_POLLER_THREADS}/g" ${CRONTAB_PATH}/librenms + + # Fix perms + echo "Fixing permissions..." + chmod -R 0644 ${CRONTAB_PATH} +else + # Config : Directories + cat > ${LIBRENMS_PATH}/config.d/directories.php < /dev/null 2>&1; do + sleep 1 + counter=`expr $counter + 1` + if [ ${counter} -gt ${waitdb_timeout} ]; then + >&2 echo "ERROR: Failed to connect to database on $DB_HOST" + exit 1 + fi; + done + echo "Database up!" + + counttables=$(echo 'SHOW TABLES' | ${dbcmd} "$DB_NAME" | wc -l) + + echo "Updating database schema..." + runas_librenms "php build-base.php" + + if [ "${counttables}" -eq "0" ]; then + echo "Creating admin user..." + runas_librenms "php adduser.php librenms librenms 10 librenms@librenms.docker" + fi +fi + +exec "$@" diff --git a/examples/compose/docker-compose.yml b/examples/compose/docker-compose.yml new file mode 100644 index 0000000..0f303a6 --- /dev/null +++ b/examples/compose/docker-compose.yml @@ -0,0 +1,97 @@ +version: '3.2' + +services: + traefik: + image: traefik:1.6-alpine + command: + - --logLevel=INFO + - --defaultentrypoints=http,https + - --entryPoints=Name:http Address::80 Redirect.EntryPoint:https + - --entryPoints=Name:https Address::443 TLS + - --docker + - --docker.exposedbydefault=false + - --docker.domain=example.com + - --acme=true + - --acme.acmelogging=true + - --acme.email=webmaster@example.com + - --acme.storage=acme.json + - --acme.entryPoint=https + - --acme.onhostrule=true + - --acme.httpchallenge=true + - --acme.httpchallenge.entrypoint=http + ports: + - target: 80 + published: 80 + protocol: tcp + mode: host + - target: 443 + published: 443 + protocol: tcp + mode: host + volumes: + - ./acme.json:/acme.json + - /var/run/docker.sock:/var/run/docker.sock + restart: always + + db: + image: mariadb:10.2 + command: + - mysqld + - --sql-mode= + - --innodb-file-per-table=1 + - --lower-case-table-names=0 + volumes: + - db:/var/lib/mysql + environment: + - MYSQL_ALLOW_EMPTY_PASSWORD=yes + - MYSQL_DATABASE=librenms + - MYSQL_USER=librenms + - MYSQL_PASSWORD=asupersecretpassword + restart: always + + memcached: + image: memcached:alpine + restart: always + + rrdcached: + image: crazymax/rrdcached + environment: + - TZ=Europe/Paris + - LOG_LEVEL=LOG_INFO + - WRITE_TIMEOUT=1800 + - WRITE_JITTER=1800 + - WRITE_THREADS=4 + - FLUSH_DEAD_DATA_INTERVAL=3600 + restart: always + + app: + image: crazymax/librenms:latest + depends_on: + - db + - memcached + - rrdcached + volumes: + - librenms:/data + labels: + - traefik.enable=true + - traefik.backend=librenms + - traefik.port=80 + - traefik.frontend.rule=Host:librenms.example.com + env_file: + - ./librenms.env + restart: always + + cron: + image: crazymax/librenms:latest + depends_on: + - app + volumes: + - librenms:/data + command: /usr/local/bin/cron + env_file: + - ./librenms.env + restart: always + +volumes: + db: + librenms: diff --git a/examples/compose/librenms.env b/examples/compose/librenms.env new file mode 100644 index 0000000..681515b --- /dev/null +++ b/examples/compose/librenms.env @@ -0,0 +1,23 @@ +TZ=Europe/Paris + +MEMORY_LIMIT=256M +UPLOAD_MAX_SIZE=16M +OPCACHE_MEM_SIZE=128 + +LIBRENMS_POLLER_THREADS=16 +LIBRENMS_SNMP_COMMUNITY=librenmsdocker + +DB_HOST=db +DB_NAME=librenms +DB_USER=librenms +DB_PASSWORD=asupersecretpassword + +SSMTP_HOST=smtp.example.com +SSMTP_PORT=587 +SSMTP_HOSTNAME=librenms.example.com +SSMTP_USER=smtp@example.com +SSMTP_PASSWORD= +SSMTP_TLS=YES + +MEMCACHED_HOST=memcached +RRDCACHED_HOST=rrdcached