INT 21h

Hi, I am Vladimir Smagin, SysAdmin. Telegram Email GPG / Микроблог

Nginx unitd in Docker, upload configuration and additional PHP module during image building

№ 9575 В разделе "Администрирование" от November 25th, 2018,

Yes, I know, complete documentation about containerization unitd with predefined config is absent, found examples just uploads config after container start, but not during build. Here’s my own Dockerfile with unitd, php, php-mysql module and uploading project’s configuration during image building.

FROM nginx/unit:1.6-php7.0

LABEL maintainer="21h@blindage.org"
LABEL description="More information here https://blindage.org/?p=9575"

RUN    apt-get ${APT_FLAGS_COMMON} update && \
    apt-get ${APT_FLAGS_PERSISTENT} -y install php7.0-mysql && \
    apt-get ${APT_FLAGS_COMMON} autoremove && \
    apt-get ${APT_FLAGS_COMMON} clean && \
    rm -rf /var/lib/apt/lists/*

COPY config.json /state/new_config.json

WORKDIR /www

COPY index.php .

RUN mkdir preview
RUN chown -R www-data:www-data /www

# upload config to unitd and die
RUN unitd --state /state --pid /tmp/unitd.pid && \
    curl -s -X PUT -d @/state/new_config.json \
         --unix-socket /run/control.unit.sock \
         http://localhost/config/ && \
    kill -9 $(cat /tmp/unitd.pid)

EXPOSE 80

# now container ready to start with predefined config
CMD ["unitd", "--no-daemon", "--state", "/state"]

Нет комментариев »

shroudBNC (sBNC) 1.3.9 in Docker

№ 9569 В разделе "Администрирование" от November 23rd, 2018,

Yes! This is legendary SBNC! Used repositories of Ubuntu 16.04 to get it and build this precious Docker image.

Place in /srv/docker/sbnc/home your predefined config files, it is a user’s home directory and stored in $HOME.

Sample config files:

$HOME/sbnc/sbnc.conf

system.users=vlad
system.port=9000
system.ip=0.0.0.0
system.md5=0

$HOME/sbnc/users/vlad.conf

user.password=myultrasecurepassword
user.server=irc.tomsk.net
user.realname=21h
user.port=6669
user.nick=vlad
user.admin=1
user.seen=1542914743
user.autobacklog=on
user.channels=#linux

Now you are ready to run it:

docker run -d --name sbnc \
    -v /srv/docker/sbnc/home:/var/lib/sbnc \
    -p 9000:9000 \
    --restart=always iam21h/sbnc

DO NOT FORGET TO SET RIGHT FILES PERMISSIONS ON CONFIG DIRECTORIES AND FILES!

Docker HUB https://hub.docker.com/r/iam21h/sbnc/
Source https://git.blindage.org/21h/docker-shroudBNC

Нет комментариев »

Backup MySQL в Docker

№ 9567 В разделе "Администрирование" от November 22nd, 2018,

# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql

# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE

Нет комментариев »

Zabbix: notifications to Telegram

№ 9548 В разделе "Администрирование" от November 15th, 2018,

To receive and forward messages to Telegram you need to install my Telegram-post-bot or use docker image. After this you can create script /usr/lib/zabbix/alertscripts/telegram.sh with this content:

#!/bin/bash
source /etc/profile

json_escape () {
    printf '%s' "$1" | python -c 'import json,sys; print(json.dumps(sys.stdin.read()).strip("\""))'
}

chat_id="-763495760089" # your channel id
post_title=$(json_escape "$1")
post_body=$(json_escape "$2")

echo "{\"chatID\":\"${chat_id}\",\"message\":\"${post_title}\n\n${post_body}\"}" | nc -U /run/telegram-GrapeBlessedBot.sock

You can get your account, group or channel id easily using @get_id_bot.

Now you ready to add new Media type (Administration -> Media types)

Add new media to your account

That’s all folks!

Нет комментариев »

Zabbix: monitor bash script results

№ 9533 В разделе "Администрирование" от November 10th, 2018,

Install zabbix-agent (sometimes zabbix-sender) package to your server that contains zabbix_sender. Now add some exit codes checks after every monitored command.

#!/bin/bash
source /etc/profile
cd /tmp
weekday=$(date '+%w') # 7 days history
monthday=$(date '+%d') # whole month

history=$weekday 

pg_dump postgresql://postgres@127.0.0.1:5432/mydatabase| gzip > db_backup_$history.sql.gz
if [ $? -ne 0 ]
then
    echo "pg_dump failed to dump"
    /usr/bin/zabbix_sender -z zabbix.server.ru -s pg2-server -k pgdumper.dump -o failed
    rm -f db_backup_$history.sql.gz
    exit 1
else
    /usr/bin/zabbix_sender -z zabbix.server.ru -s pg2-server -k pgdumper.dump -o successful
    curl -u ftp_login:ftp_password ftp://ftp.server.ru/postgres-backups/$history/db_backup_$history.sql.gz \
         --ftp-create-dirs -T db_backup_$history.sql.gz
    if [ $? -ne 0 ]
        then
            echo "curl failed to upload dumped file"
            /usr/bin/zabbix_sender -z zabbix.server.ru -s pg2-server -k pgdumper.upload -o failed
            rm -f db_backup_$history.sql.gz
            exit 1
        fi
    /usr/bin/zabbix_sender -z zabbix.server.ru -s pg2-server -k pgdumper.upload -o successful
    rm -f db_backup_$history.sql.gz
fi

Create template

Add your monitored items

And add triggers to raise exceptions

You can combine items in one trigger

Do not forget to activate email notices.

Нет комментариев »

Микроблог перейти

# 2018-11-26 09:15:41

Обнаружил в kubedb код google analytics UA-62096468-20, слежка включена по умолчанию.

# 2018-11-24 23:30:12

Несложно смог контейнеризовать nginx unit с предзагрузкой конфигурации перед стартом контейнера blindage.org/?p=9575


© Vladimir Smagin, 2005-2018. Копирование материалов без разрешения запрещено. GPG 0x29AE91B1A37721C3
Яндекс.Метрика

Fortune cookie: Q: What do you have if you have a moth ball in one hand and a moth ball in the other hand? A: One hell of a big moth!