Pages

Παρασκευή 31 Μαΐου 2013

Ubiquity UniFi Controller Software στο Raspberry PiUbiquity UniFi Controller Software on Raspberry Pi

Εισαγωγή

Introduction

Βασικά η ιστορία συνεχίζεται από προηγούμενο άρθρο που βρίσκεται σε αυτό το blog. Για να υπάρξει μια σύνδεση με τα προηγούμενα, θα γίνει μια γενική περιγραφή του προβλήματος. Στη συνέχεια θα δούμε λίγα πράγματα για ένα εργαλείο που θα χρησιμοποιήσουμε (το Raspberry Pi) για τη λύση του προβλήματος και θα προχωρήσουμε στον τρόπο που ακολουθήθηκε για να επιτευχθεί το επιθυμητό αποτέλεσμα.

The story continues from an earlier post posted in the current blog. For clarity and connection to the previously mentioned information, there will be a general description of the problem. Then we will get to know the tool we use in this article (Raspberry Pi) for the solution of the problem and we will present the way we followed to reach our goal.

Επιγραμματικά ακολουθούν:

Briefly:

Το βασικό πρόβλημα

The Problem

Το βασικό κομμάτι που μας ενδιαφέρει εδώ, είναι το στήσιμο ενός δικτύου ξενοδοχείου. Αυτό, με τη σειρά του, συνεπάγεται όλο το καλό πακέτο του ελέγχου σύνδεσης των πελατών, ποσού διακίνησης δεδομένων κ.λ.π. Αυτό το επιτυγχάνουν επαρκώς και με το παραπάνω τα Access Points της Ubiquity. Η χρήση ενός UniFi Outdoor Access Point λύνει όλα τα προβλήματα δικτύωσης. Το μόνο μειονέκτημα (και αυτό που μας απασχολεί στο παρόν άρθρο) είναι πως θα πρέπει να υπάρχει ένα μηχάνημα που να τρέχει το software της εταιρίας για τον έλεγχο και τη διαχείριση του δικτύου. Αυτό με τη σειρά του συνεπάγεται κατανάλωση ενέργειας για PC, θόρυβος από τα ανεμιστηράκια του, απαραίτητη χρήση UPS που να αντέχει σε μεγάλες διακοπές ρεύματος, license του λειτουργικού του συστήματος αν πρόκειται για μηχάνημα που τρέχει Bugindows, συχνές επανεκκινήσεις λόγω των προβλημάρων του αναφερόμενου λειτουργικού κ.λ.π. Ειδικα τα δύο τελευταία προβλήματα (που είναι και τα πιο σημαντικά) λύθηκαν με την εγκατάσταση λειτουργικού Linux και συγκεκριμένα της διανομής openSUSE, όπως φαίνεται και σε άλλο άρθρο του ίδιου blog.

The basic part in question at this point is a network setup for a hotel. This means the whole packet of services for controlling client access, bandwidth limiting per client, data quota etc. For Ubiquity's Access Points this is only part of their capabilities. Usage of a UniFi Outdoor Access Point is the solution for all our networking problems. The only drawback (and what is covered in this article) is the necessity of a computer running the controller software for all the network monitoring and managing, 24 hours a day. And this, in turn, leads to much energy consumption from a PC, noise from its fans, the necessity of UPS usage that is able to keep the system up during long duration power failures, license for its operating system if it runs Bugindows, probably frequently reboots because of this (non) operating system and many more... Especially the two last problems we presented (which are the most important) were solved by installing a Linux distribution; more specifically openSUSE, as presented in a previous article in this blog.

Η λύση των υπολοίπων προβλημάτων διερευνήθηκε περισσότερο για να βρει ο γράφων δουλειά να κάνει (!!! Τι πρωτότυπο :)). Δεν είναι κάτι άλλο από το πασίγνωστο, πλέον στο χώρο των gadgetάκιδων, Raspberry Pi.

The research for solutions to the other problems started just for the author to kill some of his spear time (!!! How rare :)). The research led to, famous in the gadget lovers' cycles, Raspberry Pi.

Raspberry Pi ως server...

Raspberry Pi as a server...

Το Raspberry Pi είναι ένας υπολογιστής, όπως ακριβώς κι ένα κινητό. Η διαφορά του είναι πως δεν έχει οθόνη. Τι διαθέτει αυτός ο υπολογιστής (βασικά χαρακτηριστικά):

Raspberry Pi is a small computer, just like a smartphone. Its difference is the lack of a screen. Part of its specifications are presented:

  • Επεξεργαστής: ARM στα 700MHz, με δυνατότητα Overclocking στο 1GHz
  • Processor: ARM running at 700MHz, with Overclocking capability up to 1GHz
  • Μνήμη: 256 MBytes η παλιά έκδοση (Α), 512 MBytes η έκδοση Β
  • Memory: 256 MBytes at the old version (Α), 512 MBytes at its newer version, Β
  • Ethernet: 10/100 Mbit
  • Video out: Δε μας ενδιαφέρει. Server θέλουμε να το κάνουμε, αλλά ως άχρηστη πληροφορία της ημέρας διαθέτει έξοδο HDMI και TVWe don't care. We want to use it as a server, but as useless information of the day it has HDMI and Composite Video outputs
  • USB: 2 πόρτεςports
  • Boot: από κάρτα μνήμηςfrom an SD Card
  • Τροφοδοσία: 5V με μικρή κατανάλωση ρεύματος (μέγιστη στα 700mA στην έκδοση Β)
  • Power: 5V having small power consumption (maximum 700mA on version Β)

Αυτά τα χαρακτηριστικά το κάνουν ιδανικό για χρήση ως server. Δίνουν, επίσης, τη δυνατότητα να μπορέσει να τροφοδοτηθεί, αργότερα, από ένα σύστημα UPS που να παράγει τα 5V που χρειάζονται απ' ευθείας από τη μπαταρία του. Κατά συνέπεια μια διακοπή της ΔΕΗ για... πολλές ώρες δεν θα το ενοχλήσει :)

These specifications make this thing ideal for making a server. They also give it the ability to be, later, powered by a small UPS system that supplies 5V DC straight from a battery, without the need of inverters and 220V AC. So, a power failure because of the power company for... looong duration won't bother the system :)

Άλλο ένα καλό του εν λόγω gadget είναι πως πάρα πολλές διανομές Linux έχουν στηθεί για το Raspberry Pi· ακόμα και FreeBSD μπορούμε να βρούμε (αν και κανονικά αυτό δεν πρέπει να μας κάνει εντύπωση!). Μιας και την τελευταία φορά που έστησα το σύστημα του UniFi Controller ήταν επάνω σε openSUSE, δοκίμασα την εν λόγω διανομή και στο Raspberry Pi. Τα αποτελέσματα ήταν θαυμάσια. Το μόνο περίεργο ήταν η εγκατάσταση της Java, αλλά δεν ήταν κάτι που να αξίζει αναφοράς.

Another plus of this gadget is that there are so many Linux distributions running on Raspberry Pi right now; you can even find FreeBSD (though this should not impress us!). Since my last time I set up UniFi Controller was in an openSUSE Linux, I also tried it in Raspberry Pi. The results were marvellous. The only weird thing was the Java installation, but nothing worth mentioning here.

Κάτι που με "έτρωγε" ήταν πως αν κάποιος πάρει ένα Raspberry Pi και θελήσει να ασχοληθεί με τη χρήση του σε δίκτυο, όπως και αυτό που ήταν το έναυσμα για αυτή την ιστορία, τότε αμφιβάλλω αν θα ασχοληθεί με το να βάλει openSUSE· σίγουρα θα ασχοληθεί με το "έτοιμο" Raspbian που είναι βασισμένο επάνω στη διανομή Debian. Οπότε, για να μπορέσω να συμβάλλω και σε αυτό τον τομέα θα έπρεπε να δοκιμάσω αυτή τη διανομή για τις "ταρζανιές".

Something that really made me worried was that if someone gets a Raspberry Pi and wants to use it like what described in this article then I doubt he/she will install openSUSE; I bet on the default Raspbian operating system that is based on Debian. So, for me to be a contributor at this part I should use this distribution for all the play.

Το Στήσιμο

The Setup

Το στήσιμο του συστήματος δεν είναι καθόλου δύσκολο. Μπορεί κάποιος να κατεβάσει το κατάλληλο image και να το γράψει σε μια κάρτα μνήμης SD, ή να χρησιμοποιήσει το BerryBoot. Η δεύτερη επιλογή απλά θα προσθέσει μερικά δευτερόλεπτα στο bootάρισμα του συστήματος, αλλά αν κάποιος θέλει να "παίξει" με το Raspberry τότε είναι μια καλή λύση.

The system's setup is not difficult at all. Anyone can download the correct OS image that suits his/her needs and write it in an SD Memory Card. Alternatively BerryBoot can be used. The latter will just add some seconds during boot up of the system, but if somebody wants to "play" with Raspberry then it is a marvellous choice.

Η κάρτα που χρησιμοποιήθηκε στο στήσιμό μας είναι μια 8GB SD Class 10. Δίνει αρκετό χώρο για "παιχνίδια", ενώ είναι αρκετά γρήγορη για ένα ικανοποιητικό χρόνο εκκίνησης. Εκεί εγκαταστάθηκε το Raspbian, ρυθμίστηκε για λίγο overclocking (800 MHz) και έγινε και expand το partition που περιέχει το λειτουργικό. Αυτά, επειδή δεν υπήρχε πληκτρολόγιο στο Raspberry, έγινε μέσω ssh, εκτελώντας από εκεί το raspi-config.

The memory card used here is a 8GB SD Class 10. It gives much space to play, while at the same time is very fast for a short boot time. There was Raspbian installed, configured for some overclocking (800 MHz) and the partition containing the operating system was expanded. Because of lack of a keyboard connected to Raspberry, all these were done through ssh, running raspi-config.

Σε γενικές γραμμές η εγκατάσταση του συστήματος δε νομίζω πως χρειάζεται παρουσίαση. Όλα υπάρχουν στο Internet και είναι αρκετά κατανοητά για κάποιον ο οποίος αποφασίζει να ασχοληθεί με το Raspberry. Έτσι, οι λεπτομέρειες της εγκατάστασης λειτουργικού και ενεργοποίησης του συστήματος, καθώς επίσης και της αναβάθμισης του λογισμικού δεν περιγράφονται.

In general, the system installation was smooth and it doesn't worth mentioning. Every tip and information on that lies in the Internet and are crystal clear for anybody who wishes to use Raspberry Pi. So, all these installation details as well as those for updating the operating system are not presented.

Η αρχική εγκατάσταση περιέχει ένα χρήστη με το όνομα pi, ο οποίος ανήκει στο group pi, έχει password το raspberry, ενώ το όνομα του συστήματος στο δίκτυο είναι raspberrypi. Φυσικά, σε όλα αυτά έγιναν αλλαγές, οπότε ο χρήστης του συστήματος ονομάστηκε elias (λέμε τώρα!), το αρχικό group του χρήστη έχει το ίδιο όνομα, ενώ το δικτυακό όνομα του συστήματος έγινε unificontroll και διάφορα άλλα μικροσεταρίσματα.

The default installation has a user named pi, who belongs to pi group, identified by raspberry as password and the network name of the system is raspberrypi. Of course, changes have been made to all of these settings, so the user name now becomes elias (well, for the clarity of this article!), the initial user's group has the same name and the network name becomes unificontroll. There were also some minor alterations on the setup not worth mentioning.

Προεργασία

Groundwork

1. Εγκατάσταση Java
1. Java Installation

Για να λειτουργήσει το UniFi Controller χρειάζεται τη βάση δεδομένων mongodb και τη γλώσσα Java να είναι εγκαταστημένα στο σύστημα. Για τη Java δεν υπάρχει κάποιο πρόβλημα, μιας και είναι έτοιμη σε πακέτο .deb για το Raspbian. Αρκεί ένα

For UniFi Controller to be able to operate, it needs mongodb database and Java programming language installed in the target system. Java is no problem since there is already a .deb package for Raspbian. Just execute:

elias@unificontrol:~ > sudo apt-get install openjdk-7-jdk
[sudo] password for elias:
.
.
.

2. Εγκατάσταση MongoDB
2. MongoDB Installation

Το περίεργο της υπόθεσης είναι πως δεν υπάρχει πακέτο για MongoDB (τουλάχιστον μέχρι τη στιγμή που γράφεται το παρόν άρθρο). Κατά συνέπεια μπαίνουμε σε διαδικασίες compile κ.λ.π. Μετά από λίγο ψάξιμο βρέθηκε ένα πολύ καλό άρθρο για την εγκατάσταση της mongopi που είναι η μεταφορά της εν λόγω βάσης δεδομένων στο Raspberry. Το συγκεκριμένο άρθρο που βρέθηκε δίνει πληροφορίες για την εγκατάσταση ενός ολόκληρου συστήματος με πολλά Raspberries. Η περιγραφή που θα γίνει στο παρόν άρθρο είναι μόνο για την εγκατάσταση της MongoDB, ως το σημείο που χρειάζεται για να λειτουργήσει με το UniFi Controller.

Perhaps it is strange, but there is no package available for MongoDB (at least at the time of this writing). So, we have to proceed to other procedures like compiling etc. After some searching through the internet there was an article found for mongopi installation, which is the database in question patched for Raspberry. This article gives information for the whole process of a system with many Raspberries setup. The description in here, will be only for MongoDB installation, up to the necessary point to be functional and usable by UniFi Controller.

Ο κώδικας της mongopi είναι στο github. Για να γίνει η εγκατάσταση θα πρέπει να εγκατασταθούν πρώτα το git και κάτι ψιλά... Ξεκινάμε με την εγκατάσταση των απαραίτητων πακέτων γι' αυτή τη δουλειά:

mongopi code is available to download in github. For the total installation process to be complete, git and some other packages as well, must be installed... Lets start all these necessary installations:

elias@unificontrol:~ > sudo apt-get install git-core build-essential scons \
   libpcre++-dev xulrunner-dev libboost-dev \
   libboost-program-options-dev libboost-thread-dev \
   libboost-filesystem-dev
.
.
.

Στη συνέχεια κλωνοποιήσουμε το αποθετήριο με τα αρχεία της mongopi από το github:

OK. Now lets clone the mongopi repository from github:

elias@unificontrol:~ > git clone git://github.com/RickP/mongopi.git

Η συνέχεια θέλει υπομονή... Ώρα για compilation... Αυτό γίνεται με τη βοήθεια του εργαλείου scons και μπορεί να πάρει αρκετές ώρες (περίπου 4):

What follows needs patience... Time to compile the code... This is done using a tool named scons and it may take some hours (well, about 4):

elias@unificontrol:~ > cd mongopi
elias@unificontrol:~/mongopi > scons

Μετά από... λίγη ημέρα :) το compilation θα έχει τελειώσει. Συνέχεια έχει η εγκατάσταση. Αυτή θα χρειαστεί μόνο... 3 ώρες!...

After some... day passes :) the compilation process will be over. Installation follows. This will take only about... 3 hours!...

elias@unificontrol:~/mongopi > sudo scons --prefix=/opt/mongo install

