Showing posts with label ARM. Show all posts
Showing posts with label ARM. Show all posts

Tuesday, July 10, 2018

Create your own OVH Server availability checker

Recently I came to know that OVH has a line of storage specific "So You Start"  (SyS) ARM based servers. I have been using a Kimsufi server, but some of these SyS servers are cheaper than the Kimsufi server I have been using. Also the storage available in SyS servers is larger than what I get from the Kimsufi Server for a slightly higher price. Therefore I decided to try a SyS ARM server (ARM-2T/1801armada01)

Unfortunately SyS ARM servers are not always available to order, specially the cheapest servers. I was refreshing their page regularly to order a server, but soon I understood that's not practical. I didn't see they become available in the web page even though I tried many times for several days.

Then I decided to automate the check so that I can order a server whenever they are available.

Fortunately OVH offers a REST API to communicate with their servers and services. It's easier to check the availability of a server sending a http request to their API. Using a bunch of commands, the availability can be checked using a one line Linux command.

Just checking the availability is not enough. There should be a way to notify the availability. I could setup a script to send the availability to an email easily, but I don't read emails often. The best way of doing that is to push a message to my mobile. I found a free service called pushme (pushme.jagcesar.se) which can be used to push a message to my mobile. It also use a REST API, so I can send a message as a http POST request to pushme servers. Then pushme forwards the message to the app installed in the mobile via iCloud.

I created a simple shell script to read the server code as an argument and used it to check the availability of that server type using the OVH REST API. If a server is available, it sends a message to pushme using pushme REST API.

Then the script was scheduled to run for every 5 minutes using a cron job so that I'll get a notification whenever a server is available.

I also created another script to send a test message in every day morning to verify that the availability checker mechanism works.

After a day of implementing this, I was able to purchase the server I wanted. :)
Hope this might help you to find a server as well.
 
Avaiability Checker. It worked!

Screenshot of the notifications I received about 1801armada01 availability

But note that pushme works only with Apple. you will need another message sender if you use Android. Also this is a very simple and lazy way of doing this. No errors are checked in the script and only happy path is considered.

Here are the shell scripts and crons I used,

server_checker.sh

#!/bin/bash

server_code=$1
pushmeapi_token='replace_this_with_your_pushmeapi_token'

availability_count=`curl -s "https://www.ovh.com/engine/api/dedicated/server/availabilities?country=eu&hardware=$server_code" | json_pp | grep availability | grep -v unavailable | wc -l`

if [ $availability_count -gt 0 ]; then
 curl -d "title=found a $server_code&token=$pushmeapi_token" -X POST  https://pushmeapi.jagcesar.se
fi



ping_sender.sh

#!/bin/bash

pushmeapi_token='replace_this_with_your_pushmeapi_token'

curl -d "title=test message&token=$pushmeapi_token" -X POST  https://pushmeapi.jagcesar.se



Cron Jobs

*/5 * * * * /home/seedbox/server_checker.sh 1801sk13
*/5 * * * * /home/seedbox/server_checker.sh 1801armada01
30 5 * * * /home/seedbox/ping_sender.sh


You can find out the server code from either their web page (look at the source of the web page) or using their API.

Examples:

In https://www.soyoustart.com/us/server-storage/ page, when you click ARM-2T, the server code is there at the end of the URL as 1801armada01

below command will provide the list of ARM server types,

curl -s "https://www.ovh.com/engine/api/dedicated/server/availabilities?country=eu" | json_pp | grep hardware | grep -v , | sort | uniq | grep armada

below command will provide the list of kimsufi server types,

curl -s "https://www.ovh.com/engine/api/dedicated/server/availabilities?country=eu" | json_pp | grep hardware | grep -v , | sort | uniq | grep sk



Anyway, here is a list of machine types of kimsufi servers and SyS ARM servers,

Kimsufi Servers

France
KS-1    1801sk12
KS-2    1801sk13
KS-3    1801sk14
KS-4    1801sk15
KS-5    1801sk16
KS-6    1801sk17
KS-7    1801sk18
KS-8    1801sk19
KS-9    1801sk20
KS-10    1801sk21
KS-11    1801sk22
KS-12    1801sk23

Canada
KS-1    1804sk12
KS-2    1804sk13
KS-3    1804sk14
KS-4    1804sk15
KS-5    1804sk16
KS-6    1804sk17
KS-7    1804sk18
KS-8    1804sk19
KS-9    1804sk20
KS-10    1804sk21
KS-11    1804sk22
KS-12    1804sk23

