Move Process from disconnected SSH session

GNU screen or tmux are great utilities but some times one of your ssh connection is disconnected and process running there vanishes to background on the same pts . My computer running Windows 10 was rebooted due to great windows update active hours settings and there was some apt thing running stopped on some dialog waiting for input.

After some struggle I found about reptyr and that thing saved my day . Just download from https://github.com/nelhage/reptyr .

wget  https://github.com/nelhage/reptyr/archive/reptyr-0.7.0.tar.gz
tar -xzvf reptyr-0.7.0.tar.gz
cd reptyr-reptyr-0.7.0/
make
make install

With minimal Debian web server install above commands installed the reptyr on my machine. Next is few easy steps to get the process moved to new shell session

ps ax | grep myprocess
reptyr PID
......

Get the PID and use this with reptyr command as above . Process for disconnected session will appear from where it was stopped.

Dynamic DNS Raspberry Pi or Linux Systems (domains.google)

Google domains provide excellent Dynamic DNS services free with the hosting for IPv4 and IPv6. In case you have a small web service hosted using dynamic dns this tool can be very helpful for setting up low cost hosting in few minutes. Most of the common Broadband routers these days support on TZO or Dyn.com which are paid services of dyn.com. Create the port forwarding for your broadband or DSL routers to your LAN device IP and the follow the steps.

pi@raspberrypi:~ $ sudo apt update
pi@raspberrypi:~ $ sudo apt insatll ddclient

after successful installation of ddclient edit the configuration file at /etc/ddclient.conf in your favorite editor

# Configuration file for ddclient generated by debconf
# /etc/ddclient.conf
ssl=yes
#protocol=dyndns2
protocol=googledomains
use=web
server=domains.google.com
login=googledomaindyndnslogin
password='autogeneratedpasswordformgoogle'
www.affan.info
daemon=100

Protocol is used as

protocol=dyndns2
for other dynamic dns servers but for google
protocol=googledomains
works not the first one. its important to set option
use=web
if this option is not set the ddclient will take the local interface ip instead of the actual IP address of your broadband WAN interface.

Raspberry Pi3 

Once configuration is done save the file and restart the client .

pi@raspberrypi:~ $ sudo service ddclient restart
. To verify the setup and ip run the following command
pi@raspberrypi:~ $ sudo ddclient -query
. Match the output ip with your google domain console.

Empowering the Home Hypervisor Server with VirtualBox

As an IT enthusiast one now a days one must keep some test infrastructure to test and play the IT stuff. Running a virtual machine normally is the easiest way to do this but it have some limitations if it is to be done in a cost effective way. either you have to run a pro versions of Microsoft Windows 8+ on your system or buy some thing from vmware. A good alternative is open source VirtualBox which is limited in some features related to remote management. phpVirtualBox give a nice power to VirtualBox making it possible to run headless Virtual Machines and manage those remotely from any where just using a web browser.
Here is the simple how-to the way I achieved this in my home network making it possible to run all my guest vms which can be managed from any where from a web browser.
Installing phpVirtualBox:
Install VirtualBox and Add-on tools on your windows machine as normal.After the successful installation of VirtualBox we need to install service required to manage the auto start the virtual machine on time of system reboot or shutdown.
Download and install open source sotware VBoxVmService form VboxVmService . Install the service as described .
Edit the VBoxVmService.ini file located in the installation folder of VBoxVmService i.e. c:\vms with basic required settings for the VirtualBox and your headless VM as below

[Settings]
VBOX_USER_HOME=C:\Users\MyUser\.VirtualBox
RunWebService=yes
PauseShutdown=5000
[Vm0]
VmName=MyFirstVM
ShutdownMethod=savestate
AutoStart=yes

Save the VBoxVmService.ini and restart the computer.
Install IIS and PHP on your machine using Microsoft Web Platform Installer.
Download phpVirtualBox from the project website phpVirtualBox. Extract the phpVirtualBox to an appropriate location and in IIS Manager add a virtual directory pointing to phpVirtualBox directory location . Add Basic and Windows Authentication Methods in IIS features if not installed before as this will be the security measure being used which will be discussed later in this article.
Go to phpVirtualBox directory and save config.php-sample as “config.php” Edit config.php in any text editor and check for the following values.
 