Αυτή η εντολή θα εγκαταστήσει τη mongopi στον κατάλογο /opt/mongo. Φυσικά η όλη διαδικασία έπιασε και υπερβολικό χώρο στην κάρτα μνήμης (περίπου 2GB) οπότε καλό είναι να σβήσετε τον κατάλογο που περιέχει τον πηγαίο κώδικα:

That command will install mongopi in /opt/mongo directory. Naturally, the whole compilation/installation process allocated a huge space in the memory card (something around 2GB) so it is very good thing to delete the directory that contains the source code:

elias@unificontrol:~/mongopi > cd ..
elias@unificontrol:~ > sudo rm -rf mongopi
elias@unificontrol:~ > 

Καλό είναι να μπει στο PATH του συστήματος ο κατάλογος με τα εκτελέσιμα της MongoDB για να είναι εύκολη η διαχείριση των βάσεών της. Αυτό γίνεται απλά με την προσθήκη του στο αρχείο .bashrc της ακόλουθης γραμμής:

It is also a nice idea to insert into the PATH system variable the directory that contains all the executables of MongoDB, for easy access during databases administration. Just insert the following line in .bashrc file:

export PATH=$PATH:/opt/mongo/bin

Σε αυτό το σημείο η εγκατάσταση της MongoDB έχει γίνει. Αν χρειαστεί να τη χρησιμοποιήσετε και σε άλλες εφαρμογές, τότε πιθανό είναι να πρέπει να δημιουργήσετε και τον κατάλογο /data/db στο σύστημά σας. Αυτό στην περίπτωση του UniFi Controller δεν είναι απαραίτητο γιατί τη δικιά του βάση δεδομένων την κρατάει σε δικό του κατάλογο.

We reached the point that MongoDB is installed in the system. If you are going to also use it in other applications you possibly have to create /data/db directory, or mongo will complain. In the case of just using it only with UniFi Controller that step can be omitted, because it uses its own directory for the database contents.

Εγκατάσταση UniFi Controller

UniFi Controller Installation

Η εγκατάσταση του UniFi Controller δεν έχει κάποια δυσκολία. Σε γενικές γραμμές είναι ίδια με αυτή που έχει γίνει και σε προηγούμενο άρθρο σε άλλη έκδοση του λειτουργικού Linux

UniFi Controller installation is not difficult at all. It is about the same as described in a previous article in another Linux distribution.

Ξεκινάμε με το να δημιουργήσουμε ένα group με το όνομα unifid, όπου εκεί θα μπει και ο χρήστης που θα έχει τη δυνατότητα του custom portal για τους πελάτες του δικτύου. Μιας και ο μόνος χρήστης που υπάρχει αυτή τη στιγμή στο σύστημα είναι ο elias, αυτός είναι που θα προστεθεί και στο εν λόγω group.

Start from creating a user group named unifid, that will contain the user who will have the ability to create/alter the custom portal for the network clients. Since the only user existed in the system right now is elias, this user will be added into the group in question.

elias@unificontrol:~ > sudo addgroup unifid
Adding group `unifid' (GID 1003) ...
Done.
elias@unificontrol:~ > sudo adduser elias unifid
Adding user `elias' to group `unifid' ...
Adding user elias to group unifid
Done.

Για να δει το σύστημα την αλλαγή στα groups θα πρέπει να κάνουμε ένα logout και μετά ξανά login. Αυτό που φαίνεται στις ακόλουθες εντολές είναι η σύνδεση μέσω ssh από άλλον υπολογιστή:

For the system to read the new settings in you'll have to logout and relogin. What is presented in the following commands is a connection from another computer through ssh:

elias@unificontrol:~ > logout
Connection to 192.168.1.10 closed.
elias@otherpc:~> ssh 192.168.1.10
elias@192.168.1.10's password: 
Linux unificontrol 3.6.11+ #456 PREEMPT Mon May 20 17:42:15 BST 2013 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu May 30 11:43:24 2013 from 192.168.1.20
elias@unificontrol:~ > groups
elias adm dialout cdrom sudo audio video plugdev games users netdev input unifid
elias@unificontrol:~ > 

Το επόμενο βήμα είναι να κατεβάσουμε το .zip αρχείο του προγράμματος. Οι διαθέσιμες εκδόσεις είναι δύο:

The next step is to download the desirable .zip file of the program. The available versions (at the time of this writing) are two:

Όποια από τις δύο εκδόσεις και αν ενδιαφερθείτε να εγκαταστήσετε, ο τρόπος είναι ακριβώς ο ίδιος. Απλώς κατεβάστε το αρχείο .zip και αποσυμπιέστε το. Επειδή θα πρέπει να αποδεχθείτε την άδεια χρήσης του προγράμματος, θα πρέπει να το κατεβάσετε με τη βοήθεια κάποιου browser στον υπολογιστή σας και στη συνέχεια να το μεταφέρετε με scp στο Raspberry. Στη συνέχεια το αποσυμπιέζετε:

Whichever of these you may choose to install, the way is exactly the same. Just download the desired .zip file and uncompress it. Because you'll have to accept the license agreement, you have to download it using your computer's browser and transfer the file to Raspberry Pi using scp. There you can uncompress it:

elias@otherpc:~ > scp ~/Downloads/UniFi.unix.zip 192.168.1.10:/home/elias/
elias@192.168.1.10's password:
UniFi.unix.zip    100%   28MB   1.2MB/s   00:23
elias@otherpc:~ > ssh 192.168.1.10
elias@192.168.1.10's password:
.
.
elias@unificontrol:~ > cd /opt/
elias@unificontrol:/opt > sudo unzip /home/elias/UniFi.unix.zip
Archive:  UniFi.unix.zip
   creating: UniFi/
   creating: UniFi/bin/
    linking: UniFi/bin/mongod        -> /usr/bin/mongod 
.
.
.
elias@unificontrol:/opt >

Το πρόγραμμα έχει εγκατασταθεί στο Raspberry. Μένουν λίγες ακόμα λεπτές πινελιές για τη λειτουργία του. Καταρχήν το link που βρίσκεται μέσα στον κατάλογο UniFi/bin δεν χρειάζεται κάποια αλλαγή, γιατί η εγκατάσταση της MongoDB έχει φροντίσει να υπάρχει το αρχείο /usr/bin/mongod που χρειάζεται το UniFi Controller. Αυτό που χρειαζεται να γίνει, είναι να δημιουργθεί ο κατάλογος data που θα φιλοξενεί όλες τις παραμέτρους για το δίκτυό μας. Ο κατάλογος αυτός θα περιέχει και το portal της εισόδου των πελατών του ξενοδοχείου στο δίκτυο, έτσι θα πρέπει να μπορεί ο χρήστης που ανήκει στο group unifid να αλλάζει τα δεδομένα χωρίς να υπάρχουν προβλήματα με τα δικαιώματα. Επειδή θα πειράξουμε λίγο τη λίστα δικαιωμάτων, θα χρειαστεί να εγκατασταθεί και το πακέτο acl με την εντολή:

The program is now installed in Raspbian. There are some finishing touches for its correct operation. Begining with the link that lies in UniFi/bin directory, it does not need any change, since the MongoDB installation has placed the executable /usr/bin/mongod where UniFi Controller expects it. But what is necessary to be done is the creation of a directory named data. In there, all the parameters and information of the network will be stored. There will also be the entry portal of the hotel clients, so the user who belongs to unifid group must have the correct access rights for being able to alter those files without problems. We are going to change the access rights list a little bit, so we need to install acl package using the command:

elias@unificontrol:/opt > sudo apt-get install acl
...

Το επόμενο βήμα είναι να δημιουργθεί ο κατάλογος data και να του δοθούν τα κατάλληλα δικαιώματα:

The step that follows creates the data directory and gives the correct access rights to it:

elias@unificontrol:/opt > cd UniFi
elias@unificontrol:/opt/UniFi > sudo mkdir data
elias@unificontrol:/opt/UniFi > sudo chgrp unifid data
elias@unificontrol:/opt/UniFi > sudo chmod 0774 data
elias@unificontrol:/opt/UniFi > sudo chmod g+s data
elias@unificontrol:/opt/UniFi > sudo setfacl -d -m u::rwX,g::rwX,o::r data
elias@unificontrol:/opt/UniFi > ls -ld data
drwxrwsr--+ 7 root unifid 4096 May 29 13:13 data
elias@unificontrol:/opt/UniFi > getfacl data
# file: data
# owner: root
# group: unifid
# flags: -s-
user::rwx
group::rwx
other::r--
default:user::rwx
default:group::rwx
default:other::r--
elias@unificontrol:/opt/UniFi >

Πλέον είμαστε έτοιμοι να δοκιμάσουμε αν το πρόγραμμα λειτουργεί σωστά. Μην ξεχνάμε ότι η εγκατάσταση έχει γίνει με τέτοιο τρόπο που τρέχει από τον root. Για να ξεκινήσει το UniFi Controller θα πρέπει να δώσουμε την εντολή:

Now we are ready to test if the program works as expected. Do not forget that the installations has been made in a way that only root can execute it. To start the UniFi Controller run the following command from the command line interface:

elias@unificontrol:/opt/UniFi > sudo /usr/bin/java -jar /opt/UniFi/lib/ace.jar start &

Εδώ θα πρέπει να περιμένουμε λίγο χρονικό διάστημα (αρκετά δευτερόλεπτα) πριν καταφέρουμε να μπούμε στο σύστημα. Για να δοκιμάσουμε το σύστημά μας, θα πρέπει να χρησιμοποιήσουμε τον browser ενός υπολογιστή. Αν προσπαθήσουμε να μπούμε πριν το πρόγραμμα κάνει όλα τα απαραίτητα, τότε απλά θα έχουμε μήνυμα λάθους από τον browser. Αν όμως το σύστημα ετοιμαστεί τότε δίνοντας τη διεύθυνση του Raspberry με πόρτα την 8080, θα δούμε την εισαγωγική οθόνη του UniFi Controller. Η διεύθυνση που έχει αυτή τη στιγμή είναι η 192.168.1.10, οπότε η διεύθυνση που θα πληκτρολογήσουμε στον browser μας είναι η http://192.168.1.10:8080/. Η σελίδα θα κάνει redirection σε https, αλλά στην ίδια διεύθυνση και ο browser θα μας παραπονεθεί για το πιστοποιητικό της σελίδας. Όταν τελικά το αποδεχτούμε:

We will have to wait for a short time (several seconds) before trying to enter the system. To test it we will have to use the browser of another computer. If we try to enter before the program finishes all its intro tasks then we will simply receive an error message from our browser. But if the system is ready to accept connections, then by entering the IP address of the Raspberry Pi using port 8080, we will get the introduction screen of UniFi Controller. The address used during the righting of this article is 192.168.1.10, so this is the address we will type in our browser: http://192.168.1.10:8080/; the page will redirect to https protocol at the same IP address and our browser will complain about this page's certificate. When we finally accept it:

Για να σταματήσουμε το πρόγραμμα, αρκεί να τρέξουμε την εντολή:

To stop the program, we have to enter the following command:

elias@unificontrol:/opt/UniFi > sudo /usr/bin/java -jar /opt/UniFi/lib/ace.jar stop

Για την ώρα δεν χρειάζεται να κάνουμε παραμετροποίηση του συστήματος. Μπορούμε να την αφήσουμε για αργότερα, όταν όλα θα είναι έτοιμα!

For now we will not continue to any network configuration. We can leave it for later on, when everything is in place!

Δημιουργία service script

Service Script Creation

Τώρα που το σύστημα λειτουργεί, θα πρέπει να το κάνουμε να ενεργοποιείται στα κατάλληλα runlevels του Raspbian.

Now we know that the system works, we must make it automatically activated at the appropriate Raspbian runlevels.

Η διαδικασία είναι η ίδια με αυτή που περιγράφεται στο αντίστοιχο άρθρο για το openSUSE. Ο κατάλογος /etc/init.d/ περιέχει όλα τα scripts για τα services. Περιέχει κι ένα αρχείο που μας ενδιαφέρει περισσότερο, το skeleton. Αυτό είναι ένα αρχείο στο οποίο μπορούμε να βασιστούμε για να φτιάξουμε το δικό μας script, έτσι ώστε το UniFi Controller να μπορεί να ενεργοποιηθεί και να απενεργοποιηθεί όπως ακριβώς και όλα τα υπόλοιπα services που διαθέτει το σύστημα. Το αρχείο που θα δημιουργήσουμε είναι το unifid. Μπορείτε να το δημιουργήσετε μόνοι σας από την αρχή, απλά αντιγράφοντας το ακόλουθο και σώζοντάς το μέσα στον εν λόγω κατάλογο:

The procedure is the same as the one described in the similar article for openSUSE. The /etc/init.d/ contains all the scripts for all the available services. It also contains a file that we need more, named skeleton. That is the file we will be based on to create our own service script, to make UniFi Controller activated and deactivated in the same way as the rest of the system's services. The file we will create is called unifid. You can create it by yourselves from the very beginning, by simply copying and pasting the following code and saving it in the directory in question:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          unifid
# Required-Start:    $local_fs $syslog $network
# Required-Stop:     $local_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: unifid daemon providing Controller server for UniFi Access Points
# Description:       Start unifid to allow the UniFi Controller Software to be able to
#       control the UniFi Access Points of Ubiquity in the network. The softare runs in Java
#       and is installed in /opt/ directory.
### END INIT INFO

# Author: Elias Chrysocheris 
#

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="UniFi Controller Service for assisting Ubiquity's UniFi Access Points"
JAVA_BIN=/usr/bin/java
NAME=unifid
MONGOD_BIN=/opt/UniFi/bin/mongod
DAEMON=/opt/UniFi/lib/ace.jar
DAEMON_ARGS="-jar $DAEMON"
SCRIPTNAME=/etc/init.d/$NAME

# Exit if Java package is not installed
[ -x "$JAVA_BIN" ] || { echo "Cannot find java executable in $JAVA_BIN, or java is not installed...";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 5; fi; }

# Also, mongoDB must be installed. The extra step here is that there must be a valid link in
# /opt/UniFi/bin/mongod that points to the mongod executable
if [ ! \( -e $MONGOD_BIN \) ]
then
    echo "Cannot find mongod executable in $MONGOD_BIN, or mongoDB is not installed...";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 5; fi;
fi

# Exit if the package is not installed
[ -e "$DAEMON" ] || { echo "Cannot find UniFi Controller executable in $DAEMON, or the controller software is not installed...";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 5; fi; }

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
    # Return
    #   0 if daemon has been started
    #   1 if daemon was already running
    #   2 if daemon could not be started
    start-stop-daemon --test --start --quiet --exec $JAVA_BIN -- $DAEMON_ARGS start > /dev/null \
        || return 1
    start-stop-daemon --start --quiet --exec $JAVA_BIN -- $DAEMON_ARGS start &
    RETVAL="$?"
    [ $RETVAL > 0 ] && return 2
    # Add code here, if necessary, that waits for the process to be ready
    # to handle requests from services started subsequently which depend
    # on this one.  As a last resort, sleep for some time.
}

