1
0
Fork 0
mirror of https://github.com/librenms/docker.git synced 2026-07-18 00:55:20 +00:00

Initial version based on LibreNMS 1.41

This commit is contained in:
CrazyMax 2018-07-07 13:38:51 +02:00
commit 6f459df0f2
22 changed files with 866 additions and 0 deletions

13
.dockerignore Normal file
View file

@ -0,0 +1,13 @@
/.dev
/.idea
/*.iml
/.git
/.res
/examples
/.editorconfig
/.gitignore
/.travis.yml
/CHANGELOG.md
/LICENSE
/README.md

19
.editorconfig Normal file
View file

@ -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

6
.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
# Jetbrains
/.idea
/*.iml
# App
/.dev

BIN
.res/docker-librenms.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

BIN
.res/paypal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

59
.travis.yml Normal file
View file

@ -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=

5
CHANGELOG.md Normal file
View file

@ -0,0 +1,5 @@
# Changelog
## 1.41-RC1 (2018/07/07)
* Initial version based on LibreNMS 1.41

62
Dockerfile Normal file
View file

@ -0,0 +1,62 @@
FROM alpine:3.8
MAINTAINER CrazyMax <crazy-max@users.noreply.github.com>
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" ]

21
LICENSE Normal file
View file

@ -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.

183
README.md Normal file
View file

@ -0,0 +1,183 @@
<p align="center"><a href="https://github.com/crazy-max/docker-librenms" target="_blank"><img height="128"src="https://raw.githubusercontent.com/crazy-max/docker-librenms/master/.res/docker-librenms.jpg"></a></p>
<p align="center">
<a href="https://microbadger.com/images/crazymax/librenms"><img src="https://images.microbadger.com/badges/version/crazymax/librenms.svg?style=flat-square" alt="Version"></a>
<a href="https://travis-ci.org/crazy-max/docker-librenms"><img src="https://img.shields.io/travis/crazy-max/docker-librenms/master.svg?style=flat-square" alt="Build Status"></a>
<a href="https://hub.docker.com/r/crazymax/librenms/"><img src="https://img.shields.io/docker/stars/crazymax/librenms.svg?style=flat-square" alt="Docker Stars"></a>
<a href="https://hub.docker.com/r/crazymax/librenms/"><img src="https://img.shields.io/docker/pulls/crazymax/librenms.svg?style=flat-square" alt="Docker Pulls"></a>
<a href="https://quay.io/repository/crazymax/librenms"><img src="https://quay.io/repository/crazymax/librenms/status?style=flat-square" alt="Docker Repository on Quay"></a>
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=962TPYQKMQ2UE"><img src="https://img.shields.io/badge/donate-paypal-7057ff.svg?style=flat-square" alt="Donate Paypal"></a>
</p>
## About
🐳 [LibreNMS](https://www.librenms.org/) Docker image based on Alpine Linux and Nginx.<br />
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
<?php
$config['page_refresh'] = "300";
$config['webui']['default_dashboard_id'] = 0;
```
This configuration will be included in LibreNMS and will override the default values.
### Validate
If you want to validate your installation from the CLI, type the following command :
```bash
$ docker exec -it --user librenms librenms php validate.php
====================================
Component | Version
--------- | -------
LibreNMS | 1.41
DB Schema | 253
PHP | 7.2.7
MySQL | 10.2.16-MariaDB-10.2.16+maria~jessie
RRDTool | 1.7.0
SNMP | NET-SNMP 5.7.3
====================================
[OK] Composer Version: 1.6.5
[OK] Dependencies up-to-date.
[OK] Database connection successful
[OK] Database schema correct
[WARN] You have not added any devices yet.
[FIX] You can add a device in the webui or with ./addhost.php
[FAIL] fping6 location is incorrect or bin not installed.
[FIX] Install fping6 or manually set the path to fping6 by placing the following in config.php: $config['fping6'] = '/path/to/fping6';
[WARN] Your install is over 24 hours out of date, last update: Sat, 30 Jun 2018 21:37:37 +0000
[FIX] Make sure your daily.sh cron is running and run ./daily.sh by hand to see if there are any errors.
[WARN] Your local git branch is not master, this will prevent automatic updates.
[FIX] You can switch back to master with git checkout master
```
### Update database
To update the database manually, type the following command :
```bash
$ docker exec -it --user librenms librenms php build-base.php
```
### Cron
If you want to enable the cron job, you have to run a "sidecar" container like in the [docker-compose file](examples/compose/docker-compose.yml) or run a simple container like this :
```bash
docker run -d --name librenms-cron \
--env-file $(pwd)/librenms.env \
-v librenms:/data \
crazymax/librenms:latest /usr/local/bin/cron
```
> `-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:!<br />
The most basic way to show your support is to star :star2: the project, or to raise issues :speech_balloon:<br />
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.

View file

@ -0,0 +1 @@
sendmail_path=/usr/sbin/ssmtp -t

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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;
}
}
}

View file

@ -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

View file

@ -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@

View file

@ -0,0 +1,5 @@
#!/bin/sh
set -e
exec busybox crond -f -L /dev/stdout

205
entrypoint.sh Normal file
View file

@ -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 <<EOL
mailhub=${SSMTP_HOST}:${SSMTP_PORT}
hostname=${SSMTP_HOSTNAME}
FromLineOverride=YES
AuthUser=${SSMTP_USER}
AuthPass=${SSMTP_PASSWORD}
UseTLS=${SSMTP_TLS}
UseSTARTTLS=${SSMTP_TLS}
EOL
fi
# SNMP
echo "Updating SNMP community..."
sed -i -e "s/RANDOMSTRINGGOESHERE/${LIBRENMS_SNMP_COMMUNITY}/" /etc/snmp/snmpd.conf
# Init files and folders
echo "Initializing LibreNMS files / folders..."
mkdir -p ${DATA_PATH}/config \
${DATA_PATH}/logs \
${DATA_PATH}/rrd
rm -f ${LIBRENMS_PATH}/config.d/*
echo "Setting LibreNMS configuration..."
# Config : Database
if [ -z "$DB_HOST" ]; then
>&2 echo "ERROR: DB_HOST must be defined"
exit 1
fi
cat > ${LIBRENMS_PATH}/config.d/database.php <<EOL
<?php
\$config['db_host'] = '${DB_HOST}';
\$config['db_port'] = ${DB_PORT};
\$config['db_user'] = '${DB_USER}';
\$config['db_pass'] = '${DB_PASSWORD}';
\$config['db_name'] = '${DB_NAME}';
EOL
dbcmd="mysql -h ${DB_HOST} -P ${DB_PORT} -u "${DB_USER}" "-p${DB_PASSWORD}""
unset DB_PASSWORD
# Config : Fping
cat > ${LIBRENMS_PATH}/config.d/fping.php <<EOL
<?php
\$config['fping'] = "/usr/sbin/fping";
EOL
# Config : Disable autoupdate
cat > ${LIBRENMS_PATH}/config.d/autoupdate.php <<EOL
<?php
\$config['update'] = 0;
EOL
# Config : Email
cat > ${LIBRENMS_PATH}/config.d/email.php <<EOL
<?php
\$config['email_backend'] = 'mail';
\$config['email_from'] = NULL;
\$config['email_sendmail_path'] = '/usr/sbin/ssmtp -t';
EOL
# Config : Memcached
if [ ! -z "${MEMCACHED_HOST}" ]; then
cat > ${LIBRENMS_PATH}/config.d/memcached.php <<EOL
<?php
\$config['memcached']['enable'] = true;
\$config['memcached']['host'] = '$MEMCACHED_HOST';
\$config['memcached']['port'] = 11211;
EOL
fi
# Config : RRDcached
if [ ! -z "${RRDCACHED_HOST}" ]; then
cat > ${LIBRENMS_PATH}/config.d/rrdcached.php <<EOL
<?php
\$config['rrdcached'] = "${RRDCACHED_HOST}:42217";
EOL
fi
# Sidecar cron container ?
if [ "$1" == "/usr/local/bin/cron" ]; then
echo ">>"
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 <<EOL
<?php
\$config['install_dir'] = '${LIBRENMS_PATH}';
\$config['log_dir'] = '${DATA_PATH}/logs';
\$config['rrd_dir'] = '${DATA_PATH}/rrd';
EOL
# Fix perms
echo "Fixing permissions..."
chown -R librenms. ${DATA_PATH} \
${LIBRENMS_PATH}/config.d \
${LIBRENMS_PATH}/bootstrap \
${LIBRENMS_PATH}/storage
chmod ug+rw ${DATA_PATH}/logs \
${DATA_PATH}/rrd \
${LIBRENMS_PATH}/bootstrap/cache \
${LIBRENMS_PATH}/storage \
${LIBRENMS_PATH}/storage/framework/*
echo "Waiting database..."
waitdb_timeout=30
counter=1
while ! ${dbcmd} -e "show databases;" > /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 "$@"

View file

@ -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:

View file

@ -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