From fbe65cc9d904e56a0c04936fb3a3e5c11ef7ec1b Mon Sep 17 00:00:00 2001 From: KemoNine Date: Sat, 8 Aug 2020 21:08:40 -0400 Subject: [PATCH] Updates to include rtty, munin, monit, etc --- Dockerfile | 68 +++- piframefleet_run.sh | 30 +- root/etc/cont-init.d/00-welcome | 13 +- root/etc/cont-init.d/30-config | 377 ++++++++++++++++++++--- root/etc/services.d/_service_control/run | 20 -- root/etc/services.d/cron/run | 6 + root/etc/services.d/dashbaord/run | 3 + root/etc/services.d/filebrowser/run | 4 - root/etc/services.d/monit/run | 4 - root/etc/services.d/munin-lighttpd/run | 3 + root/etc/services.d/munin-node/run | 3 + root/etc/services.d/rtty/run | 6 + root/etc/services.d/rttys/run | 4 + root/etc/services.d/syncthing/run | 4 - root/etc/services.d/wireguard/run | 4 - 15 files changed, 439 insertions(+), 110 deletions(-) delete mode 100755 root/etc/services.d/_service_control/run create mode 100755 root/etc/services.d/cron/run create mode 100755 root/etc/services.d/dashbaord/run create mode 100755 root/etc/services.d/munin-lighttpd/run create mode 100755 root/etc/services.d/munin-node/run create mode 100755 root/etc/services.d/rtty/run create mode 100755 root/etc/services.d/rttys/run diff --git a/Dockerfile b/Dockerfile index 5391894..0d91614 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,35 +1,52 @@ FROM ubuntu:latest +# General 'stuff' +VOLUME /opt/pictures +VOLUME /opt/misc +ENV CONFIG_NOTIFY_EMAIL=user@domain.tld +ENV CONFIG_NOTIFY_SMTP_SERVER=mail.domain.tld +ENV CONFIG_NOTIFY_SMTP_USER=user@domain.tld +ENV CONFIG_NOTIFY_SMTP_PASS=apassword + # Ansible related 'stuff' VOLUME /opt/ansible +# rtty 'stuff' +ENV CONFIG_RTTY_USER=admin +ENV CONFIG_RTTY_PASS=apassword +EXPOSE 5913 +VOLUME /opt/rtty + # Monit related 'stuff' -ENV MONIT_CONFIG_USER=admin -ENV MONIT_CONFIG_PASS=apassword +ENV CONFIG_MONIT_USER=admin +ENV CONFIG_MONIT_PASS=apassword EXPOSE 2812/tcp EXPOSE 2811/tcp VOLUME /opt/monit VOLUME /opt/monit-dashboard # Wireguard related 'stuff' -ENV ENABLE_WIREGUARD=false EXPOSE 51820/udp VOLUME /lib/modules VOLUME /opt/wireguard # SyncThing related 'stuff' -ENV ENABLE_SYNCTHING=false EXPOSE 8384/tcp EXPOSE 22000/tcp VOLUME /opt/syncthing # FileBrowser related 'stuff' -ENV ENABLE_FILEBROWSER=false EXPOSE 9191/tcp VOLUME /opt/filebrowser -# General 'stuff' -VOLUME /opt/pictures +# Munin related 'stuff' +VOLUME /opt/munin +EXPOSE 2813 + +# Dashboard related 'stuff' +VOLUME /opt/dashboard +EXPOSE 80 +EXPOSE 443 # Run s6-overlay as the init so we get services and similar ENTRYPOINT [ "/init" ] @@ -44,8 +61,10 @@ WORKDIR /opt/ COPY arch_detect.sh /opt/ # Install and base setup all the things +# The shell has to be bash for asdf to work properly - its needed for rtty and rttys +SHELL ["/bin/bash", "-c"] RUN apt update && apt upgrade -y && \ - apt install -y python3 curl jq bash unzip nano git && \ + apt install -y python3 curl jq bash unzip nano git tmux htop iotop nload && \ ARCH=$(/opt/arch_detect.sh); \ echo "**** Detected arch: $ARCH ****" && \ S6_RELEASE=$(curl -sX GET "https://api.github.com/repos/just-containers/s6-overlay/tags" \ @@ -71,6 +90,33 @@ RUN apt update && apt upgrade -y && \ curl https://bootstrap.pypa.io/get-pip.py -o /opt/get-pip.py && \ python2 /opt/get-pip.py && \ pip install setuptools==40.8.0 xmltodict==0.11.0 requests==2.21.0 xlsxwriter==1.3.2 web.py==0.51 && \ + echo "**** munin related ****" && \ + apt install -y munin lighttpd && \ + echo "**** rtty related ****" && \ + apt install -y libev4 build-essential cmake libev-dev libssl-dev && \ + if [ ! -d "/opt/rtty_build" ] ; then mkdir /opt/rtty_build; fi && \ + cd /opt/rtty_build && \ + mkdir rtty && \ + cd rtty && \ + git clone --recursive https://github.com/zhaojh329/rtty.git . && \ + mkdir build && cd build && \ + cmake .. && make install && \ + cd /opt && \ + mkdir /opt/rtty_build/rttys && \ + cd /opt/rtty_build/rttys && \ + git clone https://github.com/zhaojh329/rttys.git . && \ + git checkout $(git rev-list --tags --max-count=1) && \ + git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.8.0-rc1 && \ + . $HOME/.asdf/asdf.sh && \ + asdf update && \ + asdf plugin add golang && \ + asdf install golang latest && \ + asdf global golang $(asdf latest golang) && \ + go get -u github.com/zhaojh329/rttys && \ + cp ~/.asdf/installs/golang/$(asdf latest golang)/packages/bin/rttys /usr/local/bin/ && \ + cd /opt && \ + echo "**** dashbaord related ****" && \ + apt install -y lighttpd && \ echo "**** syncthing ****" && \ curl -s https://syncthing.net/release-key.txt | apt-key add - && \ echo "deb https://apt.syncthing.net/ syncthing stable" | tee /etc/apt/sources.list.d/syncthing.list && \ @@ -81,12 +127,16 @@ RUN apt update && apt upgrade -y && \ curl -fsSL https://filebrowser.org/get.sh | bash && \ echo "**** ansible ****" && \ apt install -y python3-apt sshpass ansible ansible-lint ansible-doc && \ + echo "**** misc ****" && \ + apt install -y msmtp msmtp-mta ca-certificates && \ echo "**** cleanup ****" && \ rm /opt/arch_detect.sh && \ rm /opt/s6-overlay.tar.gz && \ rm -rf /opt/wireguard-tools && \ + rm -rf /opt/rtty_build && \ + rm -rf ~/.asdf && \ rm /opt/get-pip.py && \ - apt remove --purge -y build-essential pkg-config libelf-dev unzip && \ + apt remove --purge -y build-essential cmake pkg-config libelf-dev libev-dev libssl-dev unzip && \ apt autoremove --purge -y && \ rm -rf /var/lib/apt/lists/* diff --git a/piframefleet_run.sh b/piframefleet_run.sh index 9bd628e..d4b525a 100755 --- a/piframefleet_run.sh +++ b/piframefleet_run.sh @@ -13,23 +13,35 @@ sudo docker run -it \ --cap-add=NET_ADMIN \ --cap-add=SYS_MODULE \ -e TZ=UTC \ - -e MONIT_CONFIG_USER=admin \ - -e MONIT_CONFIG_PASS=apassword \ - -e ENABLE_WIREGUARD=true \ - -e ENABLE_SYNCTHING=true \ - -e ENABLE_FILEBROWSER=true \ + -e CONFIG_NOTIFY_EMAIL=user@domain.tld \ + -e CONFIG_NOTIFY_SMTP_SERVER=email.domain.tld \ + -e CONFIG_NOTIFY_SMTP_USER=user@domain.tld \ + -e CONFIG_NOTIFY_SMTP_PASS=apassword \ + -e CONFIG_RTTY_USER=admin \ + -e CONFIG_RTTY_PASS=apassword \ + -e CONFIG_MONIT_USER=admin \ + -e CONFIG_MONIT_PASS=apassword \ + -p 9080:80/tcp \ + -p 9445:443/tcp \ -p 51821:51821/udp \ -p 8384:8384/tcp \ -p 22000:22000/tcp \ -p 9191:9191/tcp \ -p 2812:2812/tcp \ -p 2811:2811/tcp \ + -p 2813:2813/tcp \ + -p 5912:5912/tcp \ + -p 5913:5913/tcp \ -v /lib/modules:/lib/modules:ro \ - -v /var/piframefleet/syncthing:/opt/syncthing \ - -v /var/piframefleet/filebrowser:/opt/filebrowser \ - -v /var/piframefleet/wireguard:/opt/wireguard \ + -v /var/piframefleet/pictures:/opt/pictures \ + -v /var/piframefleet/misc:/opt/misc \ -v /var/piframefleet/ansible:/opt/ansible \ + -v /var/piframefleet/rtty:/opt/rtty \ -v /var/piframefleet/monit:/opt/monit \ -v /var/piframefleet/monit-dashboard:/opt/monit-dashboard \ - -v /var/piframefleet/pictures:/opt/pictures \ + -v /var/piframefleet/wireguard:/opt/wireguard \ + -v /var/piframefleet/syncthing:/opt/syncthing \ + -v /var/piframefleet/filebrowser:/opt/filebrowser \ + -v /var/piframefleet/munin:/opt/munin \ + -v /var/piframefleet/dashboard:/opt/dashboard \ piframe/piframefleet:latest diff --git a/root/etc/cont-init.d/00-welcome b/root/etc/cont-init.d/00-welcome index 29ec569..7b8e539 100755 --- a/root/etc/cont-init.d/00-welcome +++ b/root/etc/cont-init.d/00-welcome @@ -8,18 +8,13 @@ This container includes the following - Ansible - Monit - Monit-Dashboard + - Munin + - General dashboard of links + - Web terminals - SyncThing - rclone - - FileBrowser (admin/password) + - FileBrowser -------------------------------------" -echo " -------------------------------------- -Service Status - - WireGuard VPN : ${ENABLE_WIREGUARD} - - SyncThing : ${ENABLE_SYNCTHING} - - FileBrowser : ${ENABLE_FILEBROWSER} -------------------------------------- -" if [ -f "/opt/ansible/ssh.key" ] ; then echo " ------------------------------------- diff --git a/root/etc/cont-init.d/30-config b/root/etc/cont-init.d/30-config index d072a69..b3ec94c 100755 --- a/root/etc/cont-init.d/30-config +++ b/root/etc/cont-init.d/30-config @@ -7,6 +7,93 @@ if [ ! -d "/opt/pictures" ] ; then mkdir /opt/pictures fi +#################### +# Email notifications +#################### +if [ ! -d "/opt/misc" ] ; then + mkdir /opt/misc +fi +if [ ! -f "/opt/misc/msmtp.log" ] ; then +touch /opt/misc/msmtp.log +chown root: /opt/misc/msmtp.log +chmod 666 /opt/misc/msmtp.log +fi +if [ ! -f "/opt/misc/aliases" ] ; then +cat > /opt/misc/aliases < /opt/misc/msmtprc < /opt/rtty/rttys.conf < /opt/monit/conf.d/picturesfs < 80% then alert EOF fi -fi #################### # Monit dashboard @@ -81,67 +168,263 @@ cat > conf/servers.json < /opt/munin/munin.conf < /opt/munin/munin-node.conf < /opt/munin/lighttpd-munin.conf < "/munin/" ) + +\$HTTP["url"] =~ "/munin-cgi/munin-cgi-graph" { + alias.url += ( "/munin-cgi/munin-cgi-graph" => "/usr/lib/munin/cgi/munin-cgi-graph" ) + cgi.assign = ( "" => "" ) +} + +alias.url += ( "/munin/static" => "/etc/munin/static" ) +alias.url += ( "/munin" => "/opt/munin/www" ) + +mimetype.assign = ( + ".html" => "text/html", + ".txt" => "text/plain", + ".css" => "text/css", + ".js" => "application/x-javascript", + ".jpg" => "image/jpeg", + ".jpeg" => "image/jpeg", + ".gif" => "image/gif", + ".png" => "image/png", + "" => "application/octet-stream" + ) +EOF +fi +munin-node-configure --shell +s6-svc -r /var/run/s6/munin-node +# Prime the munin values so there isn't a 404 on initial view of page +su - munin --shell=/bin/bash /usr/bin/munin-cron + +#################### +# Dashboard +#################### +if [ ! -d "/opt/dashboard" ] ; then + mkdir /opt/dashboard +fi +if [ ! -f "/opt/dashboard/lighttpd.conf" ] ; then +cat > /opt/dashboard/lighttpd.conf < "text/html", + ".txt" => "text/plain", + ".css" => "text/css", + ".js" => "application/x-javascript", + ".jpg" => "image/jpeg", + ".jpeg" => "image/jpeg", + ".gif" => "image/gif", + ".png" => "image/png", + "" => "application/octet-stream" + ) +EOF +fi +if [ ! -d "/opt/dashboard/wwww" ] ; then +mkdir /opt/dashboard/www +chown www-data /opt/dashboard/www +fi +if [ ! -f "/opt/dashboard/www/index.html" ] ; then +cat > /opt/dashboard/www/index.html < + + +PiFrameFleet + + + +