#
# Function that stops the daemon/service
#
do_stop()
{
    # Return
    #   0 if daemon has been stopped
    #   1 if daemon was already stopped
    #   2 if daemon could not be stopped
    #   other if a failure occurred
    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --exec $JAVA_BIN -- $DAEMON_ARGS stop
    RETVAL="$?"
    [ "$RETVAL" = 2 ] && return 2
    # Wait for children to finish too if this is a daemon that forks
    # and if the daemon is only ever run from this initscript.
    # If the above conditions are not satisfied then add some other code
    # that waits for the process to drop all resources that could be
    # needed by services started subsequently.  A last resort is to
    # sleep for some time.
    start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
    [ "$?" = 2 ] && return 2
    return "$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
    #
    # If the daemon can reload its configuration without
    # restarting (for example, when it is sent a SIGHUP),
    # then implement that here.
    #
    start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
    return 0
}

case "$1" in
  start)
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
    do_start
    case "$?" in
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  stop)
    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
    do_stop
    case "$?" in
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  status)
    status_of_proc "$JAVA_BIN -jar $DAEMON" "$NAME" && exit 0 || exit $?
    ;;
  #reload|force-reload)
    #
    # If do_reload() is not implemented then leave this commented out
    # and leave 'force-reload' as an alias for 'restart'.
    #
    #log_daemon_msg "Reloading $DESC" "$NAME"
    #do_reload
    #log_end_msg $?
    #;;
  restart|force-reload)
    #
    # If the "reload" option is implemented then remove the
    # 'force-reload' alias
    #
    log_daemon_msg "Restarting $DESC" "$NAME"
    do_stop
    case "$?" in
      0|1)
        do_start
        case "$?" in
            0) log_end_msg 0 ;;
            1) log_end_msg 1 ;; # Old process is still running
            *) log_end_msg 1 ;; # Failed to start
        esac
        ;;
      *)
        # Failed to stop
        log_end_msg 1
        ;;
    esac
    ;;
  *)
    #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
    echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
    exit 3
    ;;
esac

Το script θα πρέπει να είναι εκτελέσιμο, οπότε όταν δημιουργηθεί στο δίσκο θα πρέπει να του ενεργοποιηθούν και τα κατάλληλα δικαιώματα εκτέλεσης. Επίσης, η δημιουργία του γίνεται από τον χρήστη root, αλλοιώς το σύστημα θα αρνηθεί να το σώσει μέσα στον κατάλογο init.d. Τέλος θα πρέπει να γίνουν update τα links των καταλόγων rc?.d, έτσι ώστε το service να ξεκινάει ή να σταματάει αυτόματα, ανάλογα με το runlevel στο οποίο μεταπηδάει το Raspbian. Οι εντολές για τα δικαιώματα και την ενημέρωση των runlevels είναι οι ακόλουθες:

The script must be marked executable, so when it is created in the disc we must alter its access rights. Another tip is that it ust be created from the root user, or the system will deny its saving into init.d. Last, the links of all rc?.d directories must be updated, for the service to be started or stopped automatically, according to runlevel transitions of the operating system. The commands for altering the access rights and updating the runlevel links are:

elias@unificontrol:/opt/UniFi > cd /etc/init.d/
elias@unificontrol:/etc/init.d > sudo chmod 0755 unifid
elias@unificontrol:/etc/init.d > sudo update-rc.d unifid defaults
update-rc.d: using dependency based boot sequencing
elias@unificontrol:/etc/init.d > 

Μπορεί να γίνει να δοκιμή του script που μόλις ενεργοποιήθηκε δίνοντας τις ακόλουθες εντολές και κοιτάζοντας τις αποκρίσεις:

We can test the newlly created and activated script by executing the folowing commands and observe their response:

elias@unificontrol:/etc/init.d > sudo /etc/init.d/unifid start
elias@unificontrol:/etc/init.d > sudo /etc/init.d/unifid status
[ ok ] unifid is running.
elias@unificontrol:/etc/init.d > sudo /etc/init.d/unifid stop
elias@unificontrol:/etc/init.d > sudo /etc/init.d/unifid status
[FAIL] unifid is not running ... failed!
elias@unificontrol:/etc/init.d > 

Αν όλα πήγαν καλά, τότε μετά από μια επανεκκίνηση αν εκτελέσουμε την εντολή ps aux | grep ace.jar θα πρέπει να δούμε τα ακόλουθα:

If everything went right, after a restart of Raspbian, using the command ps aux | grep ace.jar we must get something like:

elias@unificontrol:~ > ps aux | grep ace.jar
root      3189 54.0  5.2 370688 25212 ?        Sl   23:43   0:16 /usr/bin/java -jar /opt/UniFi/lib/ace.jar start
elias     3241  0.0  0.1   3548   892 pts/0    S+   23:43   0:00 grep --color=auto ace.jar
elias@unificontrol:~ > 

Αυτό που μας ενδιαφέρει είναι η πρώτη γραμμή που δείχνει πως ένα process τρέχει αυτή τη στιγμή στον επεξεργαστή κι έχει την εντολή ενεργοποίησης του service του UniFi Controller. Η συνέχεια είναι απλή. Ανοίγουμε και πάλι τον browser και δίνοντας την IP διεύθυνση του Raspberry με την πόρτα 8080, όπως κάναμε και πριν, ξεκινάμε την παραμετροποίηση του συστήματος των Access Points. Όταν όλα τελειώσουν μπορούμε να έχουμε μια εικόνα σαν αυτή:

What we are interested in, is the first line showing there is an active process running in our processor, started by the same command we used to start the UniFi Controller. What follows is natural; We open a browser in our computer and by entering the Raspberry's IP address and port 8080, as we did before, we can start the configuration of our Access Points. When everything is done we must get a page like that:

Συμπεράσματα

Conclutions

Το Raspberry Pi, είναι ένα gadgetάκι που, μπορεί κάποιος να μη μείνει ικανοποιημένος αν προσπαθήσει να το χρησιμοποιήσει όπως ένα Desktop υπολογιστή. Όταν το χρησιμοποιήσετε απλά για internet κ.λ.π. θα διαπιστώσετε ότι μοιάζει πολύ με ένα υπολογιστή τεχνολογίας εποχής του KDE3. Ναι μεν μπορείς να κάνεις κάποια δουλειά, αλλά οι χρόνοι καθυστέρησης σε γυρίζουν λίγο πίσω... Από την άλλη, σαν ένας μικρός server έχει αρκετά πλεονεκτήματα. Έχει ικανοποιητική ταχύτητα για τη διαχείριση ενός μικρού δικτύου. Μπορεί να αναλάβει "μικροδουλειές" όπως backup/file server, firewall ή ακόμα και για να τραβάει φωτογραφίες σαν σύστημα παρακολούθησης/ασφάλειας. Στη δική μας περίπτωση, αυτό που μας ενδιέφερε είναι να μπορέσει να λειτουργήσει ως διαχειριστής δικτύου ξενοδοχείου και αυτή τη δουλειά την κάνει αρκετά καλά.

Raspberry Pi is a small gadget that someone may not be satisfied if he/she uses it as a desktop computer. If you use it simply for internet browsing etc. you will find out it is very similar, in terms of processing power, to a computer that used KDE3. It is true you can do some work, but the execution times takes you a little bit back in time... In contrast, working as a small server has many advantages. Its speed is satisfactory for using in a small network. It can handle some simple tasks such as a backup/file server, a firewall or even taking photos as an area survailance/security system. In our case, what we were interested in was to be able to handle access control and portal serving in a hotel's network. And that is a job that can handle very well.

Μια ακόμα δυνατότητα είναι πως μπορεί πολύ εύκολα να τροφοδοτηθεί από μια επαναφορτιζόμενη μπαταρία. Λόγω την μικρής του κατανάλωσης μια τέτοια μπαταρία είναι ικανή να το κρατήσει σε λειτουργία για πραγματικά πολλές ώρες, σε περίπτωση διακοπής της ΔΕΗ.

Another posibility is that it can be easily powered by a rechargable battery. Due to its low power consumption a battery like that can keep it functional even during long time power failures of the power company.

Όσο για την τιμή του, είναι ιδανική για αυτό που προσφέρει και αυτά που μπορεί να κάνει, ειδικά σαν "δικτυακό βοήθημα". Οι γενικές εντυπώσεις μας είναι άριστες!

And for its price, it is ideal for what it can offer and perform, aspecially as a "network assistant". Our general impression is more than surprising!

Ηλίας Χρυσοχέρης

Elias Chrysocheris

Σάββατο 11 Μαΐου 2013

Ubiquity UniFi Controller Software στο openSUSEUbiquity UniFi Controller Software in openSUSE

Το ξεκίνημα της ιστορίας

The Beginning Of The Story

Κάποια στιγμή μου ζητήθηκε από ένα φίλο να τον βοηθήσω να στήσει ένα δίκτυο σε ένα ξενοδοχείο. Μετά από λίγο ψάξιμο βρέθηκαν τα κατάλληλα εργαλεία για αυτή τη δουλειά: τα Access Points της Ubiquity. Συγκεκριμένα η απόφαση πήγε στη σειρά UniFi που έχουν καταπληκτικά χαρακτηριστικά. Δίνουν τη δυνατότητα για custom guest portal για την είσοδο των πελατών, δημιουργία VPNs, μέχρι τέσσερα διαφορετικά SSIDs με το καθένα από αυτά να έχει τα δικά του χαρακτηριστικά, ορισμό μέγιστου bandwidth για κάθε client που συνδέεται επάνω, ορισμό μέγιστου ποσού δεδομένων που θα διακινήσει και πολλά άλλα. Όλα αυτά τα δίνουν σε αρκετά προσιτή τιμή.

Once, a friend of mine asked me to help him set up a wireless network of a hotel. After short searching in the internet and around the necessary tools for this job were found: The Access Points of Ubiquity. More precisely the decision end up to the UniFi line that have great specifications. They have the ability to use custom guest portals for the authorisation to the network usage, VPNs, ability to handle up to four wireless SSIDs, each having its own characteristics, bandwidth limit per client, user data quota and many many more; and all these in a very good price.

Το μειονέκτημα που υπάρχει στην όλη ιστορία είναι πως για να έχει custom guest portal, ή δημιουργία voucher για τους πελάτες, θα πρέπει ένας υπολογιστής να τρέχει συνεχώς το software της μαμάς εταιρίας (Ubiquity). Για να λυθεί αυτό, αρχικά υπήρχε η ιδέα να χρησιμοποιηθεί το μηχάνημα της reception του ξενοδοχείου για αυτή τη δουλειά. Όμως το μηχάνημα αυτό θα πρέπει να σβήνει κάποιες φορές... Άλλο ένα μειονέκτημα είναι ότι το συγκεκριμένο μηχάνημα τρέχει το ακατονόμαστο λειτουργικό.

The only drawback in the whole system is the necessity to have one computer running the mother company's (Ubiquity's) software 24/7 to give the ability of serving the custom guest portal and client voucher creation. The first idea was to use the reception's computer for that purpose. But this computer is switched off some hours in the night... Another minus in this idea was that this specific machine must run the unnamed operating system (may God make it "operating").

Μετά από μια επίδειξη του Ubuntu και του openSUSE, παρότι έχει κάποια ιδέα αυτός ο φίλος από Linux, προτίμησε (τι αναπάντεχο...) να χρησιμοποιήσει το προσωπικό του μηχάνημα με openSUSE και το software της Ubiquity να τρέχει σε αυτό το μηχάνημα. Αυτό το μηχάνημα δεν σβήνει ποτέ, οπότε είναι η καλύτερη ιδέα!

After a small demonstration of Ubuntu and openSUSE, though my friend already knew some things about Linux, he prefered (hmmm, how unexpected...) to use openSUSE and Ubiquity's software in his personal computer. That computer could stay alive 24/7, so this was the best idea!

Τι θα δούμε

What's in this article

Τα κομμάτια που θα δούμε σε αυτό το άρθρο είναι τα ακόλουθα:

We are going to discuss the following topics:

Προεργασία

Groundwork

Η προεργασία για το στήσιμο του συστήματος έχει το κλασικό backup αρχείων, εγκατάσταση του openSUSE στον υπολογιστή και επαναφορά των αρχείων από το backup του προηγούμενου λειτουργικού

The groundwork we have to do is to backup the system, install openSUSE in the computer and restore the necessary user files form the backup of the previous (ehmmm... non) operating system.

Στη συνέχεια θα πρέπει να εγκατασταθούν οι εξαρτήσεις που χρειάζεται το UniFi Controller Software. Αυτές δεν είναι πολλές:

Next, follows the step of dependecies installation of UniFi Controller Software. They are not that many:

  • Java
  • MongoDB

