![]() |
|
Rock64 Webserver / NAS project - Printable Version +- PINE64 (https://forum.pine64.org) +-- Forum: ROCK64 (https://forum.pine64.org/forumdisplay.php?fid=85) +--- Forum: Rock64 Hardware and Accessories (https://forum.pine64.org/forumdisplay.php?fid=89) +--- Thread: Rock64 Webserver / NAS project (/showthread.php?tid=5879) |
Rock64 Webserver / NAS project - mikedhoore - 03-21-2018 First, I would like to introduce myself briefly. I am Mike, 26 years old and I’m currently studying at Erasmus University College in Brussels. For a lesson "Trends & Talents" I must develop a project independently that is not given in another lesson. I already started another post before deciding to use this project as my school project ( https://forum.pine64.org/showthread.php?tid=5132 ). The main idea is to build a Linux server with 2 main goals, a web server and a personal NAS(mainly for home use). Web server For now I own a domain name with a web hosting and no SSL. I will install and configure Apache, MariaDB and PHP to run my HTML/PHP website, additional I will install tomcat and java to run my java projects. I will use Let’s encrypt and Certbot to handle the SSL/TLS-certificates to make sure that all the traffic uses the safer HTTPS protocol. NAS Now I own a Netgear Readynas 102 with 2x3TB WD red disks, this to share my files in my home network. My Readynas is synced with a Cloud service through my Laptop. The 2x3TB disk will be connected to the Rock with 2 “USB 3.0 to SATA III HARD DRIVE ADAPTER CABLE/ CONVERTER with UASP” cables connected to a USB 3.0 hub. I will install and configure SAMBA to share the drives in my home network over the Gigabit ethernet port. The drives will be synced to the cloud directly from the Rock (Encrypted or not encrypted, not sure yet) I will use a 4GB version with Debian Stretch Minimal Community Build Image by ayufan. Most of the hardware is already ready and I’m now playing and testing with the software for the last 3 months, step by step I will post the made progress. I will use this board to post my progress and hopefully to receive tips, tricks and feedback from you, the readers, I’ll try to share everything like schematics, scripts and step by step explanation how I installed or configured scripts and/or software. RE: Rock64 Webserver / NAS project - mikedhoore - 03-21-2018 First, I started building the rock64 and all its hardware in a case, I also made a PCB to connect the GPIO pins to additional hardware like a TFT screen, a fan, RGB strips, … (Since there are only 10 images allowed per post I replaced some images by the word Image. I started with making a PVC plate to support the rock64 and other pcb’s. I closed the back openings with a plexiglass plate so that I could screw the extension cord to it. After that I attached the power supply on the bottom plate of the case. With some resistors and transistors I made the RGB led strip to work, with hot glue I made a 45° profile for the RGB strip also have I soldered a cable to the stripes to connect to the self-made PCB. Image Image Build in a 2.4” LCD screen for later on. Making openings in the back plate to attach the extension cords. Image Etching and soldering my own PCB. Image Image Making the power and signal cables myself. Made a plexiglass case to coverup the 220V part. Image Schematics of the PCB Image Download link of the Eagle project : https://mikedhoore.stackstorage.com/s/flyba19r25RlVyX The final result The album to see more photos: https://ibb.co/album/mpWuLa Used hardware ThermalTake Core V1 Case (Amazon.com) PVC and Plexi plates (laying around in my hobby room) 2x 10cm RGB led strip (laying around in my hobby room) Rock64 4GB (Pine64.org) 64GB eMMC (Pine64.org) Serial console (Pine64.org) USB 2.0 male to female extension cable (laying around in my hobby room) Micro SD to eMMC converter (ameridroid.com) Heatsink 20x20x10mm (ebay.com) 50W dual power supply (ebay.com) 2.4” LCD screen (ebay.com) USB 3.0 A to 20 Pin header cable (ebay.com) HDMI extension cable (ebay.com) 2x RJ45 extension cable (ebay.com) Dual USB 2.0 extension cable (ebay.com) USB 3.0 hub (ebay.com) White Nylon spacer M2.5 (ebay.com) White Nylon screw M2.5 (ebay.com) Panel Mount Rocker Switch Fuse Holder Power Socket (ebay.com) 2x 3.5mm power jack for rock64 and usb3.0 hub (laying around in my hobby room) 2x 5.5mm power jack for USB to SATA cable (laying around in my hobby room) 2x USB 3.0 to SATA III CABLE with UASP (Pine64.org) Cables, screws, Heat shrink tubing, … (laying around in my hobby room) Custom made PCB (Made in my school) Used GPIO pins GPIO 1: RGB-strip Red (PWM) (P5+ / pin 10 / GPIO2_B7 / 79) GPIO 2: RGB-strip Green (PWM) (P5+ / pin 12 / GPIO2_C4 / 84) GPIO 3: RGB-strip Blue (PWM) (P5+ / pin 14 / GPIO2_C6 / 86) GPIO 4: FAN (PWM) (P5+ / pin 4 / GPIO2_C2 / 82) GPIO 5: FAN (IN RPM) (P5+ / pin 6 / GPIO2_C3 / 83) GPIO 6: LED Case power (OUT) (P5+ / pin 3 / GPIO2_C1 / 81) GPIO 7: LED Case HDD (OUT) (P5+ / pin 5 / GPIO2_C7 / 87) GPIO 8: Switch Case power (IN) (P5+ / pin 9 / GPIO2_C0 / 80) GPIO 9: Switch Case reset (IN) (P5+ / pin 11 / GPIO2_C5 / 85) GPIO 10: LCD led background (PWM) SPI TXD: LCD SPI RXD: LCD SPI CLK: LCD SPI CSN0: LCD SPI CSN1: LCD UART TX: serial-usb (Pi-2 / pin 8) UART RX: serial-usb (Pi-2 / pin 10) Ethernet RD+ (P5+ / pin 17 ) Ethernet RD- (P5+ / pin 18 ) Ethernet TX+ (P5+ / pin 19 ) Ethernet TX- (P5+ / pin 20 ) 5V (P5+ / pin 2) GND (P5+ / pin 7) 3.3V (P5+ / pin 1) RE: Rock64 Webserver / NAS project - mikedhoore - 03-27-2018 To get started with the rock64 I first did some "Basic" configuration 1) First of all I used etcher to burn the image on the eMMC with a µSD to eMMC converter. etcher : https://www.etcher.io Image : https://github.com/ayufan-rock64/linux-build/releases/latest (i have chosen Stretch minimal) µSD to eMMC : https://ameridroid.com/products/emmc-adapter 2) After that I connected the board to the serial console and opened a terminal with putty Howto connect : https://forum.pine64.org/showthread.php?tid=5029 PuTTY : https://www.putty.org/ 3) Once connected the first thing I did was change the host name HowTo : https://forum.pine64.org/showthread.php?tid=4868&pid=30220#pid30220 Reboot for changes to take effect 4) Then I changed the password for rock64 user and root user For rock64 user : Code: $ passwdCode: $ sudo passwd root5) To make sure I have a fixed IP address I configured following file like this File : /etc/network/interfaces.d/eth0 Code: allow-hotplug eth0
iface eth0 inet static
address 192.168.178.250
netmask 255.255.255.0
gateway 192.168.178.1
dns-nameservers 8.8.8.8 192.168.178.1Code: $ sudo systemctl disable dhcpcd.service6) At last I updated the rock64 with following command to make sure that all services that are running on the system are the latest version Code: $ sudo apt-get update
$ sudo apt-get upgrade So far for the "Basic" configuration RE: Rock64 Webserver / NAS project - tllim - 04-02-2018 PINE64 moderators and developers meet up at Brussels on first week of February annual for FOSDEM event and looking forward to meet up with you on FOSDEM 2019. Keep up on your good work and beer on me. RE: Rock64 Webserver / NAS project - mikedhoore - 04-03-2018 (04-02-2018, 09:44 PM)tllim Wrote: PINE64 moderators and developers meet up at Brussels on first week of February annual for FOSDEM event and looking forward to meet up with you on FOSDEM 2019. Keep up on your good work and beer on me. Thanks I am already looking forward to it and i will certainly be present
RE: Rock64 Webserver / NAS project - mikedhoore - 04-07-2018 After the “Basic” configuration I got started with my webserver part, 1) First, I started installing Apache Code: $ sudo apt install apache22) Once this was working I installed Maria DB to have a database if needed Code: $ sudo apt install mariadb-serverCode: $ sudo mysql_secure_installationSet root password [Y/n] Answer yes and set password Remove anonymous users? [Y/n] Answer yes Disallow root login remotely? [Y/n] Answer yes Remove test DB an access to it? [Y/n] Answer yes Reload privilege tables now? [Y/n] Answer yes You can check this is working with following commands Code: $ sudo mysql – u root -p
MariaDB [(none)]> show database;
MariaDB [(none)]> exit 3) After that I installed PHP with following command Code: $ sudo apt install php7.0 libapache2-mod-php7.0 php7.0-mysql php7.0-gd php7.0-opcacheCode: $ sudo systemctl restart apache2Code: $ sudo rm /var/www/html/index.html
$ sudo nano /var/www/html/index.php
//Add following code in the index.php
<?php phpinfo(); ?> 4) To add some extra security I installed a firewall to block all open ports on the rock Code: $ sudo apt install ufwCode: $ sudo ufw allow 22
$ sudo ufw allow 80
$ sudo ufw allow 443 Code: $ sudo ufw enableCode: $ sudo ufw status verboseUsed resource for 1 to 4 is https://www.cyberciti.biz/faq/how-to-install-linux-apache-mysql-php-lamp-stack-on-debian-9-stretch/ 5) To make access to the database easier I installed phpMyAdmin with following command Code: $ sudo apt install phpMyAdminWeb server to reconfigure? Chose apache2 Config DB for phpMyAdmin with dbconfig-common? Choose Yes Password of the DB admin user Give the root password from MariaDB install MySQL app password for phpMyAdmin Choose a password (this doesn’t need to be same as the root but it can) This completes the installation, then I still had to configure phpMyAdmin to Apache Code: $ sudo nano /etc/apache2/apache2.conf
//Add following code to the bottom of apache2.conf
Include /etc/phpmyadmin/apache.conf Code: $ sudo mysql – u root -p
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit Code: $ sudo /etc/init.d/apache2 restartUsed resource for 5 is https://pimylifeup.com/raspberry-pi-mysql-phpmyadmin/ 6) Most of my projects I write are in Java so I needed to install Java and of course a tomcat server, first of all I started installing Oracle Java on my Rock (at the moment of installing 8u162 was the latest version, u will need to check http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html to see what is now the latest version and change the command accordingly ) Code: $ sudo wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u162-b12/0da788060d494f5095bf8624735fa2f1/jdk-8u162-linux-arm64-vfp-hflt.tar.gz
$ sudo tar -zxvf jdk-8u162-linux-arm64-vfp-hflt.tar.gz
$ sudo mv jdk1.8.0_162/ /usr/
$ sudo rm jdk-8u162-linux-arm64-vfp-hflt.tar.gz
$ sudo update-alternatives --install /usr/bin/java java /usr/jdk1.8.0_162/bin/java 2
$ sudo update-alternatives --config java Code: $ java -versionCode: $ sudo nano /etc/profile
//Added following code to the bottom of /etc/profile
export JAVA_HOME=/usr/jdk1.8.0_162/
export JRE_HOME=/usr/jdk1.8.0_162/jre/
export PATH=$JAVA_HOME/bin:$PATH 7) After installing Java we need a server to run Java projects, I installed tomcat 8 (at the moment of installing v8.5.28 was the latest version, you will need to check http://www-us.apache.org/dist/tomcat/ to see what is now the latest version and change the command accordingly ) I started with making a low-privilege user to run the tomcat service Code: $ sudo groupadd tomcat
$ sudo mkdir /opt/tomcat
$ sudo useradd -g tomcat -d /opt/tomcat -s /bin/nologin tomcat Code: $ sudo wget http://www-us.apache.org/dist/tomcat/tomcat-8/v8.5.28/bin/apache-tomcat-8.5.28.tar.gz
$ sudo tar -zxvf apache-tomcat-*.tar.gz
$ sudo mv apache-tomcat-8.5.28/* /opt/tomcat/
$ sudo rm apache-tomcat-8.5.28.tar.gz
$ sudo chown -R tomcat:tomcat /opt/tomcat/ Code: $ sudo sh /opt/tomcat/bin/startup.sh
//To stop tomcat manual use
$ sudo $ sudo sh /opt/tomcat/bin/shutdown.sh Code: $ sudo nano /etc/systemd/system/tomcat.service
//I added following code to the new file tomcat.service
[Unit]
Description=Apache Tomcat 8.x Web Application Container
Wants=network.target
After=network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/jdk1.8.0_162/
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1G -Djava.net.preferIPv4Stack=true'
Environment='JAVA_OPTS=-Djava.awt.headless=true'
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
SuccessExitStatus=143
User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target Code: $ sudo systemctl daemon-reload
$ sudo systemctl enable tomcat Code: $ sudo systemctl start tomcat
//To see the status of the service I can run the command
$ sudo systemctl status tomcat Code: $ sudo nano /opt/tomcat/conf/tomcat-users.xml
// Add following code just above </tomcat-users>
<role rolename="admin-gui,manager-gui"/>
<user username="admin" password="XXX" roles="manager-gui,admin-gui"/> Code: $ sudo nano /opt/tomcat/webapps/manager/META-INF/context.xml
//Change allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> To
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.178.*" />
$ sudo nano /opt/tomcat/webapps/host-manager/META-INF/context.xml
//Change allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> To
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.178.*" /> Before the changes take effected I needed to restart my tomcat server Code: $ sudo systemctl restart tomcatCode: $ sudo ufw allow 8080
$ sudo ufw reload Used resource for 6 and 7 is https://www.itzgeek.com/how-tos/linux/debian/how-to-install-tomcat-8-5-on-debian-9-ubuntu-16-04-linux-mint-18.html 8) Because I don’t want to let my user surf to mydomain.com:8080 I wanted to link a subdomain to the tomcat server(Java) and my main domain the apache server(html and php), this is done by adding a proxy to mine .conf file in apache Code: $ sudo nano /etc/apache2/sites-available/000-default.conf
//Add following code the bottom of the file
<VirtualHost *:80>
ServerAdmin mike@mikedhoore.be
ServerName java.mikedhoore.be
ServerAlias www.java.mikedhoore.be
ProxyPreserveHost On
# setup the proxy
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost> Code: ServerName mikedhoore.be
ServerAlias www.mikedhoore.be Code: $ sudo a2enmod proxy
$ sudo a2enmod proxy_http
$ sudo service apache2 restart Used resource for 8 https://serverfault.com/questions/195611/how-do-i-redirect-subdomains-to-a-different-port-on-the-same-server So now I have a working apache server that can run HTML and PHP on my main domain and a tomcat server that can run Java on a subdomain, both can access my database and I can easy access my database in a web GUI. At last I also will implement HTTPS access, but I’m waiting for CertBot to implement wildcards in Apache. RE: Rock64 Webserver / NAS project - mikedhoore - 04-21-2018 Ones the webserver was up and running I started installing / configuring my NAS part of my Rock64 project. 1) First, I started by installing 1 HDD to the rock64 over USB 3.0 with the USB3.0 to SATA cable from the web shop here. ( https://www.pine64.org/?product=usb-3-0-to-sata-iii-hard-drive-adapter-cable-converter-with-uasp ) To confirm the drive was recognized I used following command Code: $ lsblkTo get more info about the device and the current partitions I used Code: $ sudo fdisk -l /dev/sdaCode: $ sudo fdisk /dev/sdaCode: m --> To show the full menu
g --> To create a new and empty GPT partition table
n --> To make a new partition
1 --> To give the partition number
enter --> To choose the default first sector
enter --> To choose the default last sector
w --> To save the changes and exitAfter this I still needed to format the partition and choose a filesystem I have chosen for ext4 Code: $ sudo mkfs.ext4 /dev/sda1Code: $ sudo lsblk -fs2) Before I could use the disk it still needed to be mounted, first I made a folder to mount the disk on Code: $ sudo mkdir /media/hdd0Code: $ sudo mount /dev/sda1 /media/hdd0Code: $ lsblkCode: $ sudo chown -R rock64:rock64 /media/hdd0/Used resource for 1 and 2 https://forum.pine64.org/showthread.php?tid=4925 3) Because I want to use the disk as a NAS I needed to share the folder, since I have mostely windows and android machines in my home network I used SMB First of all I installed SAMAB on the Rock64 Code: $ sudo apt-get install sambaCode: $ sudo smbpasswd -a rock64Code: $ sudo nano /etc/samba/smb.conf
// Added following code to the bottom of the file
[hdd0]
path = /media/hdd0
available = yes
valid users = rock64
read only = no
browsable = yes
public = yes
writable = yesCode: $ sudo service smbd restartCode: $ sudo ufw allow samba![]() Used resource for 3 https://www.howtogeek.com/176471/how-to-share-files-between-windows-and-linux/ 4) After a few days I decide to add my second disk to the rock and make a software raid, I shutdown the rock and unplugged the first disk, plugged in a usb3.0 hub and connected the previous disk and the second disk to the hub. Once rebooted I noticed my first disk was now under /dev/sdb and the last connected disk was under /dev/sda. So now I wanted to make a RAID1 but I didn’t want to lose my data on the previous disk. First of all I partitioned the newly added disk Code: $ sudo fdisk /dev/sdaCode: m --> To show the full menu
g --> To create a new and empty GPT partition table
n --> To make a new partition
1 --> To give the partition number
enter --> To choose the default first sector
enter --> To choose the default last sector
w --> To save the changes and exitCode: $ sudo apt-get install mdadmCode: $ sudo mdadm --create /dev/md0 --level=raid1 --raid-devices=2 /dev/sda1 missingCode: $ sudo mkfs.ext4 /dev/md0Code: $ sudo mkdir /media/raidCode: $ sudo mount /dev/md0 /media/raidCode: $ lsblkCode: $ sudo chown -R rock64:rock64 /media/raid/Code: $ sudo cp -a /media/hdd0/ /media/raid/Code: $ sudo fdisk /dev/sdbCode: m --> To show the full menu
g --> To create a new and empty GPT partition table
n --> To make a new partition
1 --> To give the partition number
enter --> To choose the default first sector
enter --> To choose the default last sector
w --> To save the changes and exitCode: $ sudo mdadm /dev/md0 --add /dev/sdb1Code: $ watch cat /proc/mdstatThe only thing I needed to extra was change the /etc/samba/smb.conf file Code: $ sudo nano /etc/samba/smb.conf
// Added following code to the bottom of the file
[raid]
path = /media/raid
available = yes
valid users = rock64
read only = no
browsable = yes
public = yes
writable = yesCode: $ sudo service smbd restartUsed resource for 4 https://unix.stackexchange.com/questions/281654/convert-a-non-boot-single-hdd-to-raid-1-without-deleting-it 5) The disks I used in my rock64 came from an old Readynas 102, now I had the idea to use this readynas as a backup for my Rock. First I installed sshfs Code: $ sudo apt-get install sshfsCode: $ sudo ssh-keygen -t rsaCode: $ sudo ssh-copy-id -I ~/.ssh/id_rsa.pub root@192.168.178.32Code: $ sudo mkdir /media/backupCode: $ sudo sshfs root@192.168.178.32:/data/Backup /media/backup/Code: $ sudo df -hUsed resource for 5 https://www.cyberciti.biz/faq/how-to-mount-remote-directory-filesystems-with-sshfs-on-linux/ 6) I also wanted an off-site backup in the cloud, since my cloud service only support webdav I needed to configure it as a davfs, first of all I installed davfs2 Code: $ sudo apt-get install davfs2Code: $ sudo dpkg-reconfigure davfs2Code: $ sudo usermod -a -G davfs2 root
$ sudo usermod -a -G davfs2 rock64Code: $ sudo nano ~/.davfs2/secrets
// Added following code to the bottom of the file
#Stack by transIP
https://mikedhoore.stackstorage.com/remote.php/webdav mikedhoore MyPassCode: $ sudo chmod 600 /etc/davfs2/secrets
$ sudo chown root:root /etc/davfs2/secretsCode: $ sudo mkdir /media/stackCode: $ sudo mount -t davfs https://mikedhoore.stackstorage.com/remote.php/webdav/ /media/stackCode: $ sudo df -hUsed resource for 6 https://ajclarkson.co.uk/blog/auto-mount-webdav-raspberry-pi/ and https://wiki.archlinux.org/index.php/Davfs2 7) After a reboot the made mounts from raid, backup and stack disappeared so I needed to save them in /etc/fstab Code: $ sudo nano /etc/fstab
// Added following code to the bottom of the file
UUID=f995d3c4-c9e3-48bc-a021-e099200308f6 /media/raid ext4 defaults 0 0
root@192.168.178.32:/data/Backup /media/backup fuse.sshfs delay_connect,_netdev,user,idmap=user,transform_symlinks,identityfile=/home/rock64/.ssh/id_rsa,allow_other,default_permissions,uid=1000,gid=1000 0 0
https://mikedhoore.stackstorage.com/remote.php/webdav/ /media/stack davfs x-systemd.requires=network.target,auto,nouser 0 0Code: $ lsblkCode: $ sudo mount -aUsed resource for 7 https://www.howtogeek.com/howto/38125/htg-explains-what-is-the-linux-fstab-and-how-does-it-work/ 8) Since I only want to back up the files that are changed I used rsync to back up from my rock to my backup server and cloud so I stared by installing rsync. Code: $ sudo apt-get install rsyncCode: $ sudo crontab -e
// Added following code to the bottom of the file
#Rsync every hour from raid(sda1 + sdb1 = md0) to backup(sshfs)
10 * * * * rsync -avzh /media/raid/ /media/backup/ >> /var/log/Mike/rsyncBackup.log
#Rsync every day from raid(sda1 + sdb1 = md0) to Stack cloud
0 3 * * * rsync -avzh /media/raid/ /media/stack/BACKUP_NAS/ >> /var/log/Mike/rsyncStack.logUsed resources for 8 https://www.tecmint.com/rsync-local-remote-file-synchronization-commands/ and https://kvz.io/blog/2007/07/29/schedule-tasks-on-linux-using-crontab/ After all this I now have a working NAS that I can access in my home network over SMB, it also backups on premises and off premises in the cloud. RE: Rock64 Webserver / NAS project - mikedhoore - 04-21-2018 I also written some scripts for the GPIO pins first off all I wrote a script to initialize all the pins that I have connected Code: #!/bin/sh
#RED - RGB-strip
echo 79 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio79/direction
#BIG - Case Button
echo 80 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio80/direction
#POWER - Case Led
echo 81 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio81/direction
#FAN - Case fan
echo 82 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio82/direction
#RPM_FAN - Case fan
echo 83 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio83/direction
#GREEN - RGB-strip
echo 84 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio84/direction
#SMALL - Case Button
echo 85 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio85/direction
#BLUE - RGB-strip
echo 86 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio86/direction
#HDD - Case Button
echo 87 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio87/directionTo test all these pins I also wrote a script Code: #!/bin/bash
#MikeD
#Test all pins in use
LOOPS=5
ON_TIME=.5
OFF_TIME=.25
echo " "
echo " _________________________ "
echo "| |"
echo "| Test script voor I/O |"
echo "| ***** BY MIKE D. **** |"
echo "|-------------------------|"
echo "| ~~ INPUTS ~~ |"
echo "| BIG =" `cat /sys/class/gpio/gpio80/value` " |"
echo "| SMALL =" `cat /sys/class/gpio/gpio85/value` " |"
echo "| RPM_FAN =" `cat /sys/class/gpio/gpio83/value` " |"
echo "| PRESS BIG button |"
while [ `cat /sys/class/gpio/gpio80/value` -gt 0 ]; do
sleep .1
done
echo "| BIG == OK ! |"
echo "| PRESS SMALL button |"
while [ `cat /sys/class/gpio/gpio85/value` -gt 0 ]; do
sleep .1
done
echo "| SMALL == OK ! |"
echo "| Rotate case fan |"
while [ `cat /sys/class/gpio/gpio83/value` -gt 0 ]; do
sleep .1
done
echo "| RPM_FAN == OK |"
echo "|-------------------------|"
echo "| ~~ ALL INPUTS OK ~~ |"
echo "|-------------------------|"
echo "| ~~ OUTPUTS ~~ |"
echo "| RED - RGB-strip |"
read -p "| Press enter to toggle |"
LOOP=0
while [ $LOOP -lt $LOOPS ]; do
echo 1 > /sys/class/gpio/gpio79/value
sleep $ON_TIME
echo 0 > /sys/class/gpio/gpio79/value
sleep $OFF_TIME
LOOP=$(($LOOP+1))
done
echo "| GREEN - RGB-strip |"
read -p "| Press enter to toggle |"
LOOP=0
while [ $LOOP -lt $LOOPS ]; do
echo 1 > /sys/class/gpio/gpio84/value
sleep $ON_TIME
echo 0 > /sys/class/gpio/gpio84/value
sleep $OFF_TIME
LOOP=$(($LOOP+1))
done
echo "| BLUE - RGB-strip |"
read -p "| Press enter to toggle |"
LOOP=0
while [ $LOOP -lt $LOOPS ]; do
echo 1 > /sys/class/gpio/gpio86/value
sleep $ON_TIME
echo 0 > /sys/class/gpio/gpio86/value
sleep $OFF_TIME
LOOP=$(($LOOP+1))
done
echo "| FAN - Case-fan |"
read -p "| Press enter to toggle |"
LOOP=0
while [ $LOOP -lt $LOOPS ]; do
echo 1 > /sys/class/gpio/gpio82/value
sleep $ON_TIME
echo 0 > /sys/class/gpio/gpio82/value
sleep $OFF_TIME
LOOP=$(($LOOP+1))
done
echo "| POWER - Case-led |"
read -p "| Press enter to toggle |"
LOOP=0
while [ $LOOP -lt $LOOPS ]; do
echo 1 > /sys/class/gpio/gpio81/value
sleep $ON_TIME
echo 0 > /sys/class/gpio/gpio81/value
sleep $OFF_TIME
LOOP=$(($LOOP+1))
done
echo "| HDD - Case-led |"
read -p "| Press enter to toggle |"
LOOP=0
while [ $LOOP -lt $LOOPS ]; do
echo 1 > /sys/class/gpio/gpio87/value
sleep $ON_TIME
echo 0 > /sys/class/gpio/gpio87/value
sleep $OFF_TIME
LOOP=$(($LOOP+1))
done
echo "|-------------------------|"
echo "| ~~ ALL OUTPUTS OK ~~ |"
echo "|-------------------------|"
echo "| ***** BY MIKE D. **** |"
echo "|_________________________|"
echo " "At last I wrote a script to power my fan in function of the temperature Code: #!/bin/bash
#MikeD Automatic fan on cpu temp
CHECK_TIME=10 #IN SEC
function pwm(){
LOOP=0
while [ $LOOP -lt $(($CHECK_TIME*75)) ]; do
echo 1 > /sys/class/gpio/gpio82/value
sleep $1
echo 0 > /sys/class/gpio/gpio82/value
sleep $2
LOOP=$(($LOOP+1))
done
}
function fanOff() {
echo 0 > /sys/class/gpio/gpio82/value
sleep $CHECK_TIME
}
function fanTweFiv() {
pwm .025 .075
}
function fanFifty() {
pwm .050 .050
}
function fanSevFiv() {
pwm .075 .025
}
function fanFull() {
echo 1 > /sys/class/gpio/gpio82/value
sleep $CHECK_TIME
}
while [ 1 ]; do
TEMP=$(cat /sys/class/thermal/thermal_zone0/temp)
if [ $TEMP -le 20000 ]
then
fanOff
fi
if [ $TEMP -gt 20000 -a $TEMP -le 25000 ]
then
fanTweFiv
fi
if [ $TEMP -gt 25000 -a $TEMP -le 35000 ]
then
fanFifty
fi
if [ $TEMP -gt 35000 -a $TEMP -le 45000 ]
then
fanSevFiv
fi
if [ $TEMP -gt 45000 ]
then
fanFull
fi
doneRE: Rock64 Webserver / NAS project - tazthecat - 07-19-2018 @ mikedhoore - How stable has this setup been for you? Especially around the x2 hdd's on your USB 3.0 hub? |