- R -v 3.2.0
- Shiny -v latest
- plyr
- RSQLite
- openair
- reshape2
Go to,
https://github.com/davidcarslaw/openair
Type these lines below in R or RStudio console:
require(devtools)
install_github('davidcarslaw/openair')
In case you can't install devtools, run these lines below in your terminal, then run the lines above again in your R's:
$ sudo apt-get -y build-dep libcurl4-gnutls-dev
$ sudo apt-get -y install libcurl4-gnutls-dev
Ref:
- http://stackoverflow.com/questions/30794035/install-packagesdevtools-on-r-3-0-2-fails-in-ubuntu-14-04
- http://stackoverflow.com/questions/20923209/problems-installing-the-devtools-package
Paste these below on your terminal:
$ sudo apt-get install r-base
$ sudo su - \
-c "R -e \"install.packages('shiny', repos='https://cran.rstudio.com/')\""
$ sudo apt-get install gdebi-core
$ wget https://download3.rstudio.org/ubuntu-12.04/x86_64/shiny-server-1.4.1.759-amd64.deb
$ sudo gdebi shiny-server-1.4.1.759-amd64.deb
Now we have the directory structure for our files, but they are owned by our root user. If we want our regular user to be able to modify files in our web directories, we can change the ownership by doing this:
$ sudo chown lau.users /srv/shiny-server/
$ sudo start shiny-server
$ sudo stop shiny-server
$ sudo restart shiny-server
$ sudo su - -c "R -e \"install.packages('plyr', repos='http://cran.rstudio.com/')\""
$ sudo su - -c "R -e \"install.packages('RSQLite', repos='http://cran.rstudio.com/')\""
$ sudo su - -c "R -e \"devtools::install_github('davidcarslaw/openair')\""
$ sudo su - -c "R -e \"install.packages('reshape2', repos='http://cran.rstudio.com/')\""
$ sudo su - -c "R -e \"install.packages('memoise', repos='http://cran.rstudio.com/')\""
$ sudo su - -c "R -e \"install.packages('maps', repos='http://cran.rstudio.com/')\""
The config file for Shiny Server is at /etc/shiny-server/shiny-server.conf.
Ref:
- http://rstudio.github.io/shiny-server/latest/#r-installation-location
- https://www.rstudio.com/products/shiny/download-server/
- http://www.r-bloggers.com/how-to-get-your-very-own-rstudio-server-and-shiny-server-with-digitalocean/
Using command top, we can get the Process ID (PID), CPU/Memory usage for each shiny app.
$ top -u shiny
netstat is a command-line tool that displays all network connections. It can list all connections to a shiny app by specifing its Process ID (PID) using command:
$ sudo netstat -p | grep <PID>
Now, we have known the CPU/Memory performance and connections number for each shiny app, however, we still don’t know the name of each shiny app, which can be get using command lsof:
$ sudo lsof -p <PID> | grep DIR
Ref:
-
Create shiny-system folder via terminal:
$ mkdir /srv/shiny-system/
-
Create cron folder and keep cpu.R in this folder.
-
Start the crontab editor from a terminal window,
$ crontab -e
-
Add entries to your own user's crontab file,
$ * * * * * Rscript /srv/shiny-system/cron/specks/cpu.R $ * * * * * Rscript /srv/shiny-system/cron/fracks/cpu.R
To check what Linux release you are running on your server:
$ cat /etc/*-release
NAME="Arch Linux"
ID=arch
PRETTY_NAME="Arch Linux"
ANSI_COLOR="0;36"
HOME_URL="https://www.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://bugs.archlinux.org/"
You should Arch package manager - pacman to install net-tools:
$ sudo pacman -S net-tools
Install cronie for running cron tasks:
$ sudo pacman -Syu cronie
Then enable it:
$ sudo systemctl enable --now cronie.service
Check its status:
$ systemctl status cronie
Start it:
$ sudo systemctl start crond
[citizensense@localhost ~]$ sudo systemctl enable --now cronie.service
Created symlink from /etc/systemd/system/multi-user.target.wants/cronie.service to /usr/lib/systemd/system/cronie.service.
Ref:
- https://wiki.archlinux.org/index.php/Cron
- https://wiki.archlinux.org/index.php/Systemd/Timers#Management status crond
Set editor to your editor:
$ sudo export EDITOR=vim
Note that adding cron tasks as a user does not work on the production/ live server:
$ crontab -e
* * * * * Rscript /srv/shiny-system/cron/specks/cpu.R
* * * * * Rscript /srv/shiny-system/cron/fracks/cpu.R
~
~
"/tmp/crontab.8VZ7vq" 1 line, 47 characters
On the production server, you should add the cron task as a root or the tasks won't not be executed:
$ sudo crontab -e
* * * * * Rscript /srv/shiny-system/cron/specks/cpu.R
* * * * * Rscript /srv/shiny-system/cron/fracks/cpu.R
~
~
"/tmp/crontab.8VZ7vq" 1 line, 47 characters
Add vim to your crontab editor env that makes it easy to edit the cron tasks:
$ sudo EDITOR=vim crontab -e
You can run the cpu.R manually by type this in your terminal,
$ Rscript /srv/shiny-system/cron/specks/cpu.R
$ Rscript /srv/shiny-system/cron/fracks/cpu.R
Ref:
- https://bbs.archlinux.org/viewtopic.php?id=78700
- https://archlinuxarm.org/forum/viewtopic.php?f=53&t=6281
Check what tasks are running:
$ sudo crontab -l
- Make sure /srv/shiny-system/cron/specks/ folder is set to 777, and cpu.R is set to be executable.
- Make sure /srv/shiny-server/specks/speck<1-4>/ folders are set to 777, and log.txt in each of them is set to to 777.