Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

I forget why, but I had issues w/ the other xymon-server container, but mostly I wanted to practice building a service via a Dockerfile from scratch and chose XYMon-Server.

TESTING:

WD=/opt/xymon-server
cd $WD/setup
docker stop xymon-server
docker container rm xymon-server 
echo y | docker image prune
docker build --no-cache . -t="xymon-server"
docker stop xymon-server
docker container rm xymon-server

Notes:

  • I chose to setup /var/log/ as a bind as I noticed it caused XYMon logs to be output to Docker/Portainer. 
  • All you need to do to have regular logs is remove the bind mount from the docker-compose
  • To get it to work, you need that bind-mount and the directory /log/apache2 created before container starts.
WD=/opt/xymon-server 
rm $WD/{default,etc,var,apache2,msmtprc,log} -R
mkdir -p $WD/{setup,default,etc,var,apache2,msmtprc,log,log/apache2} 
cd $WD/setup
docker stop xymon-server
docker container rm xymon-server
echo y | docker image prune
cat << 'EOF' >docker-compose.yaml
version: '3.7'

services:
 xymon-server:
    container_name: xymon-server
    build: .
    image: xymon-server
    hostname: xymon-server
    ports:
      - '8984:80'
      - '1984:1984'
    volumes:
      - type: bind
        source: /opt/xymon-server/default/
        target: /etc/default
      - type: bind
        source: /opt/xymon-server/etc/
        target: /etc/xymon
      - type: bind 
        source: /opt/xymon-server/var/ 
        target: /var/lib/xymon
      - type: bind
        source: /opt/xymon-server/apache2/
        target: /etc/apache2/conf-enabled
      - type: bind
        source: /opt/xymon-server/msmtprc/msmtprc
        target: /etc/msmtprc        
      - type: bind
        source: /opt/xymon-server/log/
        target: /var/log     
     
    environment:
      - 'TZ=${TZ}'

EOF
chmod +x docker-compose.yaml
WD=/opt/xymon-server
cd $WD/setup
cat << 'EOF' >Dockerfile
FROM debian:buster
MAINTAINER FreeSoftwareServers

ARG DEBIAN_FRONTEND=noninteractive
ARG TZ

RUN apt-get update
RUN apt-get install -y xymon msmtp msmtp-mta mailutils tzdata nano
RUN apt-get clean 
ENV TZ=$TZ
RUN date

ENTRYPOINT ["/etc/xymon/xymon_start.sh"]
EOF
chmod +x Dockerfile
cat << 'EOF' >$WD/msmtprc/msmtprc
# Set default values for all following accounts.
defaults
port 587
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt

account gmail
host smtp.gmail.com
from <user>@gmail.com
auth on
user <user>
password <pwd>

# Set a default account
account default : gmail
EOF
chmod +x $WD/msmtprc/msmtprc
cat << 'EOF' >$WD/etc/xymon_start.sh
#!/bin/bash

service xymon start
rm -f /var/run/apache2/apache2.pid
apachectl -DFOREGROUND
EOF
chmod +x $WD/etc/xymon_start.sh

For New Server:

cat << 'EOF' >copyfiles_from_container.sh
#!/bin/bash
echo y | docker image prune
docker stop xymon-server
docker container rm xymon-server
docker build --no-cache . -t="xymon-server"
docker run -d --name xymon-server xymon-server
docker cp xymon-server:/etc/default/. /opt/xymon-server/default/ 
docker cp xymon-server:/etc/xymon/. /opt/xymon-server/etc/
docker cp xymon-server:/var/lib/xymon/. /opt/xymon-server/var/
docker cp xymon-server:/etc/apache2/conf-available/. /opt/xymon-server/apache2/ 
docker stop xymon-server
docker container rm xymon-server
sed -i "s/^CLIENTHOSTNAME.*/CLIENTHOSTNAME=\"xymon-server\"/" /opt/xymon-server/etc/xymon-client
sed -i "s@^127.0.0.1.*@127.0.0.1\txymon-server\t# bbd http://xymon-server/@" /opt/xymon-server/etc/hosts.cfg
EOF
chmod +x copyfiles_from_container.sh
./copyfiles_from_container.sh

For Migration from Packaged to Docker:

cat << 'EOF' >copyfiles_from_host.sh
#!/bin/bash
cp /etc/default/xymon* /opt/xymon-server/default/ 
cp /etc/xymon/* /opt/xymon-server/etc/ -R
cp /var/lib/xymon/* /opt/xymon-server/var/ -R
cp /etc/apache2/conf-available/* /opt/xymon-server/apache2/ -R
EOF
chmod +x copyfiles_from_host.sh
./copyfiles_from_host.sh
cat << 'EOF' >set_permissions.sh
#!/bin/bash
sed -i -e 's/Require local/Require all granted/g' /opt/xymon-server/apache2/xymon.conf
chown :101 /opt/xymon-server/ -R
chmod 775 /opt/xymon-server/ -R
chmod g+s /opt/xymon-server/ -R
EOF
chmod +x set_permissions.sh
./set_permissions.sh
cd $WD/setup
cat << 'EOF'>.env
TZ=America/Whitehorse
EOF
chmod +x .env
WD=/opt/xymon-server/setup
cat << EOF >$WD/xymon-server.service.setup.sh
cat << EOL >/lib/systemd/system/xymon-server.service
[Unit]
Description=xymon-server_Docker
Requires=docker.service network-online.target

[Service]

Restart=on-abnormal
ExecStart=/usr/bin/docker-compose --project-name xymon-server --project-directory $WD -f $WD/docker-compose.yaml up
ExecStop=/usr/bin/docker-compose --project-name xymon-server --project-directory $WD -f $WD/docker-compose.yaml stop

[Install]
WantedBy=multi-user.target
EOL
systemctl enable xymon-server
systemctl restart xymon-server
systemctl status xymon-server
EOF
chmod +x $WD/xymon-server.service.setup.sh
$WD/xymon-server.service.setup.sh
echo 'alias xycli="docker exec -it xymon-server /bin/bash"' >> ~/.bashrc
source ~/.bashrc
systemctl restart xymon-server ; watch systemctl status xymon-server
  • No labels