/* SOAP URL of vboxwebsrv (not phpVirtualBox's URL) */
var $location = 'http://127.0.0.1:18083/';
/* Default language. See languages folder for more language options.
* Can also be changed in File -> Preferences -> Language in
* phpVirtualBox.
*/
var $language = 'en';
/* Set the standard VRDE Port Number / Range, e.g. 1010-1020 or 1027 */
var $vrdeports = '9000-9100';
// Disable authentication
var $noAuth = true;

Note highlighted in line 14 we are disabling the php authentication function as this will be taken care by IIS , in most cases this is the only line you need to change in this file to make this running in windows environment.
At this stage you should be able to view the phpVirtualBox Page by browsing i.e. http://localhost/phpVirtualBox

 
Securing the Web Interface:
now lets move on and secure the newly installed Hypervisor setup . From IIS manager click  to the phpVirtualBox directory and double click the Authentication in IIS Section . Disable anonymous authentication and enable Basic Authentication .

Now go to the phpVirtualBox directory security settings and give read+ write permissions to your windows user on this directory.
Refresh phpVirtualBox link and you will be prompted for user name and password.
if you want to access  this link on internet then its must to run the website on SSL . this can be achieved by creating a self singed certificate in IIS which will be discussed later in some other post.

Connecting NAS to Raspberry Pi

Raspberry Pi is excellent choice to run a low powered fully secure Linux based server . But with the passage of time you experience that the storage on the SD is not enough and some large enough space is required to keep files and backups. USB Hard Drive or a thumb drive could be a work around . Thumb Drive again limit the capacity and USB SATA devices can be hard to manage in terms of physical setup.
Raspberry Pis have 100Mbps ethernet adapter built in which could be used to connect a network drive (NAS) or other file share .
First step is to create the share folder and user on your NAS .  In my case it was WD My Cloud I created user and set a password for that user in NAS.
Mounting the Share to Raspberry Pi
First Login to pi and create a dircetory where we will mount the NAS

pi@raspberrypi:~ $ sudo mkdir /mnt/mycloud

Mount and Test the NAS Share to pi

pi@raspberrypi:~ $ sudo mount -t cifs -o user=pi,passwd=verylongpassword ,rw,file_mode=0777,dir_mode=0777 //192.168.1.10/pi /mnt/mycloud

User  is pi which was created on WD NAS  ie 192.168.1.10 with the password “verylongpassword” but in my case WD My Cloud is not accepting more than 16 characters passwords.
Permanent Mounting
The above command will mount the NAS to pi but it will not be available after reboot. To make this derive permanent we have  to add the settings of the drive in /etc/fstab . Open  fstab with any text editor

pi@raspberrypi:~ $ sudo nano /etc/fstab

 
You will see the list of entries add the last lines as example

roc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
# a swapfile is not a swap partition, no line here
# use dphys-swapfile swap[on|off] for that

Enter the Line in end of file as highlighted

roc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
# a swapfile is not a swap partition, no line here
# use dphys-swapfile swap[on|off] for that
#Mounting the NAS
//192.168.1.10/pi /mnt/mycloud cifs _netdev,user=pi,passwd=verylongpassword,rw,file_mode=0777,dir_mode=0777,iocharset=utf8,comment=systemd.automount 0 0

Hit Ctrl+X and save .
Reboot your Raspbery pi and after login run df -h to see your NAS is mounted on /mnt/mycloud

pi@raspberrypi:~ $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 15G 5.5G 8.6G 39% /
devtmpfs 427M 0 427M 0% /dev
tmpfs 432M 0 432M 0% /dev/shm
tmpfs 432M 6.2M 425M 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 432M 0 432M 0% /sys/fs/cgroup
//192.168.1.10/pi 2.7T 896G 1.9T 33% /mnt/mycloud
/dev/mmcblk0p1 63M 21M 43M 34% /boot
tmpfs 87M 0 87M 0% /run/user/1000

Network Drive Bench Mark
Running a simple benchmark on Network drive shows fair Read and Write Speed over 100Mbps Pi Ethernet . First Highlighted line is for Write and Last one is Read Test.

pi@raspberrypi:/mnt/mycloud $ ./diskbench.sh
dd if=/dev/zero of=test.tst bs=4096 count=100000
100000+0 records in
100000+0 records out
409600000 bytes (410 MB) copied, 34.855 s, 11.8 MB/s
dd if=test.tst of=/dev/null bs=4096 count=100000
100000+0 records in
100000+0 records out
409600000 bytes (410 MB) copied, 36.612 s, 11.2 MB/s