====== Raspberry Pi 4 ====== {{tag>raspberry_pi rpi}} ===== Python-Pandas-Plotly ===== Path: /workspace/Python-Pandas-Plotly/ docker build -t python-pandas-plotly -f Dockerfile . docker run -d --name Python-Pandas-Plotly -p 5000:5000 -it python-pandas-plotly docker exec -it Python-Pandas-Plotly /bin/bash ===== DB Load and Backup ===== ==== DB Load ==== $ cat /home/pi/fuelwatcher/db_load.sh #!/bin/bash sleep $[ ( $RANDOM % 720 ) + 1 ]s python3 /home/pi/fuelwatcher/rss_download.py >> /home/pi/fuelwatcher/logs/rss_download_`date +%Y-%m-%dT%H-%M-%S`.log python3 /home/pi/fuelwatcher/db_load_file.py >> /home/pi/fuelwatcher/logs/db_load_file_`date +%Y-%m-%dT%H-%M-%S`.log python3 /workspace/fuelwatcher/generate-all.py >> /home/pi/fuelwatcher/logs/generate-all_`date +%Y-%m-%dT%H-%M-%S`.log ; /home/pi/fuelwatcher/file_upload.sh 2>&1 | tee /home/pi/fuelwatcher/logs/file_upload_`date +%Y-%m-%dT%H-%M-%S`.log tail /home/pi/fuelwatcher/logs/*_`date +%Y-%m-%d`*.log >>/tmp/tail_`date +%Y-%m-%d`.txt docker exec FW_PostgreSQL /bin/bash -c /var/lib/postgresql/data/scripts/query.sh >>/tmp/tail_`date +%Y-%m-%d`.txt sleep 20 mail -s "DB Load logs - `date +%Y-%m-%d`" dbload@seanys.com $ cat /home/pi/fuelwatcher/file_upload.sh #!/bin/sh # @author: Alexandre Plennevaux # @description: MIRROR DISTANT FOLDER TO LOCAL FOLDER VIA FTP # @FoundAt: https://gist.github.com/pixeline/0f9f922cffb5a6bba97a # FTP LOGIN HOST='seanys.com' USER='XXXXXXXXXX' PASSWORD='XXXXXXXXXXXXXXX' # DISTANT DIRECTORY REMOTE_DIR='/fueltracker' #LOCAL DIRECTORY LOCAL_DIR='/workspace/fuelwatcher/pages' # RUNTIME! echo echo "Starting upload $REMOTE_DIR from $HOST to $LOCAL_DIR" date lftp -u "$USER","$PASSWORD" $HOST < $ cat /var/lib/docker/volumes/fw_stack_postgres-data/_data/scripts/query.sh #!/bin/bash echo -e "\n\n" echo "SET TIMEZONE='Australia/Perth';SELECT count(*), date FROM fuelwatcher.FUELWATCHER.DATE_PRICE WHERE DATE > CURRENT_DATE AT TIME ZONE '+8' + TIME '06:00' - interval '4 day' group by date ORDER BY date DESC;" | psql fuelwatcher ==== Backup ==== # cat /var/lib/docker/volumes/fw_stack_postgres-data/_data/scripts/backup.sh #!/bin/bash pg_dumpall > /var/lib/postgresql/data/backups/FW_PostgreSQL_all_`date +%Y-%m-%dT%H-%M-%S`.bak $ cat /home/pi/fuelwatcher/pg_backup.sh #!/bin/bash docker exec -it FW_PostgreSQL /bin/bash -c /var/lib/postgresql/data/scripts/backup.sh sudo rsync -av /var/lib/docker/volumes/fw_stack_postgres-data/_data/backups/ /media/usb/backup/postgresql/backups/ # Do we want to gzip all the files? # sudo find . -maxdepth 1 -type f ! -name '*.gz' -exec gzip "{}" \; mail -s "PostgreSQL backup log - `date +%Y-%m-%d`" dbload@seanys.com === Permissions fix === postgres@482ecde1f1c1:/$ ls -la /var/lib/postgresql/data/ drwxr-xr-x 2 root root 4096 Nov 24 16:31 backups root@rpi64:~# rm -Rf /var/lib/docker/volumes/fw_stack_postgres-data/_data/backups/ root@rpi64:~# docker exec -it FW_PostgreSQL /bin/bash postgres@482ecde1f1c1:/$ mkdir /var/lib/postgresql/data/backups postgres@482ecde1f1c1:/$ ls -la /var/lib/postgresql/data/ drwxr-xr-x 2 postgres postgres 4096 Dec 14 04:56 backups === Alternate solution (still incomplete) === /etc/fstab //kargath.local/Backups /workspace/backups cifs credentials=/home/pi/.cifscredz,uid=pi,gid=pi 0 0 ==== crontab ==== $ crontab -l 25 6 * * * /home/pi/fuelwatcher/db_load.sh 00 8 * * * /home/pi/fuelwatcher/pg_backup.sh # FreeDNS update 4,24,44 * * * * sleep 37 ; wget -O - http://freedns.afraid.org/dynamic/update.php?bWhnM3BXVzRmQXhMZEhIcnpTaFFsVUphOjE5MjE0OTE1 >> /tmp/freedns_phlaange_my_to.log 2>&1 ===== NGINX (Cloud) ===== /workspace/Cloud/docker-compose.yml version: '3.8' services: app: image: 'jc21/nginx-proxy-manager:latest' container_name: nginx restart: unless-stopped ports: - '8180:80' - '8181:81' - '8143:443' volumes: - ./data:/data - ./letsencrypt:/etc/letsencrypt Console docker exec -it -u 0 nginx /bin/bash /workspace/Cloud/rebuild #!/bin/bash SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" echo "Script directory: $SCRIPT_DIR" docker ps --format "{{.ID}}\t{{.Names}}" | grep -i nginx | awk '{print $1}' | xargs docker stop docker ps -a --format "{{.ID}}\t{{.Names}}" | grep -i nginx | awk '{print $1}' | xargs docker container rm docker image ls | grep -i nginx | awk '{print $3}'|xargs docker rmi cd $SCRIPT_DIR docker-compose build; docker-compose up -d /workspace/Cloud/reload #!/bin/bash SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" echo "Script directory: $SCRIPT_DIR" docker ps --format "{{.ID}}\t{{.Names}}" | grep -i nginx | awk '{print $1}' | xargs docker stop docker ps -a --format "{{.ID}}\t{{.Names}}" | grep -i nginx | awk '{print $1}' | xargs docker container rm cd $SCRIPT_DIR docker-compose build; docker-compose up -d ===== Mail ===== # apt-get install mailutils ===== exim4 ===== # dpkg-reconfigure exim4-config $ sudo cat /etc/exim4/update-exim4.conf.conf dc_eximconfig_configtype='satellite' dc_other_hostnames='rpi64' dc_local_interfaces='127.0.0.1 ; ::1' dc_readhost='rpi64' dc_relay_domains='' dc_minimaldns='true' dc_relay_nets='' dc_smarthost='mail.seanys.com' CFILEMODE='644' dc_use_split_config='false' dc_hide_mailname='true' dc_mailname_in_oh='true' dc_localdelivery='mail_spool' root@rpi64:~# cat /etc/exim4/ $ sudo cat /etc/exim4/passwd.client # password file used when the local exim is authenticating to a remote # host as a client. # # see exim4_passwd_client(5) for more documentation # # Example: ### target.mail.server.example:login:password seanys.com:seanys:XXXXXXXXXXXXXXXXXXX ==== References ==== * [[https://bobcares.com/blog/exim4-mailing-to-remote-domains-not-supported/|Instant fix for Exim4 ‘mailing to remote domains not supported’ error]] * [[https://serverfault.com/questions/362907/configure-exim-to-use-remote-smtp-with-authentication|Configure exim to use remote smtp with authentication]] ==== DNS Utils ==== sudo apt-get install dnsutils ===== Python bits ===== $ sudo apt-get install python3-pip $ sudo pip3 install config plotly pandas icecream feedparser psycopg2 sqlalchemy ...and maybe $ sudo apt install python3-psycopg2 ===== Mount USB ===== Just skip the "umask" bits. ==== References ==== How to format and mount a USB drive on Raspberry Pi? - [[https://raspberrytips.com/format-mount-usb-drive/]] ===== SWAP resize ===== sudo dphys-swapfile swapoff free total used free shared buff/cache available Mem: 3885396 890640 1523260 76904 1471496 2842400 Swap: 0 0 0 sudo nano /etc/dphys-swapfile sudo dphys-swapfile setup want /var/swap=2048MByte, checking existing: deleting wrong size file (268435456), generating swapfile ... of 2048MBytes sudo dphys-swapfile swapon sudo reboot ===== ZRAM (not used on RPi64) ===== ZRAM is a RAM based compressed, swap mem kernel module # remove the old dphys version $ sudo /etc/init.d/dphys-swapfile stop $ sudo apt-get remove --purge dphys-swapfile # install zram $ sudo wget -O /usr/bin/zram.sh https://raw.githubusercontent.com/novaspirit/rpi_zram/master/zram.sh # set autoload $ sudo nano /etc/rc.local # add the next line before exit 0 /usr/bin/zram.sh & # save with , and $ sudo chmod +x /usr/bin/zram.sh $ sudo nano /usr/bin/zram.sh # alter the limit with * 2 mem=$(( ($totalmem / $cores)* 1024 * 2)) # save with , and $ sudo reboot ===== Docker and Docker-Compose ===== curl -sSL https://get.docker.com | sh sudo usermod -aG docker pi sudo apt-get install libffi-dev libssl-dev sudo apt install python3-dev sudo apt-get install -y python3 python3-pip sudo pip3 install docker-compose sudo systemctl enable docker ==== References ==== * Install 64 bit OS on Raspberry Pi 4 + USB boot - https://qengineering.eu/install-raspberry-64-os.html * How To Install Docker and Docker-Compose On Raspberry Pi - https://dev.to/elalemanyo/how-to-install-docker-and-docker-compose-on-raspberry-pi-1mo ===== Format a USB-connected drive ===== fdisk /dev/sdb mkfs -t ext4 /dev/sdb1 mount /dev/sdb1 /media/ssd/ ==== References ==== * Mount ext4 USB flash drive to Raspberry Pi - https://gordonlesti.com/mount-ext4-usb-flash-drive-to-raspberry-pi/ * Disk Inspector: Retrieving and setting hard drive parameters with hdparm - https://www.linux-magazine.com/Online/Features/Tune-Your-Hard-Disk-with-hdparm ===== Apache2 / PHP ===== ==== Apache 2 ==== apt install apache2 -y usermod -a -G www-data pi chown -R -f www-data:www-data /var/www/html ==== PHP ==== === 7 === apt install php7.4 libapache2-mod-php7.4 php7.4-mbstring php7.4-mysql php7.4-curl php7.4-gd php7.4-zip php7.4-xml -y === 8.1 === curl https://packages.sury.org/php/apt.gpg | sudo tee /usr/share/keyrings/suryphp-archive-keyring.gpg >/dev/null echo "deb [signed-by=/usr/share/keyrings/suryphp-archive-keyring.gpg] https://packages.sury.org/php/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/sury-php.list sudo apt update sudo apt install php8.1-cli ==== References ==== * [[https://pimylifeup.com/raspberry-pi-latest-php/|Installing the Latest Versions of PHP on Raspberry Pi OS]] * [[https://pimylifeup.com/raspberry-pi-apache/|How to Setup a Raspberry Pi Apache Web Server]] * [[https://stackoverflow.com/questions/39820205/class-simplexmliterator-not-found-in-zend-framework-1-when-zf-create-project-zen|Class SimpleXMLIterator not found in zend framework 1 when zf create project ZendApp with PHP7]] ===== GitList ===== wget https://github.com/klaussilveira/gitlist/releases/download/2.0.0/gitlist-2.0.0.zip unzip gitlist-2.0.0.zip cd rsync -av /workspace/PHP/gitlist/* /var/www/html/ mkdir /var/www/html/cache chown www-data.www-data /var/www/html/cache/ nano config.ini-example diff config.ini config.ini-example 4c4 < repositories[] = '/media/usb/repo/' ; Path to your repositories --- > repositories[] = '/home/git/repositories/' ; Path to your repositories ===== Argon ONE ===== ==== ARGON ONE Pi 4 Power Button Functions ==== The following chart will help with the Power button functions. Once the script is installed, it will work with Pi OS 32/64-Bit and within RetroPie. ^ PI 4 STATE ^ ACTION ^ FUNCTION |OFF |Short Press |Turn ON| |ON |Long Press (>= 3s) |Soft Shutdown and Power Cut| |ON |Short press (<3s) |Nothing| |ON |Double tap |Reboot| |ON |Long Press (>= 5s) |Forced Shutdown| ==== Fan control script ==== Installation curl https://download.argon40.com/argon1.sh | bash Run argonone-config -------------------------------------- Argon One Fan Speed Configuration Tool -------------------------------------- WARNING: This will remove existing configuration. Press Y to continue:y Thank you. Select fan mode: 1. Always on 2. Adjust to temperatures (55C, 60C, and 65C) 3. Customize behavior 4. Cancel NOTE: You can also edit /etc/argononed.conf directly Enter Number (1-4):3 Please provide fan speeds and temperature pairs Provide minimum temperature (in Celsius) then [ENTER]:44 Provide fan speed for 44C (0-100) then [ENTER]:20 * Fan speed will be set to 20 once temperature reaches 44 C Provide minimum temperature (in Celsius) then [ENTER]:54 Provide fan speed for 54C (0-100) then [ENTER]:45 * Fan speed will be set to 45 once temperature reaches 54 C Provide minimum temperature (in Celsius) then [ENTER]:65 Provide fan speed for 65C (0-100) then [ENTER]:65 * Fan speed will be set to 65 once temperature reaches 65 C Provide minimum temperature (in Celsius) then [ENTER]:75 Provide fan speed for 75C (0-100) then [ENTER]:100 * Fan speed will be set to 100 once temperature reaches 75 C Provide minimum temperature (in Celsius) then [ENTER]: Thank you! We saved 4 pairs. Changes should take effect now. Settings before and after crash prevention attempt $ cat /etc/argononed.conf # # Argon One Fan Speed Configuration # # Min Temp=Fan Speed 48=15 55=45 65=65 75=100 $ cat /etc/argononed.conf # # Argon One Fan Speed Configuration # # Min Temp=Fan Speed 44=20 54=45 65=65 75=100 ==== References ==== * Install Argon ONE Scripts in Pi OS (32/64-bit) - http://wagnerstechtalk.com/argonone/#Install_Argon_ONE_Scripts_in_Pi_OS_3264-bit ===== Azure SQL Edge ===== docker-compose.yml # docker-compose.yml: version: '3' services: mssql: image: mcr.microsoft.com/azure-sql-edge container_name: "MSSQL" user: root restart: always environment: ACCEPT_EULA: Y MSSQL_SA_PASSWORD: GRoup--22 volumes: - ./data/mssql/data/:/var/opt/mssql/data - ./data/mssql/log/:/var/opt/mssql/log - ./data/mssql/secrets/:/var/opt/mssql/secrets ports: - 1433:1433 ==== References ==== * [[https://brjapon.medium.com/setting-up-ubuntu-20-04-arm-64-under-raspberry-pi-4-970654d12696|Part 2: Installing Docker in Raspberry Pi 4]] * [[https://www.williamleme.com/posts/2021/001-sqlserver-on-raspberry-pi/|Running Sql Server on a Raspberry Pi using Docker]] * [[https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-ubuntu?view=sql-server-ver15|Quickstart: Install SQL Server and create a database on Ubuntu]] ===== Temperature reading on Webmin ===== sudo apt install lm-sensors ===== RPiMonitor ===== sudo apt-get install dirmngr sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 2C0D3C0F sudo wget http://goo.gl/vewCLL -O /etc/apt/sources.list.d/rpimonitor.list sudo apt-get update sudo apt-get install rpimonitor sudo /etc/init.d/rpimonitor update ==== Modifications ==== /etc/rpimonitor/data.conf include=/etc/rpimonitor/template/wlan.conf /etc/rpimonitor/template/sdcard.conf ... static.8.source=df /boot/firmware static.8.regexp=\S+\s+(\d+).*\/boot/firmware$ ... dynamic.7.source=df /boot/firmware dynamic.7.regexp=\S+\s+\d+\s+(\d+).*\/boot/firmware$ ... ==== Restart ==== sudo service rpimonitor restart ==== References ==== * [[https://xavierberger.github.io/RPi-Monitor-docs/11_installation.html#installation-from-repository|Installation and upgrade]] * [[https://xavierberger.github.io/RPi-Monitor-docs/31_configuration_examples.html|Configuration examples]] ===== Calibre (stopped, waste of time) ===== /etc/fstab //lordaeron.local/Docs2 /media/media cifs credentials=/home/pi/.smb,uid=pi,gid=pi,vers=1.0 0 0 ==== Add content ==== Beware: copies files into "database" xvfb-run calibredb add /media/media/eBooks/Tintin/ --library-path /media/ssd/calibredb ==== Run server ==== calibre-server --with-library ~/calibre-library ==== References ==== * [[https://timlehr.com/auto-mount-samba-cifs-shares-via-fstab-on-linux/]|Auto-mount Samba / CIFS shares via fstab on Linux] ===== SWAP ===== sudo dphys-swapfile swapoff sudo nano /etc/dphys-swapfile sudo dphys-swapfile swapon ==== References ==== [[https://wpitchoune.net/tricks/raspberry_pi3_increase_swap_size.html|RASPBERRY PI - INCREASE SWAP SIZE]] ===== Fixes ===== * How to fix raspi-config “The splash screen is not installed so cannot be activated” - https://techoverflow.net/2020/06/13/how-to-fix-raspi-config-the-splash-screen-is-not-installed-so-cannot-be-activated/ * STICKY: If you have a Raspberry Pi 4 and are getting bad speeds transferring data to/from USB3.0 SSDs, read this - https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=245931 * [[https://itsfoss.com/disable-ipv6-ubuntu-linux/|How to Disable IPv6 on Ubuntu Linux]] ===== References ===== * [[https://tutorials-raspberrypi.com/raspberry-pi-default-login-password/|List of all Raspberry Pi Default Logins and Passwords]] * [[https://arstech.net/raspberry-pi-4-ubuntu-wifi/|RASPBERRY PI 4 UBUNTU WIFI SETUP]] * [[https://www.raspberrypi-spy.co.uk/2012/09/checking-your-raspberry-pi-board-version/|Checking Raspberry Pi Revision Number & Board Version]] ===== Install logs ===== * [[sendmail]] * [[Install X Window|X Window]] * [[Install exim4|exim4]] * [[apt autoremove 2021-04-26]] * [[RPi 3b+ EEPROM update]] * [[RPi 4 EEPROM update]]