Η Java είναι από την αρχή εγκαταστημένη στο openSUSE (όπως και σε κάθε διανομή Linux), οπότε το μόνο που υπήρχε σαν εγκατάσταση είναι η database MongoDB. Δεν υπάρχει ευκολότερο πράγμα από αυτό. Απλώς ανοίγουμε το YaST (από το κεντρικό μενού επιλέγουμε το tab "Computer" και από τη λίστα που εμφανίζεται επιλέγουμε το "Install/Remove Software"

Java should be already installed in openSUSE (as in every Linux distribution), so the only one left to be installed is MongoDB database. There is no easier thing than that. Just open YaST (from the main menu select the "Computer" tab and in the appeared list select "Install/Remove Software"

Μετά την εισαγωγή του συνθηματικού του root, ανοίγει το κεντρικό παράθυρο του "YaST - Software Management". Στο πεδίο εύρεσης γράφουμε το "mongodb" και πατάμε το "Search". Στο δεξί τμήμα του παραθύρου εμφανίζεται και το πακέτο που μας ενδιαφέρει. Κάνουμε διπλό κλικ επάνω του και αμέσως μαρκάρεται για εγκατάσταση. Πατώντας το "Accept" ξεκινάμε την εγκατάσταση του πακέτου μας:

After typing the root password, "YaST - Software Management" main window opens. In the search field type "mongodb" and press "Search". At the right part of this window the needed package appears. Double clicking marks the package for installation. By pressing "Accept" the installation begins:

Εγκατάσταση του UniFi Controller

UniFi Controller Installation

Η εγκατάσταση του συστήματος είναι εύκολη. Δεν έχει κάτι το περίπλοκο. Το πρόγραμμα διατίθεται σε μορφή συμπιεσμένου αρχείου .zip σε δύο εκδόσεις:

The installation of the program in question is very simple. It does not contain anything complicated. It is available as a .zip file in two versions (at the time of this writing):

Όποια έκδοση και αν προτιμήσετε η εγκατάσταση γίνεται με τον ίδιο τρόπο. Σε γενικές γραμμές, για να είναι κάπως clean το σύστημα, προτείνεται εγκαταστάσεις τέτοιου είδους (που δεν είναι δηλαδή από αποθετήρια του λειτουργικού) να γίνονται στον κατάλογο /opt/, ή στον κατάλογο /usr/local/. Εδώ η εγκατάσταση θα γίνει στον κατάλογο /opt/. Απλά αποσυμπιέστε ως root τα περιεχόμενα του αρχείου .zip που κατεβάσατε, στον κατάλογο /opt/.

Whichever version you prefer to use, the installation walkthrough is the same. In general, for our system to be cleaner, such installations (meaning, installation of programs not included in the repositories of the system) is better to be either in /opt/ directory, or /usr/local/ one. In this article the installation will be in /opt/. Just unzip as root the .zip file you downloaded, at /opt/ directory.

eliaschr@orion:~> su
Password: 
orion:/home/eliaschr # cd /opt/
orion:/opt # unzip /home/eliaschr/Downloads/UniFi.unix.zip
.
.
.
orion:/opt # 

Δημιουργία group unifi - Προαιρετικό Βήμα

unifi Group Creation - Optional Step

Επειδή λογικά θα χρειάζεστε κατά καιρούς να κάνετε κάποιες αλλαγές, όπως δημιουργία guest portal κ.λ.π. που έχουν να κάνουν με απ' ευθείας αλλαγές στα αρχεία του δίσκου, καλό είναι να δημιουργήσετε ένα group με ονομασία unifi και να κάνετε τα αρχεία του καταλόγου UniFi/data να ανήκουν σε αυτό το group. Αν ενεργοποιήσετε και το SGID bit του εν λόγω υποκαταλόγου, τότε κάθε καινούργιο αρχείο ή κατάλογο που θα δημιουργείτε μέσα στον data θα ανήκει στο group unifi. Είναι προαιρετικό βήμα, αλλά ας δούμε πως γίνεται. Γενικά, οι επεξηγήσεις που υπάρχουν γίνονται όσο το δυνατόν με λιγότερη χρήση κονσόλας για να είναι λίγο πιο κατανοητά σε καινούργιους χρήστες του λειτουργικού:

Since from time to time you may need to make some alterations of the system, like the alteration of the guest portal etc., on the disc files, it is a very good way to create a user group named unifi and make the files in UniFi/data directory belong to it. If you also set the SGID bit of the directory in question, then every new file created in data will belong to the unifi group, also. It is an optional step, but lets see how it is done. In general, the explanations given in here use the command line interface as less as possible, for the new users of the operating system to be able to understand them easier:

Η δημιουργία του group γίνεται από το YaST. Αφού γίνει η επιλογή του YaST από το μενού και δωθεί ο κωδικός του root, εμφανίζεται το κεντρικό παράθυρο. Για τη δημιουργία ένός group γίνεται επιλογή της ομάδας "Security and Users" και στη δεξιά πλευρά του "User and Group Management"

The group creatin is done in YaST. By selecting YaST from the main menu and the root password is given, the main window of the program appears. To create o user group select "Security and Users" at the left side of the window and "User and Group Management" from its right part.

Το παράθυρο που ανοίγει δείχνει τους χρήστες που υπάρχουν αυτή τη στιγμή στο σύστημα. Στο επάνω μέρος υπάρχουν τέσσερις καρτέλες. Η δεύτερη ονομάζεται "Groups" και μιας και μας ενδιαφέρει να προσθέσουμε ομάδα στο σύστημα, την επιλέγουμε. Με την επιλογή της καρτέλας των ομάδων, εμφανίζονται στην οθόνη οι διαθέσιμες ομάδες ενώ στο κάτω τμήμα της οθόνης υπάρχει το πλήκτρο προσθήκης "Add". Με την επιλογή αυτού του πλήκτρου εμφανίζεται το παράθυρο της προσθήκης ομάδας.

The window that opens presents the users that exist in the system. At the upper part there are four tabs. The second one is named "Groups" and since we need to add a user group in our system, we select it. After our tab selection, the available groups appear on screen while at the bottom of the screen there is a button named "Add". Selecting this button a new window opens for the new group creation.

Στη θέση ονόματος της καινούργιας ομάδας μπαίνει το όνομα "unifi". Το νούμερο του group δεν χρειάζεται να αλλάξει μιας κι επιλέγεται αυτόματα από το σύστημα. Στο δικό σας σύστημα μπορεί να είναι διαφορετικό. Από τη δεξιά στήλη γίνεται επιλογή των χρηστών που θα έχουν τα δικαιώματα να αλλάζουν τις ρυθμίσεις του guest portal χωρίς να χρειάζεται να γίνονται root. Στο παραπάνω στιγμιότυπο φαίνονται οι ρυθμίσεις στο δικό μου μηχάνημα, όπου έχει προστεθεί και ο δικός μου χρήστης στο εν λόγω group.

In the name field of the new group "unifi" is placed. The number of the new group does not need to be changed as it is automatically placed by the system. In your system it may be different as it is in the snapshot. From the list at the right of the window the users that will have the access rights to change the guest portal files are selected. After that they will not have to be root to do all the job. In the above snapshot there are the settings made in my system, were only my user is added in this group.

Φυσικά, με το πάτημα του πλήκτρου "ΟΚ" εμφανίζεται και πάλι η αρχική εικόνα. Εκεί πρέπει να φαίνεται και η καινούργια ομάδα που μόλις δημιουργήθηκε. Πατώντας και πάλι το "ΟΚ" εφαρμόζονται οι καινούργιες ρυθμίσεις.

After pressing "ΟΚ" you return to the previous screen. The new group just created is there. By pressing "ΟΚ" again the new settings are applied to the system.

Το τελευταίο βήμα είναι να ανήκει ο κατάλογος που μπαίνουν τα δεδομένα στο καινούργιο group. Παράλληλα πρέπει το σύστημα, όταν δημιουργείται ένα καινούργιο αρχείο, να το κάνει να ανήκει και αυτό στο group unifi, αυτόματα. Αυτό χρειάζεται για να μπορεί να το διαβάζει και ο server του UniFi Controller Software. Δυστυχώς, εδώ δε μπορούμε να αποφύγουμε την κονσόλα, αλλά γίνεται με απλές εντολές.

The last step is to make the directory, with the data we need to be able to alter, a part of the new group. At the same time the newly created files must be automatically belong to the same group. This must be done for the UniFi Controller server to be able to read it. Unfortunately this cannot be done without the help of the console, but the commands are simple.

Ανοίγουμε μια κονσόλα και μπαίνουμε ως root εκτελώντας την εντολή su. Μετά την εισαγωγή του password του υπερχρήστη εκτελούνται οι εντολές που φαίνονται εδώ:

Open a console and become root by executing su. After entering the superuser's password enter the following commands:

eliaschr@orion:~> su
Password: 
orion:/home/eliaschr # cd /opt/UniFi/
orion:/opt/UniFi # mkdir data
orion:/opt/UniFi # chgrp unifi data
orion:/opt/UniFi # chmod g+w data
orion:/opt/UniFi # chmod g+s data

Αυτό που κάνουν οι εντολές είναι να δημιουργήσουν ένα κατάλογο με το όνομα data (εντολή mkdir), να κάνουν τον κατάλογο αυτό να ανήκει στο group unifi που δημιουργήθηκε πριν (εντολή chgrp), να δοθούν δικαιώματα ανάγνωσης κι εγγραφής στο group (πρώτη εντολή chmod) κι επιπλέον, ό,τι αρχείο ή κατάλογος δημιουργείται εκεί μέσα να ανήκει στο group που ανήκει και ο κατάλογος, δηλαδή το unifi (η τελευταία εντολή chmod). Η επόμενη εντολή, χρησιμοποιεί ένα σύστημα που ονομάζεται File Access Control List που προσθέτει επιπλέον δικαιώματα. Αυτό που μας ενδιαφέρει είναι τα αρχεία που δημιουργούνται να έχουν διακαιώματα read/write για τον χρήστη και το group, ενώ για τους υπόλοιπους να έχουν μόνο διακαιώματα διαβάσματος:

What these commands do, is to create a directory with the name data (mkdir command), make this directory belong to unifi group created earlier (chgrp command), give read and write access rights to that group (first chmod command) and whatever whatever file or directory is created in there is made automatically to belong to the group of its parent, meaning unifi (The last chmod command). The next command that shall be presented, uses an extended system that is called File Access Control List that extends the access rights of the files. What we need here, is the files that created to have read/write access for both the user and the group, but only read access rights for the rest of the users:

orion:/opt/UniFi # setfacl -d -m u::rwX,g::rwX,o::r data

Τέλος, για να είναι ολοκληρωμένη η εγκατάσταση του συστήματος, θα πρέπει να δημιουργήσουμε ένα link προς το εκτελέσιμο της βάσης δεδομένων. Το link βρίσκεται ήδη στον κατάλογο /opt/UniFi/bin/ κι έχει το όνομα mongod. Δυστυχώς δείχνει σε λάθος τοποθεσία, οπότε πρέπει να το διορθώσουμε:

Last but not least, for the installation to be complete we must create a link to the executable of the database. There is already a link in /opt/UniFi/bin/ directory named mongod. Unfortunately it points to a wrong place, so we must correct it:

orion:/opt/UniFi # cd bin
orion:/opt/UniFi/bin # rm mongod
orion:/opt/UniFi/bin # ln -s /usr/sbin/mongod mongod

Τώρα το εν λόγω link δείχνει στο σωστό σημείο.

Now the link in question points to the correct file.

Μέχρι εδώ έχουμε κάνει μισή δουλειά... Βασικά μας δίνεται η δυνατότητα να μπορούμε να αλλάζουμε τα δεδομένα των αρχείων που θα δημιουργεί ο server μέσα στον κατάλογο data και τους υποκαταλόγους του, ως απλοί χρήστες. Η διαφορά είναι πως αν δημιουργήσουμε κάτι δικό μας, τότε για να το διαβάσει σωστά ο server θα πρέπει να του αλλάξουμε τα δικαιώματα, αλλά αυτό πλέον μπορεί να γίνεται εύκολα από το γραφικό περιβάλλον, χωρίς τη χρήση της κονσόλας...

Well, up to now we have done half of the job... Actually, we have the access to alter files that the server creates in data directory and its siblings as simple users (without being root). The difference is that when we create something of our own, for the server to be able to read and manipulate it correctly we will have to change its access rights by hand; but this is not that simple through the graphical environment without the terminal usage...

Έλεγχος του UniFi Controller Software

UniFi Controller Software Test

Σε αυτό το σημείο είμαστε έτοιμοι να δούμε αν το πρόγραμμα που μόλις εγκαταστήσαμε τρέχει σωστά. Το πρόγραμμα είναι γραμμένο σε Java άρα για να τρέξει αρκεί να μπούμε σε μια κονσόλα, ως υπερχρήστες και να εκτελέσουμε την εντολή:

At that point we are ready to test if the program we've just installed is functional. The program is written in Java so to execute it we need to enter a console and, as superusers run the command:

orion:/whateverpath # java -jar /opt/UniFi/lib/ace.jar start &

Με την εκτέλεση της εντολής αυτής θα παρατηρήσουμε ότι ο επεξεργαστής αρχίζει και λειτουργεί αρκετά. Μετά από μερικά δευτερόλεπτα, αν δεν έχει εμφανιστεί κανένα μήνυμα λάθους, ο server του UniFi θα έχει ξεκινήσει και ο επεξεργαστής θα έχει πέσει πάλι για ύπνο! Για να τον ελέγξουμε ότι λειτουργεί σωστά αρκεί σε ένα browser να δωθεί η διεύθυνση http://localhost:8080/

By executing this command we observe the processor working hard for a while. After some seconds, if there is no error message, UniFi server must be up and running and the processor must have fallen to sleep, again! To test that the server is well functioning the address http://localhost:8080/ must be entered in a browser.

Το πρώτο πράγμα που θα εμφανιστεί είναι το προειδοποιητικό μήνυμα για το άγνωστο ssl certificate. Φυσικά και θα πρέπει να γίνει αποδεχτή του και ο browser θα συνεχίσει στην τελική σελίδα που φαίνεται στο στιγμιότυπο:

The first thing appears on screen is a warning message for an unknown ssl certificate. Of course we must accept it and the browser will continue to the following snapshot:

Το configuration του συστήματος συνεχίζει με το πάτημα του "Next" κ.λ.π. Στο τέλος θα εμφανιστεί το τελικό login screen.

The system configuration goes on by pressing the "Next" button etc. In the end there will be the login screen.

Τώρα ο server έχει δημιουργήσει κάποια αρχεία ρυθμίσεων. Μπορούμε να τα δούμε στον κατάλογο /opt/UniFi/data παρατηρώντας ότι όλα τα αρχεία ανήκουν όντως στην ομάδα unifi όπως ακριβώς ήταν επιθυμητό:

The server has now created some settings files. We can find then in the /opt/UniFi/data directory, noticing that these files really belong to unifi group as we needed:

eliaschr@orion:/whateverpath # ls -l /opt/UniFi/data/
total 16
drwxrwsr--+ 2 root unifi 4096 May 10 22:29 backup
drwxrwsr--+ 4 root unifi 4096 May 10 22:30 db
-rw-rw-r--  1 root unifi 2184 May 10 22:29 keystore
-rw-rw-r--  1 root unifi  620 May 10 22:51 system.properties

Αν δεν έχετε ακόμα ενεργοποιημένο κάποιο UniFi Access Point στο δίκτυο δε θα καταλάβετε ένα "πρόβλημα" που υπάρχει. Αν όμως έχετε κάποιο Access Point στο δίκτυο, τότε ας δούμε και πάλι το μήνυμα που υπήρξε στο δεύτερο βήμα της παραμετροποίησης:

If you have not connected any UniFi Access Point in the network, yet, you will not have noticed a "problem". But if you have then, lets see the message we saw at the second step of the configuration wizard, again:

Το σύστημα μας λέει πολύ απλά ότι δεν βρίσκει κανένα Access Point...

Well, no devices have been discovered, says the system...

Κάποιος μπλοκάρει την επικοινωνία... (Firewall)

Someone Blocks The Communication... (Firewall)

Ο λόγος που δε μπορούμε να δούμε κανένα από τα Access Points που έχουμε συνδεδεμένα στο δίκτυό μας είναι ότι το Firewall του openSUSE μπλοκάρει την επικοινωνία. Αν γνωρίζουμε λίγα πράγματα από το firewall, τότε μπορούμε να ενεργοποιήσουμε το logging και να δούμε τι προσπαθεί να κάνει ο UniFi Controller το οποίο σταματάει εξ αιτίας του firewall. Θα δούμε μια επικοινωνία broadcast στην πόρτα 10001. Αν επιθυμούμε να έχουμε πρόσβαση στο πρόγραμμα και από άλλο υπολογιστή τότε χρειαζόμαστε και τις πόρτες 8080 και 8443. Αν χρειάζεστε και το shutdown θα πρέπει να ανοιχτεί και η πόρτα 8081. Αυτές είναι οι πόρτες που πρέπει να ανοίξουμε στο τείχος προστασίας για να μπορέσει να λειτουργήσει το σύστημα σωστά.

The reason we cannot see any of our Access Points through the UniFi Controller is the openSUSE Firewall, blocking the communication. If we are familiar with this firewall, then we can enable its logging and find out what UniFi Controller tries to do that is blocked by openSUSE Firewall. Then, we will notice a broadcast packet using port 10001. If we wish access to the program by another computer, also, we also need access to ports 8080 and 8443. If we also need shutdown access to the Access Point another port must be included in the list; port 8081. These ate the ports we have to unblock in the firewall settings in order for the system to function properly.

Επειδή μπορεί να θέλετε να αλλάξετε τις πόρτες που χρησιμοποιεί το σύστημα, τότε για να δείτε το πλήρες σετ που χρησιμοποιούνται από τις ρυθμίσεις, αρκεί να ανοίξετε το αρχείο data/system.properties. Απλά, στις πόρτες που θα ρυθμίσετε το firewall θα πρέπει να θυμηθείτε και την πόρτα 10001.

Because you may need to change the ports that the UniFi system uses, to find out the complete set (and alter them) you can open the data/system.properties file. Don't forget that together with these ports you also have to unblock 10001 in the firewall settings.

portal.http.port=8880
portal.https.port=8843
unifi.db.port=27117
unifi.http.port=8080
unifi.https.port=8443
unifi.shutdown.port=8081

Ας δούμε πως θα ανοίξουμε τις πόρτες που θέλουμε στο τείχος προστασίας. Αρχικά ανοίγουμε το YaST (αν δεν το έχουμε ήδη ανοικτό) και από την αριστερή στήλη επιλέγουμε την ομάδα "Security and Users", ενώ από τη δεξιά πλευρά ανοίγουμε το "Firewall"

Lets see how we can open the necessary ports. First, we open YaST (if we don't have it already), from its left side we choose "Security and Users", and from its right side we select "Firewall"

Στο παράθυρο που θα ανοίξει έχουμε και πάλι κατηγορίες ρυθμίσεων από την αριστερή μεριά και η δεξιά αλλάζει ανάλογα με την κατηγορία που θα επιλέξουμε. Η κατηγορία που ας ενδιαφέρει είναι η "Allowed Services"

In the window that appears there are some settings categories at its left side, while the right one changes according to the selected category. The needed one is "Allowed Services"

Επειδή οι πόρτες που θα ανοίξουμε στο τείχος προστασίας δεν ανήκουν σε κάποια γνωστή υπηρεσία θα πρέπει να τις ορίσουμε χειροκίνητα. Για να γίνει αυτό πατάμε το κάτω δεξιά πλήκτρο που ονομάζεται "Advanced...". Θα ανοίξει ένα καινούργιο παράθυρο στο οποίο θα βάλουμε τα νούμερα από τις πόρτες που μας ενδιαφέρουν. Η ρύθμιση φαίνεται στο ακόλουθο στιγμιότυπο:

Since the ports we want to open do not belong to a known service, we have to specify them by hand. To do that we just use the "Advanced..." button, at the down right side of the window. Another window appears in which we specify the number of the ports we want unblocked. They appear in the following snapshot:

Αν υπάρχουν και άλλες πόρτες ρυθμισμένες, απλά προσθέτετε αυτές που φαίνονται στο στιγμιότυπο και δεν σβήνετε τις παλιές. Πατώντας το "ΟΚ" επανερχόμαστε στην προηγούμενη οθόνη.

If there are also other ports set before, then just add the shown ones in the list, without removing the older. By pressing "ΟΚ" the system transfers us to the previous screen.

Αν ρυθμίζετε για πρώτη φορά το τείχος προστασίας, τότε πολύ πιθανό να χρειαστεί να ορίσετε και τη ζώνη προστασίας για την κάρτα δικτύου σας. Για να γίνει αυτό από την αριστερή μεριά του παραθύρου επιλέξτε την κατηγορία "Interfaces". Στη δεξιά μεριά εμφανίζονται όλες οι διαθέσιμες κάρτες δικτύου.

If this is the first time you edit the firewall settings then chances are you'll have to also set the interface zone for your network card. You can do that by selecting the "Interfaces" category to the left side of the window. Then, at the right one appear all the existed network cards.

Κάνοντας διπλό κλικ στην κάρτα δικτύου που μας ενδιαφέρει εμφανίζεται ένα παράθυρο για τον ορισμό ζώνης. Εκεί ορίσουμε τη ζώνη που μας ενδιαφέρει και πατάμε το "ΟΚ" επανερχόμενοι στο αρχικό παράθυρο.

By double clicking on the network interface we want to setup another dialogue box appears for its zone setting. Choose the zone you are interested in and press "ΟΚ", returning again to the previous screen.

Τελειώνουμε τις ρυθμίσεις του firewall πατώντας "Next" και στη συνέχεια "Finish". Μόλις τελειώσει το σύστημα την εφαρμογή των ρυθμίσεων, το τείχος προστασίας πλέον θα αφήνει την επικοινωνία να γίνει κανονικά.

We end the firewall settings by pressing "Next", followed by "Finish". After tyhe system finishes the application of the new settings, the firewall will be open for the communication of UniFi to the Access Point.

Χρήση του UniFi Controller ως service

Usage Of UniFi Controller As A Service

Το τελευταίο στάδιο είναι να οριστεί το UniFi Controller ως service, δηλαδή να ανοίγει και να κλείνει ανάλογα με το runlevel του υπολογιστή, χωρίς να χρειάζεται την επέμβαση του χρήστη.

The last step is to make UniFi Controller to run as service, meaning to start and stop according to which runlevel our computer uses, without the need of user intervention.

Για να γίνει αυτό θα πρέπει να δημιουργηθεί ένα script που να μπει μέσα στον κατάλογο /etc/init.d/. Αυτό το script θα πρέπει να έχει την ιδιότητα να ξεκινάει και να σταματάει τον server του UniFi, όπως ακριβώς γίνεται και στα υπόλοιπα services του συστήματος. Η βασική βοήθεια για τη συγγραφή αυτού του script είναι το /etc/init.d/skeleton. Με λίγο editing αυτού μπορούμε να φτιάξουμε το ακόλουθο:

For this to happen there must be a script in /etc/init.d/ directory, with the functionality of starting and stopping the UniFi server, in the same way as all the other services of the system do. /etc/init.d/skeleton is what will help up create the script in question. A little bit of editing and we create the following:

#!/bin/sh
#
#     Template SUSE system startup script for service unifid
#     Copyright (C) 1995--2005  Kurt Garloff, SUSE / Novell Inc.
#          
#     This library is free software; you can redistribute it and/or modify it
#     under the terms of the GNU Lesser General Public License as published by
#     the Free Software Foundation; either version 2.1 of the License, or (at
#     your option) any later version.
#
#     This library is distributed in the hope that it will be useful, but
#     WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#     Lesser General Public License for more details.
# 
#     You should have received a copy of the GNU Lesser General Public
#     License along with this library; if not, write to the Free Software
#     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA     
#
# /etc/init.d/unifid
#   and its symbolic link
# /usr/sbin/rcunifid
#
# System startup script for the UniFi Controller Server software of Ubiquity. See
# http://www.ubnt.com/
#
# LSB compatible service control script; see http://www.linuxbase.org/spec/
# 
# Note: This script uses functions rc_XXX defined in /etc/rc.status on
# UnitedLinux/SUSE/Novell based Linux distributions and is based on /etc/init.d/skeleton
# script provided by the openSUSE Community.
#
### BEGIN INIT INFO
# Provides:          unifid
# Required-Start:    $syslog $local_fs $network
# Should-Start:      $time ypbind smtp
# Required-Stop:     $syslog $local_fs $network
# Should-Stop:       ypbind smtp
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: unifid daemon providing Controller server for UniFi Access Points
# Description:       Start unifid to allow the UniFi Controller Software to be able to
#       control the UniFi Access Points of Ubiquity in the network. The softare runs in Java
#       and is installed in /opt/ directory.
### END INIT INFO
# 
# Any extensions to the keywords given above should be preceeded by 
# X-VendorTag- (X-UnitedLinux- X-SuSE- for us) according to LSB.
# 
# Notes on Required-Start/Should-Start:
# * There are two different issues that are solved by Required-Start
#    and Should-Start
# (a) Hard dependencies: This is used by the runlevel editor to determine
#     which services absolutely need to be started to make the start of
#     this service make sense. Example: nfsserver should have
#     Required-Start: $portmap
#     Also, required services are started before the dependent ones.
#     The runlevel editor will warn about such missing hard dependencies
#     and suggest enabling. During system startup, you may expect an error,
#     if the dependency is not fulfilled.
# (b) Specifying the init script ordering, not real (hard) dependencies.
#     This is needed by insserv to determine which service should be
#     started first (and at a later stage what services can be started
#     in parallel). The tag Should-Start: is used for this.
#     It tells, that if a service is available, it should be started
#     before. If not, never mind.
# * When specifying hard dependencies or ordering requirements, you can 
#   use names of services (contents of their Provides: section)
#   or pseudo names starting with a $. The following ones are available
#   according to LSB (1.1):
#       $local_fs               all local file systems are mounted
#                               (most services should need this!)
#       $remote_fs              all remote file systems are mounted
#                               (note that /usr may be remote, so
#                                many services should Require this!)
#       $syslog                 system logging facility up
#       $network                low level networking (eth card, ...)
#       $named                  hostname resolution available
#       $netdaemons             all network daemons are running
#   The $netdaemons pseudo service has been removed in LSB 1.2.
#   For now, we still offer it for backward compatibility.
#   These are new (LSB 1.2):
#       $time                   the system time has been set correctly
#       $portmap                SunRPC portmapping service available
#   UnitedLinux extensions:
#       $ALL                    indicates that a script should be inserted
#                               at the end
# * The services specified in the stop tags 
#   (Required-Stop/Should-Stop)
#   specify which services need to be still running when this service
#   is shut down. Often the entries there are just copies or a subset 
#   from the respective start tag.
# * Should-Start/Stop are now part of LSB as of 2.0,
#   formerly SUSE/Unitedlinux used X-UnitedLinux-Should-Start/-Stop.
#   insserv does support both variants.
# * X-UnitedLinux-Default-Enabled: yes/no is used at installation time
#   (%fillup_and_insserv macro in %post of many RPMs) to specify whether
#   a startup script should default to be enabled after installation.
#   It's not used by insserv.
#
# Note on runlevels:
# 0 - halt/poweroff                     6 - reboot
# 1 - single user                       2 - multiuser without network exported
# 3 - multiuser w/ network (text mode)  5 - multiuser w/ network and X11 (xdm)
# 
# Note on script names:
# http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/scrptnames.html
# A registry has been set up to manage the init script namespace.
# http://www.lanana.org/
# Please use the names already registered or register one or use a
# vendor prefix.

# First define a small helper function that converts the number of lines produced by ps
# shell command to a number of LSB status. Needed by the "status" parameter
function ConvertOut() {
        if (( $1 < 2 ))
        then
                CNVOUT=3
        else
                CNVOUT=0
        fi
        return $CNVOUT
}

# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
# java executable must be installed...
JAVA_BIN=/usr/bin/java
test -x $JAVA_BIN || { echo "Cannot find java executable in $JAVA_BIN, or java is not installed..."; 
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }
# Also, mongoDB must be installed. The extra step here is that there must be a valid link in
# /opt/UniFi/bin/mongod that points to the mongod executable
MONGOD_BIN=/opt/UniFi/bin/mongod
if [ ! \( -e $MONGOD_BIN \) ]
then
        echo "Cannot find mongod executable in $MONGOD_BIN, or mongoDB is not installed..."; 
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi;
fi
# Last but not least, the java jar file should be present. No need to be executable, because
# it is executed via java -jar ...
UNIFID_BIN=/opt/UniFi/lib/ace.jar
test -e $UNIFID_BIN || { echo "Cannot find UniFi Controller executable in $UNIFID_BIN, or the controller software is not installed..."; 
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }
# Source LSB init functions
# providing start_daemon, killproc, pidofproc, 
# log_success_msg, log_failure_msg and log_warning_msg.
# This is currently not used by UnitedLinux based distributions and
# not needed for init scripts for UnitedLinux only. If it is used,
# the functions from rc.status should not be sourced or used.
#. /lib/lsb/init-functions

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     be verbose in local rc status and clear it afterwards
#      rc_status -v -r  ditto and clear both the local and overall rc status
#      rc_status -s     display "skipped" and exit with status 3
#      rc_status -u     display "unused" and exit with status 3
#      rc_failed        set local and overall rc status to failed
#      rc_failed   set local and overall rc status to 
#      rc_reset         clear both the local and overall rc status
#      rc_exit          exit appropriate to overall rc status
#      rc_active        checks whether a service is activated by symlinks
. /etc/rc.status

# Reset status of this service
rc_reset

# Return values acc. to LSB for all commands but status:
# 0       - success
# 1       - generic or unspecified error
# 2       - invalid or excess argument(s)
# 3       - unimplemented feature (e.g. "reload")
# 4       - user had insufficient privileges
# 5       - program is not installed
# 6       - program is not configured
# 7       - program is not running
# 8--199  - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
# 
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signaling is not supported) are
# considered a success.

case "$1" in
    start)
        echo -n "Starting unifid "
        ## Start daemon with startproc(8). If this fails
        ## the return value is set appropriately by startproc.
        /sbin/startproc $JAVA_BIN  -jar $UNIFID_BIN start

        # Remember status and be verbose
        rc_status -v
        ;;
    stop)
        echo -n "Shutting down unifid "
        ## Stop daemon with killproc(8) and if this fails
        ## killproc sets the return value according to LSB.

        #/sbin/killproc $FOO_BIN
        $JAVA_BIN -jar $UNIFID_BIN stop

        # Remember status and be verbose
        rc_status -v
        ;;
    try-restart|condrestart)
        ## Do a restart only if the service was active before.
        ## Note: try-restart is now part of LSB (as of 1.9).
        ## RH has a similar command named condrestart.
        if test "$1" = "condrestart"; then
                echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
        fi
        $0 status
        if test $? = 0; then
                $0 restart
        else
                rc_reset        # Not running is not a failure.
        fi
        # Remember status and be quiet
        rc_status
        ;;
    restart)
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        $0 start

        # Remember status and be quiet
        rc_status
        ;;
    force-reload)
        ## Signal the daemon to reload its config. Most daemons
        ## do this on signal 1 (SIGHUP).
        ## If it does not support it, restart the service if it
        ## is running.

        echo -n "Reload service unifid "
        ## if it supports it:
        #/sbin/killproc -HUP $FOO_BIN
        #touch /var/run/FOO.pid
        #rc_status -v

        ## Otherwise:
        $0 try-restart
        rc_status
        ;;
    reload)
        ## Like force-reload, but if daemon does not support
        ## signaling, do nothing (!)

        # If it supports signaling:
        echo -n "Reload service unifid "
        #/sbin/killproc -HUP $FOO_BIN
        #touch /var/run/FOO.pid
        #rc_status -v

        ## Otherwise if it does not support reload:
        $0 try-restart
        rc_status
        #rc_failed 3
        #rc_status -v
        ;;
    status)
        echo -n "Checking for service unifid "
        ## Check status with checkproc(8), if process is running
        ## checkproc will return with exit status 0.

        # Return value is slightly different for the status command:
        # 0 - service up and running
        # 1 - service dead, but /var/run/  pid  file exists
        # 2 - service dead, but /var/lock/ lock file exists
        # 3 - service not running (unused)
        # 4 - service status unknown :-(
        # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)

        # NOTE: checkproc returns LSB compliant status values.
        # /sbin/checkproc $FOO_BIN
        # NOTE: rc_status knows that we called this init script with
        # "status" option and adapts its messages accordingly.
        # The only way to test if the java program runs is to check it through ps:
        JAVA_COUNT=$(ps aux |grep $UNIFID_BIN | wc -l)
        # The ps aux shell command if used with the grep shell command, returns one line for grep
        # and another line for the real $UNIFID_BIN file. So the result of the executed command is
        # 1 if the server is stopped, 2 if the server is started. We need to convert these values
        # into valid LSB compliant ones, meaning 3 and 0 respectively. The easiest way to do this
        # is to use a function that returns the correct status
        ConvertOut $JAVA_COUNT
        rc_status -v
        ;;
    #probe)
        ## Optional: Probe for the necessity of a reload, print out the
        ## argument to this init script which is required for a reload.
        ## Note: probe is not (yet) part of LSB (as of 1.9)

        #test /etc/FOO/FOO.conf -nt /var/run/FOO.pid && echo reload
        #;;
    *)
        echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"
        exit 1
        ;;