Sys ARM servers

France
ARM-2T    1801armada01
ARM-4T    1801armada02
ARM-6T    1801armada03

Canada
ARM-2T    1804armada01
ARM-4T    1804armada02
ARM-6T    1804armada03

Sunday, December 3, 2017

How to install and configure Kodi on Linux to use NFS and MySQL

Plex and Kodi are very popular media player software. Both of these software have pros and cons in various aspects such as open source vs closed source, free vs paid, server end transcoding vs client end transcoding etc.

When it comes to configurations, Plex is easier to configure than Kodi. However if you are a Linux user, configuring Kodi is not difficult. Actually it is easier than what I thought.

My use case is sharing media files across a LAN. An Espressobin works as the centralized headless media source, a Fedora desktop and an Android Tab as the Kodi clients.

I chose NFS to share the files and MySQL to share the Libraries.

1. Install and configure NFS server on the NAS


I'm using Armbian on my Espressobin, hence the package management tool is apt-get. 

apt-get install nfs-kernel-server

Then I have configured /etc/exports file which is the configuration file for NFS server to share the directory where my media files are.

Methods of configuring this file is explained in Kodi Wiki in detailed manner.
http://kodi.wiki/view/NFS#NFS_sharing_from_Linux

I used option one where all UIDs connected to the NFS server are mapped to UID 65534 (i.e. user nobody)

Content of my /etc/exports file,

root@espressobin:~# cat /etc/exports  | grep -v '#'
/mnt/kodi_test 192.168.8.0/24(rw,all_squash,insecure)


Then I executed exportfs -ra command to refresh the NFS shares.

At this point, the NFS share has been successfully configured.

 

2. Install and configure MySQL server on the NAS


The steps required for this are well documented in the Kodi Wiki,
http://kodi.wiki/view/MySQL/Setting_up_MySQL

In brief the steps are,
  • Install MySQL server,
apt-get install mysql-server

  • Change Bind Address,
Change bind-address in /etc/mysql/mysql.conf.d/mysqld.cnf file

  • Restart MySQL Server,
service mysql restart

  • Execute SQLs to create and configure required database user in MySQL server,
mysql -u root -p

CREATE USER 'kodi' IDENTIFIED BY 'kodi';
GRANT ALL ON *.* TO 'kodi';
flush privileges;


Now I have finished configuring the server side. I have installed and configured NFS and MySQL on my NAS. Now it's time to configure client side. So I installed Kodi on my Fedora desktop.

3. Use MySQL in Kodi


Even though I have created MySQL server and the required MYSQL users on the NAS, Kodi runs on my Desktop must be configured to use the MySQL server.

For that I need to create a XML file called advancedsettings.xml and put it to a directory in each Kodi clients. The directory location is OS specific and the correct location is documented here,
http://kodi.wiki/view/Userdata#Location_of_the_userdata_folder

So I have created my advancedsettings.xml in ~/.kodi/userdata/  in my Fedora desktop machine.

[user@localhost userdata]$ pwd
/home/user/.kodi/userdata


[user@localhost userdata]$ cat advancedsettings.xml
<advancedsettings>
  <videodatabase>
    <type>mysql</type>
    <host>192.168.8.102</host>
    <port>3306</port>
    <user>kodi</user>
    <pass>kodi</pass>
  </videodatabase>
  <musicdatabase>
    <type>mysql</type>
    <host>192.168.8.102</host>
    <port>3306</port>
    <user>kodi</user>
    <pass>kodi</pass>
  </musicdatabase>
  <videolibrary>
    <importwatchedstate>true</importwatchedstate>
    <importresumepoint>true</importresumepoint>
  </videolibrary>
</advancedsettings>


4. Use NFS share in Kodi


I started Kodi on the Fedora desktop and added the NFS share as the media source.

Instruction on adding a shared source is documented here,
http://kodi.wiki/view/Adding_video_sources#Adding_Remote_sources

In brief the steps are,
  • Click on the settings icon
  • Click on Media Settings
  • Click on Library
  • Select  Videos from "Manage Sources"
  • Click on Add Videos
  • Then Click on Browse from "Add Video Source" window
  • Choose Network File System (NFS) option from the drop down

That's it. the Espressobin NAS has been configured,
  • to share content via NFS to Kodi running on devices connected to my LAN
  • to maintain a centralized Kodi library in MySQL server running on the same NAS.

Was that difficult? I don't think so.