-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Bulding based on official GitHub commit ID's - Fixed mysql connections problems - Added Docker-Cloud support - Fixed tests
- Loading branch information
Showing
15 changed files
with
457 additions
and
2,843 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "/"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." |
Oops, something went wrong.