esac
rc_exit

Αυτό το script μπορείτε να το κάνετε copy/paste από εδώ και να το σώσετε μέσα στον κατάλογο του χρήστη με την ονομασία unifid. Οι ακόλουθες εντολές πρέπει να εκτελεστούν σε μια κονσόλα από τον υπερχρήστη για να δημιουργηθεί όλη η υποδομή του service:

You can copy/paste the script from here and save it with name unifid in the user's home directory (or werever you wish). The following commands must be executed in a console with superuser priviledges, for the service infrastructure to be created:

orion:/home/eliaschr # cp unifid /etc/init.d/
orion:/home/eliaschr # chmod 0755 /etc/init.d/unifid
orion:/home/eliaschr # ln -s /etc/init.d/unifid /sbin/rcunifid
orion:/home/eliaschr # ln -s /etc/init.d/unifid /usr/sbin/rcunifid

Τώρα θα τεστάρουμε το script και όσα έγιναν για τη χρήση του UniFi ως service. Για να γίνει αυτό θα πρέπει μέσα από το YaST να δούμε τα διαθέσιμα services και να προσπαθήσουμε να ανοίξουμε και να κλείσουμε αυτό που μας ενδιαφέρει, το unifid. Αφού ανοίξουμε το YaST (αν δεν το έχουμε ακόμα ανοικτό) και δώσουμε το password του root θα πρέπει να κάνουμε τα ακόλουθα:

We can test this script and everything done to make UniFi run as service by using YaST. Through it we will see all the available services and we will try to start and stop the one we created, unifid. After running YaST (again, if it is not still running) and enter the root password we must do the following:

Ανοίγουμε το "System Services (Runlevel)" από την ομάδα επιλογών "System".

Select the "System Services (Runlevel)" from the "System" group.

Στο παράθυρο που ανοίγει θα πρέπει να περιμένουμε λίγο για να αναγνωρίσει το σύστημα όλα τα services που υπάρχουν και να τα ρωτήσει αν είναι ενεργοποιημένα ή όχι. Μετά από λίγο που θα ολοκληρωθεί η λίστα, μπορούμε να βρούμε το service που μόλις δημιουργήσαμε, με την ονομασία unifid.

In the window that opens we have to wait some seconds for the system to finish service scanning and find out wether they are running or not. In a while, the list will be complete and there we can search for the service we created with the name unifid.

Ακόμα πιο ενδιαφέρον είναι αν γυρίσουμε σε Expert Mode, με επιλογή του από το επάνω μέρος της οθόνης. Τότε το παράθυρο μετασχηματίζεται, δίνοντας ακόμα περισσότερες πληροφορίες κι επιλογές:

It becomes more interesting if we select the Expert Mode at the top of the window. The window changes, giving more information and options:

Μπορούμε να δοκιμάσουμε την ενεργοποίηση και απενεργοποίηση του service από το κουμπί "Start/Stop/Refresh". Μπορούμε να δούμε την κατάσταση του service αν από το πλήκτρο αυτό επιλέξουμε το "Refresh status...". Αρχικά είναι απενεργοποιημένο. Το αναδυόμενο παράθυρο μας ενημερώνει για αυτή την κατάσταση.

We can test the activation and deactivation by using the "Start/Stop/Refresh" button. We can also observe the status of the service if, from the same button, in its dropdown list we select "Refresh status..." option. In the beginning it is stopped. The pop-up window informs us for this.

Αν δοκιμάσουμε να ενεργοποιήσουμε το unifid από το πλήκτρο με την επιλογή "Start...". Θα ενημερωθούμε ανάλογα:

Lets try to activate unifid from the button in question, by choosing "Start...". We will be informed:

Φυσικά το αποτέλεσμα θα το δούμε και στη λίστα του κεντρικού παραθύρου. Μπορούμε να ξαναδοκιμάσουμε την κατάσταση που επιστρέφει το script όταν το service είναι ενεργοποιημένο, ξανά με την επιλογή "Refresh status...".

Of course, we will also notice the result in the list of the main window. We can try again to see what is the status that the script returns, now that the service is up and running, again using the "Refresh status..." option.

Ας το απενεργοποιήσουμε πάλι να δούμε την αντίδραση του συστήματος. Επιλέγουμε το "Stop...". Το παράθυρο που θα μας εμφανιστεί είναι το ακόλουθο:

OK. Now, lets deactivate the service again to see the system's reaction. Choose "Stop...". The following window must appear:

Φυσικά, κάθε φορά που κάνουμε start το service ο επεξεργαστής εργάζεται αρκετά για ένα χρονικό διάστημα. Όταν τελειώσει, ο server μας είναι ενεργοποιημένος.

Naturally, each time we start the service, the processor starts working hard for a small period of time. When it finishes then our server is up.

Τέλος, όταν ενεργοποιήσουμε την υπηρεσία στο σύστημα από το κάτω δεξιά κουμπί "Set/Reset", θα δούμε ότι το service θα ενεργοποιηθεί στα runlevels 3 και 5, όπως ακριβώς τα ρυθμίσαμε στο script που γράψαμε.

Finaly, after we activate permanently the service using the "Set/Reset" button that lies at the bottom right of the window, we can see that the service is marked for starting at runlevels 3 and 5. This is described in the script we created earlier.

Όταν το ρυθμίσετε όπως θέλετε μπορείτε να αποθηκεύσετε τις ρυθμίσεις πατώντας το πλήκτρο "ΟΚ".

After you choose the settings at your will, you can store them by pressing "ΟΚ".

Από τώρα και στο εξής δεν είναι ανάγκη να ανοίγετε την κονσόλα για να ξεκινάτε το UniFi Controller Software. Εκτός του ότι μπορείτε να το έχετε να ανοίγει με τον υπολογιστή σας, μπορείτε να το ενεργοποιείτε ή απενεργοποιείτε από το YaST.

From now on, there is no need to open a terminal and start UniFi Controller Software by hand. And besides having it starting automatically while your operating system boots, you can activate and deactivate it at will through YaST.

Όταν το unifid είναι ενεργοποιημένο τότε μπορείτε να κάνετε login σε αυτό από τον browser σας, στη διεύθυνση http://localhost:8080

When unifid is activated, you can login to it through your browser, at the address http://localhost:8080

Συμπεράσματα

Conclusions

Παρότι το πρόγραμμα της εταιρίας Ubiquity έχει γραφτεί σε java και στην αρχή υπήρχαν αμφοβολίες πως θα μπορούσε να λειτουργήσει σωστά ως service, τελικά με λίγο κόπο ακόμα κι αυτό μπόρεσε να λειτουργήσει. Τώρα το σύστημα του ασύρματου δικτύου, μπορεί να παραμετροποιηθεί για τις ανάγκες ενός ξενοδοχείου, ενώ θα μπορούσε να λειτουργήσει ακόμα και σε ένα σύστημα small computer όπως π.χ. το Raspberry Pi, το Cubieboard, το Beagleboard ή ότι άλλο έχετε υπόψη σας :)

Even though Ubiquity's program is written in Java language and in the beginning there was doubt that it could work as a system service, finaly, with a small effort we managed to make it work. No the UniFi Wireless System can be used for covering the needs of a hotel, and it may even run in a small computer system as ie. a Raspberry Pi, Cubieboard, Beagleboard or anyother alike you have in your mind :)

Γενικά το UniFi είναι πολύ ενδιαφέρον και αν και ασχολήθηκα κάμποσο μαζί του ξέρω πολύ καλά πως έχει κρυφά σημεία που δεν τα έχω δει ακόμα!

In general, UniFi is very interesting and, even though I've used it a lot, I know well that there are so many "hidden" things that I haven't seen, yet!

Μια ακόμα επισήμανση που έχω να κάνω είναι πως όλη η διαδικασία ξεκίνησε αρκετό καιρό πριν κι έγινε σε σύστημα openSUSE 12.2

One more note is that all the job is done a while ago and that all the described process is done in openSUSE 12.2

Ηλίας Χρυσοχέρης

Elias Chrysocheris

Σάββατο 30 Μαρτίου 2013

Οδηγός Εγκατάστασης openSUSE 12.3



Το openSUSE είναι μια διανομή Linux αρκετά πλούσια σε προγράμματα από την πρώτη στιγμή που εγκαθίσταται στον υπολογιστή μας. Η κοινότητα της διανομής είναι αρκετά ενεργή και η παραγωγή δε θα μπορούσε να είναι διαφορετική από άψογη. Σε γενικές γραμμές κάθε 8 περίπου μήνες βγαίνει και μια καινούργια έκδοση του λειτουργικού, με όλα τα καινούργια καλούδια, τόσο σε γραφικά περιβάλλοντα, όσο και σε θέματα ασφάλειας της καρδιάς ενός λειτουργικού· του πυρήνα.


Πριν λίγες ημέρες η κοινότητα του openSUSE μας έκανε την έκπληξη να βγάλει καινούργια έκδοση μέσα σε χρόνο 6 μηνών από την προηγούμενη! Το openSUSE 12.3 βγήκε στις 13 Μαρτίου 2013 και ήδη έχει καταλάβει πολλούς υπολογιστές. Για άλλη μια φορά βλέπουμε στους υπολογιστές μας ένα διαμάντι ομορφιάς και σταθερότητας. Όποιος επιθυμεί να το εγκαταστήσει μπορεί να το κατεβάσει από την ιστοσελίδα της κοινότητας, τόσο σε έκδοση για 32 bit όσο και για 64. Υπάρχουν και εναλλακτικά Live CDs για τον έλεγχο της διανομής στο σύστημά σας στην ίδια σελίδα, ή ακόμα και CD που μπορείτε να κάνετε την εγκατάσταση του λειτουργικού εξ ολοκλήρου από το διαδίκτυο.


Ο Σύλλογος Φίλων Ανοικτού Λογισμικού Χανίων έχει, εδώ και χρόνια, ξεκινήσει να παράγει τον Ελληνικό οδηγό εγκατάστασης της εν λόγω διανομής, έτσι δε θα γινόταν να μην ενημερωθεί και ο οδηγός αυτός με βάση την καινούργια έκδοση. Συγκεκριμένα πριν από δύο ημέρες αναρτήθηκε ο καινούργιος οδηγός στην ιστοσελίδα του Συλλόγου, στο κλασικό σημείο του wiki του, την Τεκμηρίωση. Εκεί, όποιος ενδιαφέρεται μπορεί να κατεβάσει τον οδηγό και να εγκαταστήσει με ασφάλεια το λειτουργικό στον υπολογιστή του. Ο οδηγός όπως πάντα είναι πλούσιος σε ύλη, χωρίς να είναι υπερβολικά μεγάλος, πάει τον αναγνώστη βήμα βήμα με τη βοήθεια εικόνων στιγμιοτύπων, έτσι ώστε να γίνει σωστά η εγκατάσταση και το λειτουργικό να περιέχει όσα χρειάζεται ο καθημερινός χρήστης υπολογιστών.



Μια καινοτομία του οδηγού εγκατάστασης, που υπάρχει από τη πρώτη στιγμή της συγγραφής του, είναι πως δε μένει μόνο στην εγκατάσταση. Ένας από τους σκοπούς του είναι να μην αφήσει το χρήστη με την εντύπωση "Το εγκατάστησες, τώρα χρησιμοποίησε το μόνος σου!", αλλά να τον βοηθήσει ακόμα παραπέρα στο να του δείξει και πώς θα κάνει τα βασικά πράγματα. Ο οδηγός δείχνει πως γίνεται η παραμετροποίηση του συστήματος μέσω του YaST2, πως γίνονται κάποιες παραμετροποιήσεις της επιφάνειας εργασίας κ.λ.π, έτσι ώστε ένας καινούργιος χρήστης να μπορεί εύκολα να βρει αυτά που χρειάζεται με λιγότερο ψάξιμο και όχι τόσο στα τυφλά.


Ο οδηγός έχει δημιουργηθεί σε LaTeX, όπως αρμόζει σε έναν οδηγό για ανοικτό λογισμικό. Εκδίδεται σε άδεια χρήσης Creative Commons ώστε όποιος θέλει να μπορέσει να πάρει τον κώδικα και να τον χρησιμοποιήσει, να τον παραλλάξει ή να παράγει αυτό που χρειάζεται παίρνοντας ιδέες από αυτόν. Τον κώδικα θα τον βρείτε στο ίδιο σημείο που θα βρείτε και τον οδηγό.


Ελπίζουμε για άλλη μια φορά να σας φανεί χρήσιμος και να σας γλυτώσει από κακοτοπιές :)


Χρυσοχέρης Ηλίας

Τρίτη 22 Ιανουαρίου 2013

MK809 Android TV και Development ModeMK809 Android TV in Development Mode

Εισαγωγή

Introduction

Πριν από λίγο καιρό αγοράσαμε, εγώ κι ένας φίλος, από ένα MK809. Πρόκειται για ένα μικρό stick που περιέχει ένα διπλοπύρηνο ARM μικροελεγκτή στα 1.6GHz με εσωτερική μνήμη 4GB και 1GB DDR3. Γενικά, έχει πολλά καλούδια, αλλά το ωραιότερο είναι πως τρέχει Android 4.1.1.

A few days ago, me and a friend of mine bought a MK809 each. It is a small stick that contains a dual core ARM processor running at 1.6GHz, with internal storage memory of 4GB and 1GB of DDR3 RAM. It provides many nice features but the better of them is it runs Android 4.1.1.

Πήραμε το εργαλείο στα χέρια μας και αρχίσαμε να παίζουμε μαζί του. Εγκαταστήσαμε ότι εφαρμογές και παιχνίδια θέλαμε, XBMC 12.0 και άλλα. Σερφάραμε στο Internet και ρίξαμε μέσα και ένα VNC έτσι για να κάνουμε τον χαβαλέ μας. Όλα ήταν τέλεια!

When this small tool reached our hands we started "playing" with it. We installed whatever applications and games we wanted, XBMC 12.0 and many more. We surfed the internet and we also installed a VNC client just for fun. It was awesome!

Angry Birds, γιατί τα παιχνίδια δεν είναι μόνο... για να παίζουμε!

Angry Birds, because games are not only... to play!

