Skip to content

Commit

Permalink
Add packages
Browse files Browse the repository at this point in the history
  • Loading branch information
mh-superbox committed Feb 14, 2022
1 parent 9fa71de commit 629bf96
Show file tree
Hide file tree
Showing 57 changed files with 694 additions and 53 deletions.
10 changes: 8 additions & 2 deletions Config.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
source "$BR2_EXTERNAL_UNIPI_PATH/package/unipi_kernel/Config.in"
source "$BR2_EXTERNAL_UNIPI_PATH/package/unipi_tools/Config.in"
source "$BR2_EXTERNAL_UNIPI_PATH/package/python-asyncio-mqtt/Config.in"
source "$BR2_EXTERNAL_UNIPI_PATH/package/python-rich/Config.in"
source "$BR2_EXTERNAL_UNIPI_PATH/package/unipi-control/Config.in"
source "$BR2_EXTERNAL_UNIPI_PATH/package/unipi-kernel/Config.in"
source "$BR2_EXTERNAL_UNIPI_PATH/package/unipi-tools/Config.in"
source "$BR2_EXTERNAL_UNIPI_PATH/package/zsh-autosuggestions/Config.in"
source "$BR2_EXTERNAL_UNIPI_PATH/package/zsh-history-substring-search/Config.in"
source "$BR2_EXTERNAL_UNIPI_PATH/package/zsh-syntax-highlighting/Config.in"
4 changes: 4 additions & 0 deletions board/common/device_table.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# <name> <type> <mode> <uid> <gid> <major> <minor> <start> <inc> <count>
/bin/telegram-send-message f 755 0 0 - - - - -
/etc/monit/monitrc f 700 0 0 - - - - -
/root/id_ed25519_github f 600 0 0 - - - - -
6 changes: 6 additions & 0 deletions board/common/post-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ mkdir -p ${TARGET_DIR}/etc/systemd/system/multi-user.target.wants
# Enable resize root systemd service
ln -fs ../resize-root.service ${TARGET_DIR}/etc/systemd/system/multi-user.target.wants/resize-root.service

# Enable monit systemd service
ln -fs ../resize-root.service ${TARGET_DIR}/etc/systemd/system/multi-user.target.wants/monit.service

# Disable owftpd
ln -fs /dev/null ${TARGET_DIR}/etc/systemd/system/owftpd.service

# Change Loglevel
grep -qE ' loglevel=3' ${BINARIES_DIR}/rpi-firmware/cmdline.txt || sed -i '$ s/$/ loglevel=3/' ${BINARIES_DIR}/rpi-firmware/cmdline.txt

Expand Down
26 changes: 26 additions & 0 deletions board/common/rootfs_overlay/bin/telegram-send-message
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

[ -f /etc/default/telegram ] && . /etc/default/telegram

if [ -z "$TOKEN" ] ; then
echo "TOKEN is not set, please set it in /etc/default/telegram" >&2
exit 1
fi

if [ -z "$CHAT_ID" ] ; then
echo "CHAT_ID is not set, please set it in /etc/default/telegram" >&2
exit 1
fi

SEND_MESSAGE="https://api.telegram.org/bot$TOKEN/sendMessage"

if [ $# -lt 2 ] ; then
echo "Usage: $0 -s <text>"
exit 1
fi

case $1 in
-s)
curl -s -X POST "$SEND_MESSAGE" -d parse_mode=Markdown -d chat_id="$CHAT_ID" -d text="$2" > /dev/null 2>&1
;;
esac
5 changes: 5 additions & 0 deletions board/common/rootfs_overlay/etc/default/telegram
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Bot token
TOKEN=""

# User chat id
CHAT_ID=""
8 changes: 8 additions & 0 deletions board/common/rootfs_overlay/etc/monit/conf-available/avahi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
check process avahi with pidfile /var/run/avahi-daemon/pid
group avahi

start program = "/bin/systemctl start avahi-daemon.service" with timeout 60 seconds
stop program = "/bin/systemctl stop avahi-daemon.service"

if failed host 0.0.0.0 port 5353 type udp then exec "/bin/telegram-send-message -s '*[unipi]* Avahi unavailable'"
if 5 restarts within 5 cycles then timeout
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
check program mosquitto.service with path "/bin/systemctl --quiet is-active mosquitto"
group unipi

start program = "/bin/systemctl start mosquitto.service" with timeout 60 seconds
stop program = "/bin/systemctl stop mosquitto.service"

if status != 0 then exec "/bin/telegram-send-message -s '*[unipi]* Mosquitto unavailable!'"
if 5 restarts within 5 cycles then timeout
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
check process sshd with pidfile /var/run/sshd.pid
group system
group sshd

start program = "/bin/systemctl start ssh" with timeout 60 seconds
stop program = "/bin/systemctl start ssh"

if failed host 0.0.0.0 port 22 with protocol ssh then exec "/bin/telegram-send-message -s '*[unipi]* OpenSSH unavailable'"
if 5 restarts with 5 cycles then timeout
26 changes: 26 additions & 0 deletions board/common/rootfs_overlay/etc/monit/conf-available/owfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
check program owhttpd.service with path "/bin/systemctl --quiet is-active owhttpd.service"
group unipi