Command Line

+

Monit Monitoring

+

Munin Monitoring

+

Syncthing Admin Interface

+

Picture File Browser

+ + +EOF +chown www-data /opt/dashboard/www/index.html +fi #################### # WireGuard #################### -if [ "$ENABLE_WIREGUARD" = true ] ; then - ip link del dev test 2>/dev/null - if ip link add dev test type wireguard; then - echo "**** It seems the wireguard module is already active :) ****" - ip link del dev test - else - echo "**** The wireguard module is not active, please install wireguard on the host and activate the 'wg' kernel module ****" - fi - if [ ! -d "/opt/wireguard" ] ; then - mkdir /opt/wireguard - fi +ip link del dev test 2>/dev/null +if ip link add dev test type wireguard; then + echo "**** It seems the wireguard module is already active :) ****" + ip link del dev test +else + echo "**** The wireguard module is not active, please install wireguard on the host and activate the 'wg' kernel module ****" +fi +if [ ! -d "/opt/wireguard" ] ; then + mkdir /opt/wireguard fi #################### # syncthing #################### -if [ "$ENABLE_SYNCTHING" = true ] ; then - if [ ! -d "/opt/syncthing" ]; then - mkdir /opt/syncthing - fi - ST_CONF="/opt/syncthing/config.xml" - if [ ! -f "$ST_CONF" ]; then - echo "**** Initial Syncthing Config ****" - /usr/bin/syncthing -generate /opt/syncthing - sed -i 's/
127.0.0.1:8384<\/address>/
0.0.0.0:8384<\/address>/g' /opt/syncthing/config.xml - sed -i 's///g' /opt/syncthing/config.xml - if [ -d "/root/Sync" ]; then - rm -r /root/Sync - fi +if [ ! -d "/opt/syncthing" ]; then + mkdir /opt/syncthing +fi +ST_CONF="/opt/syncthing/config.xml" +if [ ! -f "$ST_CONF" ]; then + echo "**** Initial Syncthing Config ****" + /usr/bin/syncthing -generate /opt/syncthing + sed -i 's/
127.0.0.1:8384<\/address>/
0.0.0.0:8384<\/address>/g' /opt/syncthing/config.xml + sed -i 's///g' /opt/syncthing/config.xml + if [ -d "/root/Sync" ]; then + rm -r /root/Sync fi fi #################### # FileBrowser #################### -if [ "$ENABLE_FILEBROWSER" = true ] ; then - if [ ! -d "/opt/filebrowser" ]; then - mkdir /opt/filebrowser - fi - FB_DB="/opt/filebrowser/pictures.db" - if [ ! -f "$FB_DB" ]; then - echo "**** Initial FileBrowser Config ****" - filebrowser -d $FB_DB \ - config init 2>&1 > /dev/null - filebrowser -d $FB_DB \ - config set --address 0.0.0.0 2>&1 > /dev/null - filebrowser -d $FB_DB \ - config set --port 9191 2>&1 > /dev/null - filebrowser -d $FB_DB \ - config set --branding.name "PiFrameFleet - Pictures" 2>&1 > /dev/null - filebrowser -d $FB_DB \ - users add admin password 2>&1 > /dev/null - fi +if [ ! -d "/opt/filebrowser" ]; then + mkdir /opt/filebrowser +fi +FB_DB="/opt/filebrowser/pictures.db" +if [ ! -f "$FB_DB" ]; then + echo "**** Initial FileBrowser Config ****" + filebrowser -d $FB_DB \ + config init 2>&1 > /dev/null + filebrowser -d $FB_DB \ + config set --address 0.0.0.0 2>&1 > /dev/null + filebrowser -d $FB_DB \ + config set --port 9191 2>&1 > /dev/null + filebrowser -d $FB_DB \ + config set --branding.name "PiFrameFleet - Pictures" 2>&1 > /dev/null + filebrowser -d $FB_DB \ + users add admin password 2>&1 > /dev/null fi diff --git a/root/etc/services.d/_service_control/run b/root/etc/services.d/_service_control/run deleted file mode 100755 index f8270ff..0000000 --- a/root/etc/services.d/_service_control/run +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/with-contenv bash - -# Only run the services control script (this one) once -# DO NOT IMMEDIATELY DOWN -- NEED TO TERM THE REST OF THE SERVICES FIRST -s6-svc -o /var/run/s6/services/_service_control - -# s6-svc -od means to take down the service and flag it to run AT MOST once -# Service run scripts should check for enablement and immediately exit for this to work well - -if [ "$ENABLE_WIREGUARD" = false ] ; then - s6-svc -od /var/run/s6/services/wireguard -fi - -if [ "$ENABLE_SYNCTHING" = false ] ; then - s6-svc -od /var/run/s6/services/syncthing -fi - -if [ "$ENABLE_FILE_BROWSER" = false ] ; then - s6-svc -od /var/run/s6/services/filebrowser -fi diff --git a/root/etc/services.d/cron/run b/root/etc/services.d/cron/run new file mode 100755 index 0000000..d61723a --- /dev/null +++ b/root/etc/services.d/cron/run @@ -0,0 +1,6 @@ +#!/usr/bin/with-contenv sh + +# this line here is what we should have to get rid of the hard link error +touch /etc/crontab /etc/cron.*/* + +cron -f diff --git a/root/etc/services.d/dashbaord/run b/root/etc/services.d/dashbaord/run new file mode 100755 index 0000000..32fc3c5 --- /dev/null +++ b/root/etc/services.d/dashbaord/run @@ -0,0 +1,3 @@ +#!/usr/bin/with-contenv bash + +/usr/sbin/lighttpd -D -f /opt/dashboard/lighttpd.conf diff --git a/root/etc/services.d/filebrowser/run b/root/etc/services.d/filebrowser/run index 5fd51d5..e4411a7 100755 --- a/root/etc/services.d/filebrowser/run +++ b/root/etc/services.d/filebrowser/run @@ -1,9 +1,5 @@ #!/usr/bin/with-contenv bash -if [ "$ENABLE_FILEBROWSER" = false ] ; then - exit -fi - /usr/local/bin/filebrowser \ -d /opt/filebrowser/pictures.db \ -r /opt/pictures \ diff --git a/root/etc/services.d/monit/run b/root/etc/services.d/monit/run index 86ef417..82e7126 100755 --- a/root/etc/services.d/monit/run +++ b/root/etc/services.d/monit/run @@ -1,9 +1,5 @@ #!/usr/bin/with-contenv bash -if [ ! -f "/opt/monit/monitrc" ] ; then - exit -fi - cd /opt/monit /usr/bin/monit -I \ -c /opt/monit/monitrc diff --git a/root/etc/services.d/munin-lighttpd/run b/root/etc/services.d/munin-lighttpd/run new file mode 100755 index 0000000..1144d84 --- /dev/null +++ b/root/etc/services.d/munin-lighttpd/run @@ -0,0 +1,3 @@ +#!/usr/bin/with-contenv bash + +/usr/sbin/lighttpd -D -f /opt/munin/lighttpd-munin.conf diff --git a/root/etc/services.d/munin-node/run b/root/etc/services.d/munin-node/run new file mode 100755 index 0000000..09ffc5c --- /dev/null +++ b/root/etc/services.d/munin-node/run @@ -0,0 +1,3 @@ +#!/usr/bin/with-contenv bash + +/usr/sbin/munin-node diff --git a/root/etc/services.d/rtty/run b/root/etc/services.d/rtty/run new file mode 100755 index 0000000..8888724 --- /dev/null +++ b/root/etc/services.d/rtty/run @@ -0,0 +1,6 @@ +#!/usr/bin/with-contenv bash + +/usr/local/bin/rtty \ + -f root \ + -I "dispatch" \ + -a diff --git a/root/etc/services.d/rttys/run b/root/etc/services.d/rttys/run new file mode 100755 index 0000000..59ac0d6 --- /dev/null +++ b/root/etc/services.d/rttys/run @@ -0,0 +1,4 @@ +#!/usr/bin/with-contenv bash + +/usr/local/bin/rttys \ + -conf /opt/rtty/rttys.conf diff --git a/root/etc/services.d/syncthing/run b/root/etc/services.d/syncthing/run index de65091..192fae7 100755 --- a/root/etc/services.d/syncthing/run +++ b/root/etc/services.d/syncthing/run @@ -1,9 +1,5 @@ #!/usr/bin/with-contenv bash -if [ "$ENABLE_SYNCTHING" = false ] ; then - exit -fi - /usr/bin/syncthing \ -home="/opt/syncthing" \ -no-browser diff --git a/root/etc/services.d/wireguard/run b/root/etc/services.d/wireguard/run index 4767f09..cb4cc5e 100755 --- a/root/etc/services.d/wireguard/run +++ b/root/etc/services.d/wireguard/run @@ -2,10 +2,6 @@ # Adapted from https://github.com/linuxserver/docker-wireguard -if [ "$ENABLE_WIREGUARD" = false ] ; then - exit -fi - _term() { echo "Caught SIGTERM signal!" wg-quick down /opt/wireguard/wg0.conf