Ο τίτλος της παραγράφου φαίνεται λίγο περίεργος;!!! Ναι. Εδώ και αρκετά χρόνια ξέρουμε πολύ καλά πως τα πάντα γίνονται για τα παιχνίδια. Η πρώτη γλώσσα προγραμματισμού που έμαθα ήταν η BASIC μιας και έπαιζα με το αγαπημένο μου ZX Spectrum της εποχής, αλλά η δεύτερη ήταν η Assembly του για να μπορώ να σπάω τα παιχνίδια και να τους βάζω άπειρες ζωές κ.λ.π. Με παρόμοιο τρόπο ξεκίνησε και αυτή εδώ η ιστορία που καταλήγει στο παρών blog post· μόνο που αυτή τη φορά το παιχνίδι ήταν η δημοφιλής σειρά Angry Birds και ο τρόπος στο να μεταφέρουμε τα αστεράκια που έχουμε από το κινητό μας στο MK809.

Do you find the title of this paragraph strange?!!! Well, we know that games are responsible for many things that happened on computer science and evolution all these past years. The first programming language I learned was BASIC since I owned a ZX Spectrum then, but the second one is Z80 Assembly for that computer just to be able to crack its games and have infinite lives etc. In a similar way this story started and ended with this blog post; the only difference is the very popular series of Angry Birds games and the way to transfer our stars from our smartphone to MK809.

Τα διάφορα προγράμματα για Backup ΔΕΝ ΛΕΙΤΟΥΡΓΟΥΝ!...

Various backup applications DO NOT WORK!...

Αρχικά οι δοκιμές ήταν να μεταφέρουμε τα αστεράκια που με τόσο κόπο είχαμε κερδίσει όλα αυτά τα χρόνια που έχουμε λιώσει τις touchscreen των κινητών μας, με τη βοήθεια backup προγραμμάτων που υπάρχουν στο Google Play... Δεν υπήρξε καμιά επιτυχία σε αυτό. Τι να δοκιμάζουμε προγράμματα που κάνουν backup/restore στην κάρτα μνήμης... Τι να δοκιμάζουμε άλλα που δουλεύουν και μέσω dropbox... Τίποτα. Μόνο αποτυχίες.

In the beginning we tried to transfer the Angry Birds stars that we gained in such a hard play, melting the touchscreens of our smartphones! We used some backup applications, downloaded from Google Play... Well,... no success... We tried applications that backup and restore the stars in memory card... other programs that use dropbox... Nothing. Failure... No Success at all!

Κάποια στιγμή, θυμήθηκα ότι παλιότερα μέσω του adb που εχει το Android Development Toolkit για το Eclipse, μπορούσα και έγραφα αρχεία μέσα στο κινητό μου ακόμα και αν δεν ήμουν root. Ψάχνοντας στο Internet βρήκαμε κάποιο blog post που περιγράφει μια τέτοια διαδικασία, οπότε ήμουν σίγουρος πως θα πετυχαίναμε το επιθυμητό αποτέλεσμα!...

At a moment I remembered that once, using adb which is in Android Development Toolkit for Eclipse, I could write files in my cellphone even if I hadn't root access. Searching the internet we found a blog post that describes such a procedure, so I was sure we could do the trick successfully!...

ΜΚ809 USB Development Mode

Ήρθε η ώρα για το ψητό! Ας συνδέσουμε το MK809 στον υπολογιστή και να το δούμε από το adb του Android Development Toolkit. Τρέχουμε από ένα τερματικό την εντολή adb devices και... Πού είναι το ΜΚ809, οέωωω! Χμμμ... Κάτι δεν πάει καλά!

Time to play! Lets connect MK809 to the computer and see if we can use adb of Android Development Toolkit. In a terminal we execute the command adb devices and... What! Were the heck is MK809?!!! Hmmm... Something is wrong!

Μετά από αρκετή αναζήτηση στο internet, βρήκα ένα blog post που έλεγε πώς να κάνεις root το ΜΚ809, αλλά... Δεν δούλεψε... Ήταν για bugindows... Επίσης, περισσότερο έμοιαζε για άλλη έκδοση του MK80*, μιας και το blog post ανέφερε κάτι για μια πλαϊνή θύρα USB On-The-Go. Αυτή η θύρα δεν υπάρχει στο MK809.

Again, after a lot of internet searching, we found another blog post describing how to root ΜΚ809, but... didn't work... It was for bugindows... At the same time looked that is was for another MK80* device, as blog post was using a USB On-The-Go port at the side of the device. MK809 does not have a USB connector at its side.

Φυσικά το post μου έδωσε μερικές ιδέες μιας και ήταν κοντά στην πραγματικότητα. Μετά από μερικά lsusb και δοκιμές, βρήκα ότι το ΜΚ809 το έβλεπε ο υπολογιστής μου ότι συνδεόταν, το λειτουργούσε σαν USB Stick, αλλά developer mode δεν υπήρχε:

Of course, that post gave me some ideas as it was for a similar device, there should be similarities in the logic of the workflow. After some lsusb and tests, I found out that my computer could find the ΜΚ809 upon connection and it was using it as a USB memory stick, but there was no developer's mode:

orion:/etc/udev # lsusb
Bus 001 Device 002: ID 0bda:0158 Realtek Semiconductor Corp. USB 2.0 multicard reader
Bus 002 Device 002: ID 5986:0130 Acer, Inc 
Bus 002 Device 027: ID 2207:0010  
Bus 003 Device 005: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Η τρίτη γραμμή του lsusb είναι που φαίνεται λίγο παράξενη. Αυτή είναι η γραμμή που προστίθεται όταν συνδέσουμε το MK809. Μετά από ώριμη (;) σκέψη καταλήγουμε στο ότι το σύστημα δεν έχει τον απαραίτητο driver για να το λειτουργήσει...

The third line of the lsusb snapshot (boldfaced) looks a little bit weird. That is the added line each time we connect MK809. After some mature (?!!! :)) thinking we end up to the conclusion that the system does not have the correct driver module to use it...

Η πραγματικότητα είναι ακόμα πιο περίεργη. Ψάχνοντας λίγο στο διαδίκτυο παρατήρησα ότι το RK3066 που είναι το ολοκληρωμένο που χρησιμοποιεί το MK809 δεν έχει κάτι ιδιαίτερο, εκτός του ότι είναι αρκετά νέο! Άρα, οι ήδη υπάρχοντες drivers θα μπορούσαν να το λειτουργήσουν μια χαρά, μόνο που ήταν αρκετά νέο device για να το αναγνωρίζουν!... Εδώ ξεκινάει ένα μικρό παιχνίδι με το udevd!

Reality is even more weird... Searching a little more the internet (what else could we do?) we found that RK3066, which is the processor of MK809 does not have anything particular compared to other similar devices, except that it is a very new chip. So, it seemed the already existed drivers could handle it without problem, but they didn't know its existence!... Time to play with udevd!

udevd rules για την αναγνώριση του ΜΚ809

udevd rules to recognise ΜΚ809

Άντε να δούμε τι θα κάνουμε για να αναγνωρίσει το σύστημα το καινούργιο chip του MK809. Καταρχήν θα πρέπει να προσθέσουμε μια συνθήκη στο udevd που να αναγνωρίζει το USB Device με id 2207:0010. Στη διανομή openSUSE οι κανόνες του udevd βρίσκονται μέσα στον κατάλογο /etc/udev/rules.d/ κι εκεί θα πρέπει να προσθέσουμε το δικό μας. Επειδή η κάθε διανομή έχει τα δικά της, καλό θα είναι για μια άλλη διανομή να βρείτε πού υπάρχουν οι κανόνες και να κάνετε την προσθήκη σε εκείνο τον κατάλογο. Το αρχείο που θα φτιάξουμε είναι το 99-MK809-Android.rules:

Lets see what can we do to make our system recognise the new chip that MK809 uses. Our first step is to add a udevd rule to recognise USB Devices with id 2207:0010. In openSUSE udevd rules lie in /etc/udev/rules.d/ directory. Since in every distribution uses its own directory, it would be nice to find out (if you don't already know) which directory is the appropriate one for this job and make the described addition there. Th file we will add is named 99-MK809-Android.rules:

eliaschr@orion:~>su
Password: 
orion:/home/eliaschr # cd /etc/udev/rules.d/
orion:/etc/udev/rules.d # vi 99-MK809-Android.rules

#
# udev rules file for MK809 Android TV Stick
#
# Added by me (eliaschr) so as to be able to use MK809 in development mode
# To use it, first enable "USB debugging" in "Developer options" (System Settings)
# and then in the "USB" tab (Device Settings) select "Connect to PC".
#
SUBSYSTEM=="usb", ATTR{idVendor}=="2207", ATTR{idProduct}=="0010", , MODE="0666", SYMLINK+="MK809_adb"

Σώστε το αρχείο και βγείτε από το vi. Φυσικά μπορείτε να χρησιμοποιήσετε όποιον editor θέλετε, ή ακόμα και μια γραμμή εντολής που να φτιάχνει το αρχείο, αρκεί το αποτέλεσμα να είναι το ίδιο.

Save the file and quit vi. Of course you can use whatever text editor you like, or even a cat bash command (or any other you like) to create the file, as long as it produces the same result.

ΕΝΗΜΕΡΩΣΗ: Σε ένα φίλο που έχει ένα κινητό Huaway Ideos3 έπρεπε να προσθέσουμε ακόμια μια γραμμή στο αρχείο του udev που μόλις δημιουργήσαμε για να μπορέσει το σύστημα να το διαβάσει:

UPDATE: A friend of mine owns a Huaway Ideos3. We had to add another line for that in the udev rule we created in order to make the system recognise his cell phone also:

SUBSYSTEM=="usb", ATTR{idVendor}=="12d1", ATTR{idProduct}=="1038", , MODE="0666", SYMLINK+="Ideos3_adb"

Το επόμενο βήμα είναι να πούμε στο adb να ψάχνει και αυτή τη συσκευή. Για να γίνει αυτό θα πρέπει να πειράξουμε το αρχείο adb_usb.ini που υπάρχει μέσα στον κατάλογο .android στο home directory του χρήστη μας:

Next step is to make adb to include this device in its search process. In order to make it possible we have to alter adb_usb.ini file in .android subdirectory in our user's home:

eliaschr@orion:~> cd .android
eliaschr@orion:~/.android> vi adb_usb.ini

Εκεί προσθέτουμε μια γραμμή που περιέχει το:

There, we add a line containing just:

0x2207

Σώστε το αρχείο και βγείτε από το vi. Μια σημείωση είναι πως αν είχαμε χρησιμοποιήσει πιο πριν το adb, τότε ο server του Android Development Toolkit θα τρέχει, που σημαίνει πως για να διαβάσει τις καινούργιες ρυθμίσεις του αρχείου που μόλις πειράξαμε θα πρέπει να τον ξαναξεκινήσουμε. Η εκκίνηση γίνεται από το πρόγραμμα adb. Απλά θα πρέπει εμείς να τον σκοτώσουμε. Αρκεί να εκτελέσουμε την ακόλουθη εντολή:

Save the file and exit vi. Note that if we used adb earlier while making our experiments, then the Android Development Toolkit server is up and running, meaning that we have to restart it in order to read the new settings. You can restart it using adb. Just kill it first with the following command:

eliaschr@orion:~> adb kill-server

Το τελευταίο κομμάτι που πρέπει να γίνει είναι να υποχρεώσουμε το udevd να διαβάσει τους καινούργιους κανόνες:

The last part is to force udevd to read the new rules:

eliaschr@orion:~>su
Password: 
orion:/home/eliaschr # udevadm control --reload-rules
orion:/home/eliaschr #

Στη συνέχεια συνδέουμε το MK809 με ένα καλώδιο micro USB στον υπολογιστή μας. Στα Settings, από την αριστερή μεριά, στο block SYSTEM επιλέγουμε το "{} Developer options". Στη δεξιά μεριά της οθόνης βλέπουμε όλες τις διαθέσιμες ρυθμίσεις. Αν είναι απενεργοποιημένες, τότε θα πρέπει να τις ενεργοποιήσουμε από τον διακόπτη πάνω και δεξιά στην οθόνη, γυρίζοντάς τον στο "ΟΝ". Από τις επιλογές ενεργοποιούμε τις δύο βασικές στο block "DEBUGGING", που είναι οι "USB debugging" και "Allow mock locations". Η επιλογή "Select debug app" δεν περιέχει κάποια επιλογή, αλλά αυτό δεν μας ενοχλεί.

Lets connect MK809 using a micro USB cable to our computer. Also in MK809 screen, in Settings, at the left side of the screen, in SYSTEM block we select "{} Developer options". In the right part of the screen we can see all the avilable options. If they are disabled we have to enable them first using the switch widget at the top right of the screen, by sliding it to "ΟΝ". From the available options we select the two basic ones in "DEBUGGING" block; they are "USB debugging" and "Allow mock locations". "Select debug app" option does not contain any value, but this is valid.

Τέλος, από την αριστερή πλευρά της οθόνης των ρυθμίσεων επιλέγουμε το "USB" στο block "Device". Τότε στη δεξιά μεριά της οθόνης εμφανίζεται η μόνη επιλογή "Connect to PC". Μόλις την ενεργοποιήσουμε θα δούμε το MK809 να εμφανίζει στην οθόνη στο κάτω μέρος της το μήνυμα "USB debugging connected". Στον υπολογιστή μας θα δούμε ότι το adb έχει αναγνωρίσει το MK809 αν εκτελέσουμε την εντολή:

Finally, on the left side of the settings screen we select "USB" in the "Device" block. Then, in the right side we can see the one and only "Connect to PC" option. When we enable this option we can MK809 ahowing a message at the bottom of the screen saying "USB debugging connected". On out computer now, we can use adb and confirm that it can recognise MK809 device, using the command:

eliaschr@orion:~> adb devices
List of devices attached 
0123456789ABCDEF        device

eliaschr@orion:~> 

Μπορούμε, λοιπόν, να δουλέψουμε κανονικά το ΜΚ809 σε Developer Mode.

So, we can use MK809 in Developer Mode without problems.

Bonus για τους αναγνώστες του άρθρου: Angry Birds - Τα scores μας!

Bonus part ro the readers of this article: Angry Birds - Lets copy our scores!

Λίγες τεχνικές λεπτομέρειες
Some technical details

Η σειρά των παιχνιδιών Angry Birds έχει κάνει γερό πάταγο και δε νομίζω να υπάρχει κανένας που να μην έχει ασχοληθεί έστω και λίγο μαζί τους. Θα ξεκινήσουμε από μερικές μικρές λεπτομέρειες σχετικά με τα δεδομένα που μας ενδιαφέρουν.

The Angry Birds series of games is very popular these days. I don't thing there is anybody that hasn't played one of these games, even for a short time. We will present some of its technical details for their necessary data storage.

Αυτή τη στιγμή υπάρχουν τα εξής παιχνίδια της εν λόγω σειράς:

At the time of this writing the series of these games has:

  • Angry Birds
  • Angry Birds Seasons
  • Angry Birds Rio
  • Angry Birds Space
  • Angry Birds Star Wars

Φυσικά μιλάμε για τις δωρεάν εκδόσεις των παιχνιδιών. Το κάθε ένα από αυτά κρατάει κάποια στοιχεία που έχουν να κάνουν με τα scores των παικτών, κάποια settings κ.λ.π.

Of course we are talking about the free versions of the games. Each one writes some data to keep players' scores, settings etc.

Τα directories που καταγράφονται οι πληροφορίες μέσα σε μια Android συσκευή, είναι:

The directories that hold these files in an Android device are:

  • Angry Birds: /data/data/com.rovio.angrybirds/
  • Angry Birds Seasons: /data/data/com.rovio.angrybirdsseasons/
  • Angry Birds Rio: /data/data/com.rovio.angrybirdsrio/
  • Angry Birds Space: /data/data/com.rovio.angrybirdsspace.ads/
  • Angry Birds Star Wars: /data/data/com.rovio.angrybirdsstarwars.ads.iap/

Μέσα εκεί υπάρχει ένας υποκατάλογος με ονομασία files κι εκεί περιέχονται τα δεδομένα που μας ενδιαφέρουν. Σε γενικές γραμμές τα δύο βασικά αρχεία είναι τα highscores.lua και settings.lua. Επιπλέον, τα Angry Birds Space και Angry Birds Star Wars έχουν άλλα τρία αρχεία: eaglepurchases.lua, episodepurchases.lua και gamepurchases.lua. Αυτά είναι τα αρχεία που θα πρέπει να μεταφέρουμε από τη μια συσκευή στην άλλη, προκειμένου να διατηρήσουμε τα highscores μας.

In there, there is a subdirectory called files that stores the necessary files we need. In general terms, two are the files that we have to manpulate and these are highscores.lua and settings.lua. Additionally, Angry Birds Space and Angry Birds Star Wars include three other files, also: eaglepurchases.lua, episodepurchases.lua and gamepurchases.lua. These are the files we must copy from the source device to the other, in order to transfer our highscores to the latter.

Μεταφορά αρχείων με το adb
Files transfer using adb

Αρχικά συνδέουμε τη συσκευή η οποία περιέχει τα scores που θέλουμε να μεταφέρουμε. Είναι η συσκευή που έχουμε περάσει ατελείωτες ώρες, παίζοντας, βρίζοντας κ.λ.π. μέχρι να γεμίσουμε τα πάντα με τρία αστεράκια :)