start program = "/bin/systemctl start owhttpd.service" with timeout 60 seconds
stop program = "/bin/systemctl stop owhttpd.service"

if status != 0 then exec "/bin/telegram-send-message -s '*[unipi]* 1-Wire Webserver unavailable!'"
if 5 restarts within 5 cycles then timeout

check program owserver.service with path "/bin/systemctl --quiet is-active owserver.service"
group unipi

start program = "/bin/systemctl start owserver.service" with timeout 60 seconds
stop program = "/bin/systemctl stop owserver.service"

if status != 0 then exec "/bin/telegram-send-message -s '*[unipi]* 1-Wire Backend Server unavailable!'"
if 5 restarts within 5 cycles then timeout

check program owfs.service with path "/bin/systemctl --quiet is-active owfs.service"
group unipi

start program = "/bin/systemctl start owfs.service" with timeout 60 seconds
stop program = "/bin/systemctl stop owfs.service"

if status != 0 then exec "/bin/telegram-send-message -s '*[unipi]* 1-Wire Filesystem unavailable!'"
if 5 restarts within 5 cycles then timeout
19 changes: 19 additions & 0 deletions board/common/rootfs_overlay/etc/monit/conf-available/system
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
check system $HOST
if loadavg (5min) > 3 then exec "/bin/telegram-send-message -s '*[unipi]* Load 5min greater then 3'"
if loadavg (15min) > 3 then exec "/bin/telegram-send-messag -s '*[unipi]* Load 15min greater then 3'"
if memory usage > 80% for 4 cycles then exec "/bin/telegram-send-messag -s '*[unipi]* Memory usage greater then 80 %'"
if swap usage > 20% for 4 cycles then exec "/bin/telegram-send-message -s '*[unipi]* Swap usage greater then 20 %'"

# Test the user part of CPU usage
if cpu usage (user) > 95% for 2 cycles then exec "/bin/telegram-send-message -s '*[unipi]* CPU (User) greater then 95 %'"

# Test the system part of CPU usage
if cpu usage (system) > 80% for 2 cycles then exec "/bin/telegram-send-message -s '*[unipi]* CPU (System) greater then 80 %'"

# Test the i/o wait part of CPU usage
if cpu usage (wait) > 80% for 2 cycles then exec "/bin/telegram-send-message -s '*[unipi]* CPU (Wait) greater then 80 %'"

# Test CPU usage including user, system and wait. Note that
# multi-core systems can generate 100 % per core
# so total CPU usage can be more than 100 %
if cpu usage > 200% for 4 cycles then exec "/bin/telegram-send-message -s '*[unipi]* CPU greater then 200 %'"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
check program om-telegram-alert.timer with path "/bin/systemctl --quiet is-active om-telegram-alert.timer"
group timers

start program = "/bin/systemctl start om-telegram-alert.timer" with timeout 60 seconds
stop program = "/bin/systemctl stop om-telegram-alert.timer"

if status != 0 then exec "/bin/telegram-send-message -s '*[unipi]* om-telegram-alert.timer unavailable!'"
if 5 restarts within 5 cycles then timeout
26 changes: 26 additions & 0 deletions board/common/rootfs_overlay/etc/monit/conf-available/unipi
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
check program unipitcp.service with path "/bin/systemctl --quiet is-active unipitcp.service"
group unipi

start program = "/bin/systemctl start unipitcp.service" with timeout 60 seconds
stop program = "/bin/systemctl stop unipitcp.service"

if status != 0 then exec "/bin/telegram-send-message -s '*[unipi]* Unipi TCP unavailable!'"
if 5 restarts within 5 cycles then timeout

check program unipicheck.service with path "/bin/systemctl --quiet is-active unipicheck.service"
group unipi

start program = "/bin/systemctl start unipicheck.service" with timeout 60 seconds
stop program = "/bin/systemctl stop unipicheck.service"

if status != 0 then exec "/bin/telegram-send-message -s '*[unipi]* Unipi Check unavailable!'"
if 5 restarts within 5 cycles then timeout

check program unipi-control.service with path "/bin/systemctl --quiet is-active unipi-control.service"
group unipi

start program = "/bin/systemctl start unipi-control.service" with timeout 60 seconds
stop program = "/bin/systemctl stop unipi-control.service"

if status != 0 then exec "/bin/telegram-send-message -s '*[unipi]* Unipi Control unavailable!'"
if 5 restarts within 5 cycles then timeout
1 change: 1 addition & 0 deletions board/common/rootfs_overlay/etc/monit/conf-enabled/avahi
1 change: 1 addition & 0 deletions board/common/rootfs_overlay/etc/monit/conf-enabled/owfs
1 change: 1 addition & 0 deletions board/common/rootfs_overlay/etc/monit/conf-enabled/system
1 change: 1 addition & 0 deletions board/common/rootfs_overlay/etc/monit/conf-enabled/unipi

0 comments on commit 629bf96

Please sign in to comment.