Skip to content

Commit

Permalink
Updated to version 1.0.0 (Git Hub)
Browse files Browse the repository at this point in the history
- Bulding based on official GitHub commit ID's
- Fixed mysql connections problems
- Added Docker-Cloud support
- Fixed tests
  • Loading branch information
pozgo committed Mar 25, 2016
1 parent b3e4cb1 commit 9e01166
Show file tree
Hide file tree
Showing 15 changed files with 457 additions and 2,843 deletions.
24 changes: 15 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
FROM million12/centos-supervisor
FROM million12/nginx-php:php70
MAINTAINER Przemyslaw Ozgo <linux@ozgo.info>

ENV DB_USER=user \
DB_PASS=password \
DB_ADDRESS=127.0.0.1 \
SPINE_VERSION=0.8.8f \
CACTI_COMMIT_HASH=dfba135dbd84f93f30704da824fa52a7df272b65 \
TIMEZONE=UTC

RUN \
yum update --nogpgcheck -y && \
yum install --nogpgcheck -y tar httpd gcc make mariadb-devel net-snmp-devel cacti && \
curl -o /tmp/cacti-spine.tgz http://www.cacti.net/downloads/spine/cacti-spine-0.8.8c.tar.gz && \
rpm --rebuilddb && yum clean all && \
yum install -y rrdtool net-snmp net-snmp-devel net-snmp-utils mariadb-devel cronie && \
git clone https://github.com/Cacti/cacti.git /cacti/ && \
cd /cacti && git checkout ${CACTI_COMMIT_HASH} && \
curl -o /tmp/cacti-spine.tgz http://www.cacti.net/downloads/spine/cacti-spine-${SPINE_VERSION}.tar.gz && \
mkdir -p /tmp/spine && \
tar zxvf /tmp/cacti-spine.tgz -C /tmp/spine --strip-components=1 && \
rm -f /tmp/cacti-spine.tgz && \
cd /tmp/spine/ && ./configure && make && make install && \
echo "date.timezone = UTC" >> /etc/php.ini && \
rm -rf /tmp/spine && \
yum remove -y gcc make tar mariadb-devel && \
yum remove -y gcc mariadb-devel net-snmp-devel && \
yum clean all

ENV DB_USER=user DB_PASS=password DB_ADDRESS=127.0.0.1

COPY container-files /

