Friday, July 27, 2018

Installing PHP7.2 on a Rapsberry Pi - janw.me

Installing PHP7.2 on a Rapsberry Pi

To get a big performance boost we will use PHP 7.1 instead of the older 5.6 which Rasbian still uses by default. But because this is the default we will need to do a few extra tweaks.
In the file /etc/apt/sources.list.d/10-buster.list add
deb http://mirrordirector.raspbian.org/raspbian/ buster main contrib non-free rpi
After saving create the next file sudo nano /etc/apt/preferences.d/10-buster. With the content:
Package: *
Pin: release n=stretch
Pin-Priority: 900

Package: *
Pin: release n=buster
Pin-Priority: 750
Again save. Make the system aware of this source list with
sudo apt update
Now we are ready to install PHP7 with all it’s modules:
sudo apt-get install -y -t buster php7.2-fpm php7.2-curl php7.2-gd php7.2-intl php7.2-mbstring php7.2-mysql php7.2-imap php7.2-opcache php7.2-sqlite3 php7.2-xml php7.2-xmlrpc php7.2-zip php-apcu
When done check it with php -v it should show a PHP 7.2. (or higher).
Now we need to add a few fpm things for nginx to work properly.
sudo nano /etc/php/7.2/fpm/conf.d/90-pi-custom.ini
And add:
cgi.fix_pathinfo=0

upload_max_filesize=64m
post_max_size=64m
max_execution_time=600
Finally reload php
sudo service php7.2-fpm reload
Now PHP is ready to use

Extra

You might want image optimization.
We have installed php-gp for that. But that is not enough.
sudo apt install -y optipng gifsicle libjpeg-progs

Thursday, July 19, 2018

linux - Count files in a directory with filename matching a string - Stack Overflow

linux - Count files in a directory with filename matching a string - Stack Overflow



I suggest to use find as shown below. The reason for that is that filenames may contain newlines which would break a script that is using wc -l. I'm printing just a dot per filename and count the dots with wc -c:
find /some/path/some/dir/ -maxdepth 1 -name 'some_mask_*.txt' -printf '.' | wc -c
or if you want to write the results to variable:
ifiles=$(find /some/path/some/dir/ -maxdepth 1 -name 'some_mask_*.txt' -printf '.' | wc -c)

Friday, July 13, 2018

linux - Run parallel multiple commands at once in the same terminal - Stack Overflow

linux - Run parallel multiple commands at once in the same terminal - Stack Overflow



This bash script is for N parallel threads. Each argument is a command.
trap will kill all subprocesses when SIGINT is catched.
wait $PID_LIST is waiting each process to complete. When all processes have completed, the program exits.
#!/bin/bash

for cmd in "$@"; do {
  echo "Process \"$cmd\" started";
  $cmd & pid=$!
  PID_LIST+=" $pid";
} done

trap "kill $PID_LIST" SIGINT

echo "Parallel processes have started";

wait $PID_LIST

echo
echo "All processes have completed";
Save this script as parallel_commands and make it executable.
This is how to use this script:
parallel_commands "cmd arg0 arg1 arg2" "other_cmd arg0 arg2 arg3"
Example:
parallel_commands "sleep 1" "sleep 2" "sleep 3" "sleep 4"
Start 4 parallel sleep and waits until "sleep 4" finishes.

Sunday, July 01, 2018

aria2 on Raspberry Pi | Installation and Troubleshooting

https://edwinvakkachan.wordpress.com/2018/02/07/aria2-on-raspberry-pi-installation-and-troubleshooting/

Installing aria2 on Raspberry Pi

aria2 is a lightweight multi-protocol & multi-source command-line download utility. It supports HTTP/HTTPS, FTP, SFTP, BitTorrent and Metalink. aria2 can be manipulated via built-in JSON-RPC and XML-RPC interfaces. They said.

Installation:

First thing first, always update your repository.
sudo apt-get update
Next, download aria2.
sudo apt-get install aria2
Now, we make a config file for aria2. First, make the directory for it.
sudo mkdir /home/pi/.aria2
And make the config file.
sudo nano /home/pi/.aria2/aria2.conf
Here’s my configuration, you can always configure it yourself using this guide.
dir=/home/pi/downloads
file-allocation=falloc
continue
log-level=error
max-connection-per-server=4
summary-interval=120
daemon=true
enable-rpc=true
rpc-listen-port=6800
rpc-listen-all=true
max-concurrent-downloads=1
disable-ipv6=true
disk-cache=25M
timeout=600
retry-wait=30
max-tries=50
Now, we make aria2 can run on boot. First, make init.d file.
sudo nano /etc/init.d/aria2
Here’s my script:
#! /bin/sh
# /etc/init.d/aria2
### BEGIN INIT INFO
# Provides: aria2cRPC
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: aria2c RPC init script.
# Description: Starts and stops aria2 RPC services.
### END INIT INFO
RETVAL=0
case “$1” in
start)
echo -n “Starting aria2c daemon ”
umask 0000
aria2c –daemon=true –enable-rpc –rpc-listen-all -D –conf-path=/home/pi/.aria2/aria2.conf
RETVAL=$?
echo
;;
stop)
echo -n “Shutting down aria2c daemon ”
/usr/bin/killall aria2c
RETVAL=$?
echo
;;
restart)
stop
sleep 3
start
;;
*)
echo $”Usage: $0 {start|stop|restart}”
RETVAL=1
esac
exit $RETVAL
Now change aria2’s init.d script permission so it can run as executable.
sudo chmod +x /etc/init.d/aria2
Make aria2 run on boot.
sudo update-rc.d aria2 defaults
Now reboot your Raspberry Pi
sudo shutdown -r now
You can always access aria2 on local network using this webgui provided by ziahamza.
To configure the webgui, go to Setting>Connection Setting.
Enter the host, in this case your Raspberry Pi IP address. And your aria2 port which is inside your aria2.conf, in this case 6800.

Troubleshooting:

1. Download was not successful, download directory are external harddrive
Open aria2.conf and change file-allocation=falloc to file-allocation=none