First we connect the source device that contains the scores we want to transfer from, to our computer. Its the device that we've spent infinite ours of playing, cursing etc, until we reach our goal to have three stars in every level :)

Όταν τη συνδέσουμε εκτελούμε τις ακόλουθες εντολές:

In a terminal execute the following commands:

eliaschr@orion:~> mkdir AngryBirdsBackup
eliaschr@orion:~> mkdir AngryBirdsBackup/ab/
eliaschr@orion:~> mkdir AngryBirdsBackup/abs/
eliaschr@orion:~> mkdir AngryBirdsBackup/abr/
eliaschr@orion:~> mkdir AngryBirdsBackup/absp/
eliaschr@orion:~> mkdir AngryBirdsBackup/absw/

Με αυτές δημιουργήσαμε ένα directory για κάθε παιχνίδι, που θα κρατήσει τα ευαίσθητα δεδομένα μας :). Ήρθε η ώρα να μεταφέρουμε τα αρχεία από τη συσκευή στον υπολογιστή μας:

These commands create one directory for each game; that will hold our sensitive data :). Time to copy the files from the source device to our computer:

eliaschr@orion:~> cd AngryBirdsBackup/
eliaschr@orion:~/AngryBirdsBackup> #
eliaschr@orion:~/AngryBirdsBackup> # Get Angry Birds files
eliaschr@orion:~/AngryBirdsBackup> adb pull /data/data/com.rovio.angrybirds/files/highscores.lua ab/
eliaschr@orion:~/AngryBirdsBackup> adb pull /data/data/com.rovio.angrybirds/files/settings.lua ab/
eliaschr@orion:~/AngryBirdsBackup> #
eliaschr@orion:~/AngryBirdsBackup> # Get Angry Birds Season files
eliaschr@orion:~/AngryBirdsBackup> adb pull /data/data/com.rovio.angrybirdsseasons/files/highscores.lua abs/
eliaschr@orion:~/AngryBirdsBackup> adb pull /data/data/com.rovio.angrybirdsseasons/files/settings.lua abs/
eliaschr@orion:~/AngryBirdsBackup> #
eliaschr@orion:~/AngryBirdsBackup> # Get Angry Birds Rio files
eliaschr@orion:~/AngryBirdsBackup> adb pull /data/data/com.rovio.angrybirdsrio/files/highscores.lua abr/
eliaschr@orion:~/AngryBirdsBackup> adb pull /data/data/com.rovio.angrybirdsrio/files/settings.lua abr/
eliaschr@orion:~/AngryBirdsBackup> #
eliaschr@orion:~/AngryBirdsBackup> # Get Angry Birds Space files
eliaschr@orion:~/AngryBirdsBackup> adb pull /data/data/com.rovio.angrybirdsspace.ads/files/highscores.lua absp/
eliaschr@orion:~/AngryBirdsBackup> adb pull /data/data/com.rovio.angrybirdsspace.ads/files/settings.lua absp/
eliaschr@orion:~/AngryBirdsBackup> adb pull /data/data/com.rovio.angrybirdsspace.ads/files/episodepurchases.lua absp/
eliaschr@orion:~/AngryBirdsBackup> adb pull /data/data/com.rovio.angrybirdsspace.ads/files/gamepurchases.lua absp/
eliaschr@orion:~/AngryBirdsBackup> adb pull /data/data/com.rovio.angrybirdsspace.ads/files/eaglepurchases.lua absp/
eliaschr@orion:~/AngryBirdsBackup> #
eliaschr@orion:~/AngryBirdsBackup> # Get Angry Birds Star Wars files
eliaschr@orion:~/AngryBirdsBackup> adb pull /data/data/com.rovio.angrybirdsstarwars.ads.iap/files/highscores.lua absw/
eliaschr@orion:~/AngryBirdsBackup> adb pull /data/data/com.rovio.angrybirdsstarwars.ads.iap/files/settings.lua absw/
eliaschr@orion:~/AngryBirdsBackup> adb pull /data/data/com.rovio.angrybirdsstarwars.ads.iap/files/episodepurchases.lua absw/
eliaschr@orion:~/AngryBirdsBackup> adb pull /data/data/com.rovio.angrybirdsstarwars.ads.iap/files/gamepurchases.lua absw/
eliaschr@orion:~/AngryBirdsBackup> adb pull /data/data/com.rovio.angrybirdsstarwars.ads.iap/files/eaglepurchases.lua absw/

Αυτά θα αντιγράψουν τα απαραίτητα αρχεία στον υπολογιστή μας. Υπενθυμίζουμε ότι δεν χρειάζεται να είμαστε root για να γίνουν οι αντιγραφές.

Now the necessary files are in our computer's storage. Remember that we don't need to be root user to make the copies.

Αποσυνδέουμε τη συσκευή μας και συνδέουμε το MK809. Αρχικά θα πρέπει να εγκαταστησουμε τα παιχνίδια Angry Birds που μας ενδιαφέρουν. Είναι απαραίτητη προϋπόθεση να παίξουμε τουλάχιστον μια πίστα σε κάθε ένα, για να δημιουργηθεί η δομή των φακέλων όπως ακριβώς χρειάζεται. Αν δεν γίνει αυτό δε θα μπορέσουμε να αντιγράψουμε τα αρχεία με τα scores μας!.

We disconnect the source device and connect MK809. But before we do that we have to install the Angry Birds games in MK809 and must have played at least one level in each one. The games will create the necessary file structure in the device. Fail to do that, we will not be able to copy the score files.!.

Ενεργοποιούμε το Connect to PC (προϋπόθεση φυσικά είναι να έχουμε κάνει και τα υπόλοιπα βήματα για να μπορέσουμε να λειτουργήσουμε το MK809 από το adb). Αφού ο υπολογιστής μας το δει εκτελούμε τις αντίθετες αντιγραφές για να μεταφέρουμε τα αρχεία που βρίσκονται στον υπολογιστή μας μέσα στο MK809:

Enable Connect to PC (keep in mind that all the previous steps to make MK809 be recognised by adb must be completed). After our computer sees the device we can make the same copies of the files, but in reverse direction; from PC to MK809:

eliaschr@orion:~/AngryBirdsBackup> #
eliaschr@orion:~/AngryBirdsBackup> # Save Angry Birds files
eliaschr@orion:~/AngryBirdsBackup> adb push ab/highscores.lua /data/data/com.rovio.angrybirds/files/
eliaschr@orion:~/AngryBirdsBackup> adb push ab/settings.lua /data/data/com.rovio.angrybirds/files/
eliaschr@orion:~/AngryBirdsBackup> #
eliaschr@orion:~/AngryBirdsBackup> # Save Angry Birds Season files
eliaschr@orion:~/AngryBirdsBackup> adb push abs/highscores.lua /data/data/com.rovio.angrybirdsseasons/files/
eliaschr@orion:~/AngryBirdsBackup> adb push abs/settings.lua /data/data/com.rovio.angrybirdsseasons/files/
eliaschr@orion:~/AngryBirdsBackup> #
eliaschr@orion:~/AngryBirdsBackup> # Save Angry Birds Rio files
eliaschr@orion:~/AngryBirdsBackup> adb push abr/highscores.lua /data/data/com.rovio.angrybirdsrio/files/
eliaschr@orion:~/AngryBirdsBackup> adb push abr/settings.lua /data/data/com.rovio.angrybirdsrio/files/
eliaschr@orion:~/AngryBirdsBackup> #
eliaschr@orion:~/AngryBirdsBackup> # Save Angry Birds Space files
eliaschr@orion:~/AngryBirdsBackup> adb push absp/highscores.lua /data/data/com.rovio.angrybirdsspace.ads/files/
eliaschr@orion:~/AngryBirdsBackup> adb push absp/settings.lua /data/data/com.rovio.angrybirdsspace.ads/files/
eliaschr@orion:~/AngryBirdsBackup> adb push absp/episodepurchases.lua /data/data/com.rovio.angrybirdsspace.ads/files/
eliaschr@orion:~/AngryBirdsBackup> adb push absp/gamepurchases.lua /data/data/com.rovio.angrybirdsspace.ads/files/
eliaschr@orion:~/AngryBirdsBackup> adb push absp/eaglepurchases.lua /data/data/com.rovio.angrybirdsspace.ads/files/
eliaschr@orion:~/AngryBirdsBackup> #
eliaschr@orion:~/AngryBirdsBackup> # Save Angry Birds Star Wars files
eliaschr@orion:~/AngryBirdsBackup> adb push absw/highscores.lua /data/data/com.rovio.angrybirdsstarwars.ads.iap/files/
eliaschr@orion:~/AngryBirdsBackup> adb push absw/settings.lua /data/data/com.rovio.angrybirdsstarwars.ads.iap/files/
eliaschr@orion:~/AngryBirdsBackup> adb push absw/episodepurchases.lua /data/data/com.rovio.angrybirdsstarwars.ads.iap/files/
eliaschr@orion:~/AngryBirdsBackup> adb push absw/gamepurchases.lua /data/data/com.rovio.angrybirdsstarwars.ads.iap/files/
eliaschr@orion:~/AngryBirdsBackup> adb push absw/eaglepurchases.lua /data/data/com.rovio.angrybirdsstarwars.ads.iap/files/

Μετά από αυτές τις εντολές, μπορείτε πλέον να κλείσετε το Connect to PC από το MK809 και να το αποσυνδέσετε. Τρέξτε τα αγαπημένα σας παιχνίδια και απολαύστε όλα τα αστέρια που είχατε κερδίσει από πριν, σε ατελείωτες ώρες παιχνιδιού και κατάρων :)

Now, you can disable Connect to PC from MK809 and disconnect it. Execute your favourite games and enjoy them, having the stars and scores you previously gained so hard, through curses and infinite hours of play, on a different device :)

Χρυσοχέρης Ηλίας

Elias Chrysocheris

Πέμπτη 27 Σεπτεμβρίου 2012

Ελληνικός Οδηγός Εγκατάστασης openSUSE 12.2



Στις 5 Σεπτεμβρίου 2012 βγήκε και η καινούργια έκδοση του λειτουργικού openSUSE. Στην έκδοση openSUSE 12.2 θα βρείτε όλο το τελευταίο software που έχει βγει στα γραφικά περιβάλλοντα KDE4, GNOME3, XFCE και LXDE. Φυσικά υπάρχουν και άλλα μικρότερα και ελαφρύτερα γραφικά περιβάλλοντα. Όλα όπως πάντα, σε αρμονία και την κλασική ομορφιά που μας προσφέρει το openSUSE όλα αυτά τα χρόνια της ύπαρξής του.


Η εγκατάσταση γίνεται με τον κλασικό τρόπο του YaST2 χωρίς προβλήματα και αποτελείται από ένα DVD και δύο CD με addons:


  • DVD Εγκατάστασης: Περιέχει όλο το βασικό software ανοικτού λογισμικού μαζί
    και τις απαραίτητες μεταφράσεις του συστήματος εγκατάστασης YaST2.
  • Languages Add-On CD: Περιέχει όλες τις μεταφράσεις για όλα τα προγράμματα
    του εγκαταστημένου συστήματος
  • Non-OSS Add-On: Περιέχει προγράμματα κλειστού λογισμικού που συνήθως
    χρησιμοποιούμε, όπως Flash Player, Opera Browser κ.λ.π.


Η διάθεση του openSUSE 12.2 γίνεται και σαν Live CD είτε με KDE4 είτε με GNOME3, αλλά και σαν Network Installation όπου κατεβάζετε ένα CD με πολύ βασικό σύστημα εγκατάστασης και όλο το software που εγκαθιστάτε κατεβαίνει εκείνη τη στιγμή από το διαδίκτυο. Αυτό, κατά συνέπεια, σημαίνει πως η εγκατάσταση διαρκεί περισσότερη ώρα, μιας και όλα τα πακέτα κατεβαίνουν μέσω διαδικτύου, από την άλλη δε χρειάζεται κάποιος να κατεβάσει πρώτα τα δύο CD και το DVD εγκατάστασης. Φυσικά θα πρέπει να επιλέξετε αν θέλετε την 32bit έκδοση του λειτουργικού, ή την 64 bit.


Για κάποιον που έχει κάνει κάποιες φορές εγκατάσταση στο λειτουργικό, η εγκατάσταση είναι παιχνιδάκι. Για κάποιον ο οποίος είναι καινούργιος στο χώρο του Linux και χρειάζεται λίγη βοήθεια, όπως και με κάθε καινούργια έκδοση, δημιούργησα και τον καινούργιο Οδηγό Εγκατάστασης του openSUSE 12.2 στα Ελληνικά. Ο οδηγός είναι ένα project που έχει αναλάβει ο Σύλλογος Φίλων Ανοικτού Λογισμικού Χανίων και έτσι φιλοξενείται στο wiki του.



Ελπίζω ο οδηγός να φανεί ένα χρήσιμο εργαλείο. Αν παρατηρήσετε κάτι που, αλλάζοντάς το, ο οδηγός γίνεται καλύτερος και πιο καταννοητός, παρακαλώ ενημερώστε με. Κάθε σχόλιο είναι αποδεκτό.


Χρυσοχέρης Ηλίας