EXPOSE 80
EXPOSE 80 81 443
34 changes: 26 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
###Cacti Server (CentOS7 + Supervisor)
[Docker Image](https://registry.hub.docker.com/u/polinux/cacti/) with Cacti server using CentOS7 and Supervisor.
Image is using external datbase.

[![Circle CI](https://circleci.com/gh/pozgo/docker-cacti/tree/master.svg?style=svg&circle-token=f36545fc3efb2fa189ce90bd0cda6d19022eddc0)](https://circleci.com/gh/pozgo/docker-cacti/tree/master)
[![GitHub Open Issues](https://img.shields.io/github/issues/pozgo/docker-cacti.svg)](https://github.com/pozgo/docker-cacti/issues)
[![GitHub Stars](https://img.shields.io/github/stars/pozgo/docker-cacti.svg)](https://github.com/pozgo/docker-cacti)
[![GitHub Forks](https://img.shields.io/github/forks/pozgo/docker-cacti.svg)](https://github.com/pozgo/docker-cacti)
[![Stars on Docker Hub](https://img.shields.io/docker/stars/polinux/cacti.svg)](https://hub.docker.com/r/polinux/cacti)
[![Pulls on Docker Hub](https://img.shields.io/docker/pulls/polinux/cacti.svg)](https://hub.docker.com/r/polinux/cacti)
[![Docker Layers](https://badge.imagelayers.io/polinux/cacti:latest.svg)](https://hub.docker.com/r/polinux/cacti)

[![Deploy to Docker Cloud](https://files.cloud.docker.com/images/deploy-to-dockercloud.svg)](https://cloud.docker.com/stack/deploy/?repo=https://github.com/pozgo/docker-cacti/tree/master)

[Docker Image](https://registry.hub.docker.com/u/polinux/cacti/) with Cacti server using [million12/nginx-php]() docker image as base. (HTTP2 and HAProxy SSL termination ready.)
Image is using external datbase and it's build on PHP 7.0.

### Database deployment
To be able to connect to database we would need one to be running first. Easiest way to do that is to use another docker image. For this purpose we will use our [million12/mariadb](https://registry.hub.docker.com/u/million12/mariadb/) image as our database.
Expand All @@ -25,7 +36,13 @@ In this Image you can use environmental variables to connect into external MySQL

`DB_USER` = database user
`DB_PASS` = database password
`DB_ADDRESS` = database address (either ip or domain-name).
`DB_ADDRESS` = database address (either ip or domain-name)
`TIMEZONE` = timezone

### HTTP/2 Support
Container is built with `http/2` support and by default it listens on port `443`.
Make sure you open it on `docker run`.
Port `81` is used by default for load balancing (`HAProxy`) ssl termination.

### Cacti Deployment
Now when we have our database running we can deploy cacti image with appropriate environmental variables set.
Expand All @@ -36,22 +53,23 @@ Example:
-d \
--name cacti \
-p 80:80 \
-p 443:443 \
--env="DB_ADDRESS=database_ip" \
--env="DB_USER=cactiuser" \
--env="DB_PASS=my_password" \
polinux/cacti

### Access Cacti web interface
To log in into cacti for the first time use credentials `admin:admin`. System will ask you to change those when logged in for the firts time.
### Access Cacti web interface
To log in into cacti for the first time use credentials `admin:admin`. System will ask you to change those when logged in for the firts time.

Access web interface under
Access web interface under

[dockerhost.ip/cacti]()
[dockerhost.ip/install]()

Follow the on screen instructions.

## Author

Author: Przemyslaw Ozgo (<linux@ozgo.info>)

---
Expand Down
8 changes: 4 additions & 4 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ dependencies:
test:
override:
- while true; do if grep "You can now connect to this MariaDB Server" -a ${CIRCLE_ARTIFACTS}/db.log; then break; else sleep 1; fi done
- docker run -d --name cacti --link db:cacti.db -p 80:80 --env="DB_ADDRESS=cacti.db" --env="DB_USER=$DB_USER" --env="DB_PASS=$DB_PASS" polinix/cacti
- docker run -d --name cacti --link db:cacti.db -p 80:80 --env="DB_ADDRESS=cacti.db" --env="DB_USER=$DB_USER" --env="DB_PASS=$DB_PASS" polinux/cacti
- docker logs -f cacti | tee -a ${CIRCLE_ARTIFACTS}/cacti.log:
background: true
- while true; do if grep "already running" -a ${CIRCLE_ARTIFACTS}/cacti.log; then break; else sleep 1; fi done
# Check Zabbix Web interface status
- curl -s -L --head http://127.0.0.1/ | grep "HTTP/1.1 200 OK"
- while true; do if grep "Cacti Server UP" -a ${CIRCLE_ARTIFACTS}/cacti.log; then break; else sleep 1; fi done
# Check Cacti Web interface status
- curl -s -L --head http://127.0.0.1/ | grep "HTTP/1.1 200 OK"
9 changes: 9 additions & 0 deletions container-files/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "$DB_ADDRESS";
$database_username = "$DB_USER";
$database_password = "$DB_PASS";
$database_port = "3306";
$database_ssl = false;
$url_path = "/";
118 changes: 93 additions & 25 deletions container-files/config/init/start.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,99 @@
#!/bin/sh

set -e
set -u

# Fix Cron jobs
crontab /etc/import-cron.conf
sed -i -e 's/^#*//' /etc/cron.d/cacti
set -eu
export TERM=xterm
#Export default DB Password
export MYSQL_PWD=$DB_PASS

# Check if Cacti DB exists
if [ STATUS=$(mysqlshow -u $DB_USER -h $DB_ADDRESS cacti) != "cacti" ]; then
mysql -u $DB_USER -h $DB_ADDRESS -e "CREATE DATABASE cacti"
mysql -u $DB_USER -h $DB_ADDRESS -e "GRANT ALL ON cacti.* TO $DB_USER@'%' IDENTIFIED BY '$DB_PASS'"
mysql -u $DB_USER -h $DB_ADDRESS cacti < /etc/cacti/cacti.sql
# Bash Colors
green=`tput setaf 2`
bold=`tput bold`
reset=`tput sgr0`
log() {
if [[ "$@" ]]; then echo "${bold}${green}[LOG `date +'%T'`]${reset} $@";
else echo; fi
}
move_cacti() {
if [ -e "/cacti" ]; then
log "Moving Cacti into Web Directory"
rm -rf /data/www/cacti
mv -f /cacti /data/www/cacti
chown -R www:www /data/www
log "Cacti moved"
fi
}
move_config_files() {
if [ -e "/config.php" ]; then
log "Moving Config files"
mv /config.php /data/www/cacti/include/config.php
mv -f /global.php /data/www/cacti/include/global.php
chown -R www:www /data/www
log "Config files moved"
fi
}
create_db(){
log "Creating Cacti Database"
mysql -u $DB_USER -h $DB_ADDRESS -e "CREATE DATABASE IF NOT EXISTS cacti;"
mysql -u $DB_USER -h $DB_ADDRESS -e "GRANT ALL ON cacti.* TO '$DB_USER'@'%' IDENTIFIED BY '$DB_PASS';"
mysql -u $DB_USER -h $DB_ADDRESS -e "flush privileges;"
log "Database created successfully"
}
import_db() {
log "Importing Database..."
mysql -u $DB_USER -h $DB_ADDRESS cacti < /data/www/cacti/cacti.sql
log "Database Imported successfully"
}
spine_db_update() {
log "Update databse with spine config details"
mysql -u $DB_USER -h $DB_ADDRESS -e "REPLACE INTO cacti.settings SET name='path_spine', value='/usr/local/spine/bin/spine';"
log "Database updated"
}
update_cacti_db_config() {
log "Updating default Cacti config file"
sed -i 's/$DB_ADDRESS/'$DB_ADDRESS'/g' /data/www/cacti/include/config.php
sed -i 's/$DB_USER/'$DB_USER'/g' /data/www/cacti/include/config.php
sed -i 's/$DB_PASS/'$DB_PASS'/g' /data/www/cacti/include/config.php
log "Config file updated with Database credentials"
}
update_spine_config() {
log "Updating Spine config file"
if [ -e "/spine.conf" ]; then
mv -f /spine.conf /usr/local/spine/etc/spine.conf
sed -i 's/$DB_ADDRESS/'$DB_ADDRESS'/g' /usr/local/spine/etc/spine.conf
sed -i 's/$DB_USER/'$DB_USER'/g' /usr/local/spine/etc/spine.conf
sed -i 's/$DB_PASS/'$DB_PASS'/g' /usr/local/spine/etc/spine.conf
log "Spine config updated"
fi
}
update_cron() {
log "Updating Cron jobs"
# Add Cron jobs
crontab /etc/import-cron.conf
log "Crontab updated."
}
set_timezone() {
if [[ $(grep "date.timezone = ${TIMEZONE}" /etc/php.ini) != "date.timezone = ${TIMEZONE}" ]]; then
log "Updating TIMEZONE"
echo "date.timezone = ${TIMEZONE}" >> /etc/php.ini
log "TIMEZONE set to: ${TIMEZONE}"
fi
}
start_crond() {
crond
log "Started cron daemon"
}
# ## Magic Starts Here
move_cacti
move_config_files
# Check Database Status and update if needed
if [[ $(mysql -u "${DB_USER}" -h "${DB_ADDRESS}" -e "show databases" | grep cacti) != "cacti" ]]; then
create_db
import_db
spine_db_update
fi

# Update Cacti config
sed -i 's/$DB_ADDRESS/'$DB_ADDRESS'/g' /etc/cacti/db.php
sed -i 's/$DB_USER/'$DB_USER'/g' /etc/cacti/db.php
sed -i 's/$DB_PASS/'$DB_PASS'/g' /etc/cacti/db.php

update_cacti_db_config
# Update Spine config
sed -i 's/$DB_ADDRESS/'$DB_ADDRESS'/g' /usr/local/spine/etc/spine.conf
sed -i 's/$DB_USER/'$DB_USER'/g' /usr/local/spine/etc/spine.conf
sed -i 's/$DB_PASS/'$DB_PASS'/g' /usr/local/spine/etc/spine.conf

if [ STATUS=$(mysqlshow -u $DB_USER -h $DB_ADDRESS cacti) != "cacti" ]; then
mysql -u $DB_USER -h $DB_ADDRESS -e "REPLACE INTO cacti.settings SET name='path_spine', value='/usr/local/spine/bin/spine'";
fi
update_spine_config
update_cron
set_timezone
start_crond
log "Cacti Server UP."
Loading

0 comments on commit 9e01166

Please sign in to comment.