Certbot

Certbot is a tool that comes with letsencrypt to automatize renewal of certificates.

– install it with your linux distribution
– to install a certificate run
sudo certbot --nginx -d example.com -d www.example.com

  • install it with your linux distribution
  • to install a certificate run

sudo certbot --nginx -d example.com -d www.example.com

  • For debian and nginx, you’ll have to run the following command :

sudo certbot --authenticator standalone --installer nginx -d <domain> --pre-hook "systemctl stop nginx" --post-hook "systemctl start nginx"

CamiTK, VTK etc

Un petit article pour installer CamiTK.

ça commence par compiler la bonne version de VTK, apparemment, c’est la 7.1.1 avec la bonne version de Qt.

On peut utiliser Homebrew pour obtenir Qt 5 :

brew install qt5

puis configurer la compilation de VTK avec le bon Qt5_DIR :

cmake .. -DBUILD_TESTING=false -DVTK_Group_Qt=off -DModule_vtkGUISupportQt=on -DModule_vtkGUISupportQtOpenGL=on -DVTK_QT_VERSION=5 -DQt5_DIR="/usr/local/opt/qt/lib/cmake/Qt5/" -DCMAKE_BUILD_TYPE=Release

make; make install

puis configurer CamiTK :

cmake .. -DBUILD_TESTING=false -DVTK_Group_Qt=true -DVTK_QT_VERSION=5 -DQt5_DIR="/usr/local/opt/qt5/lib/cmake/Qt5" -DCMAKE_BUILD_TYPE=Release -DVTK_DIR="/usr/local/lib/cmake/vtk-7.1/"

make; make install

OpenProject

 

Bel outils de gestion de projet en ruby avec du node !

à partir de cette page.

Créer l’utilisateur openproject :

sudo groupadd openproject
sudo useradd --create-home --gid openproject openproject
sudo passwd openproject #(enter desired password)
chsh -s /bin/bash openproject
usermod -G sudo -a openproject

Installer les composants nécessaires :

sudo apt-get update -y
sudo apt-get install -y zlib1g-dev build-essential                  \
                    libssl-dev libreadline-dev                      \
                    libyaml-dev libgdbm-dev                         \
                    libncurses5-dev automake                        \
                    imagemagick libmagickcore-dev libmagickwand-dev \
                    libtool bison libffi-dev git curl               \
                    libxml2 libxml2-dev libxslt1-dev                \
                    libssl1.0-dev mysql-server memcached            \
                    default-libmysqlclient-dev mysql-server

Créer la base de données pour openproject

mysql -uroot -p
mysql> CREATE DATABASE openproject CHARACTER SET utf8;
mysql> CREATE USER 'openproject'@'localhost' IDENTIFIED BY 'my_password';
mysql> GRANT ALL PRIVILEGES ON openproject.* TO 'openproject'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> QUIT

Récupérer ruby et node pour le compte openproject.

su openproject --login
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.profile
echo 'eval "$(rbenv init -)"' >> ~/.profile
source ~/.profile
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

rbenv install 2.4.1
rbenv rehash
rbenv global 2.4.1

git clone https://github.com/OiNutter/nodenv.git ~/.nodenv
echo 'export PATH="$HOME/.nodenv/bin:$PATH"' >> ~/.profile
echo 'eval "$(nodenv init -)"' >> ~/.profile
source ~/.profile
git clone git://github.com/OiNutter/node-build.git ~/.nodenv/plugins/node-build

nodenv install 6.11.3
nodenv rehash
nodenv global 6.11.3

Récupérer OpenProject

cd ~
git clone https://github.com/opf/openproject-ce.git --branch stable/7 --depth 1
cd openproject-ce
gem install bundler
bundle install --deployment --without postgres sqlite development test therubyracer docker

npm install

# for raspberry pi or other if phantomjs does not install
git clone https://github.com/piksel/phantomjs-raspberrypi.git
chmod +x phantomjs-raspberrypi/bin/phantomjs
cp phantomjs-raspberrypi/bin/phantomjs /home/openproject/.nodenv/shims/
npm install phantomjs
npm install
# for raspberry pi

Copier

cp config/database.yml.example config/database.yml

puis renseigner les informations pour la connexion à la base de donnée dans le ficher /home/openproject/openproject-ce/config/database.yml

production:
  adapter: mysql2
  database: openproject
  host: localhost
  username: openproject
  password: my_password
  encoding: utf8

development:
  adapter: mysql2
  database: openproject
  host: localhost
  username: openproject
  password: my_password
  encoding: utf8

Copier

cp config/configuration.yml.example config/configuration.yml

puis renseigner les informations pour la configuration dans le fichier /home/openproject/openproject-ce/config/configuration.yml:

cp config/configuration.yml.example config/configuration.yml
production:                          #main level
  email_delivery_method: :smtp       #settings for the production environment
  smtp_address: smtp.gmail.com
  smtp_port: 587
  smtp_domain: smtp.gmail.com
  smtp_user_name: ***@gmail.com
  smtp_password: ****
  smtp_enable_starttls_auto: true
  smtp_authentication: plain
[...]
rails_cache_store: :memcache

Lancer le site en production

cd ~/openproject-ce
RAILS_ENV="production" ./bin/rake db:create
RAILS_ENV="production" ./bin/rake db:migrate
RAILS_ENV="production" ./bin/rake db:seed
RAILS_ENV="production" ./bin/rake assets:precompile

Le tester.

RAILS_ENV="production" npm run webpack-watch &
RAILS_ENV="production" ./bin/rails server

Remplir la clé.

echo "export SECRET_KEY_BASE=$(./bin/rake secret)" >> ~/.profile
source ~/.profile

Faire le lien avec apache2

sudo apt-get install -y apache2 libcurl4-gnutls-dev      \
                               apache2-dev libapr1-dev \
                               libaprutil1-dev
chmod o+x "/home/openproject"

su openproject --login
cd ~/openproject-ce
gem install passenger
passenger-install-apache2-module

Editer le fichier /etc/apache2/mods-available/passenger.load

LoadModule passenger_module /home/openproject/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/passenger-5.1.8/buildout/apache2/mod_passenger.so

Editer le fichier /etc/apache2/mods-available/passenger.conf

<IfModule mod_passenger.c>
     PassengerRoot /home/openproject/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/passenger-5.1.8
  PassengerDefaultRuby /home/openproject/.rbenv/versions/2.3.0/bin/ruby
</IfModule>
[root@openproject] a2enmod passenger

Editer le fichier /etc/apache2/sites-available/openproject.conf

SetEnv EXECJS_RUNTIME Disabled

<VirtualHost *:80>
   ServerName yourdomain.com
   # !!! Be sure to point DocumentRoot to 'public'!
   DocumentRoot /home/openproject/openproject-ce/public
   <Directory /home/openproject/openproject-ce/public>
      # This relaxes Apache security settings.
      AllowOverride all
      # MultiViews must be turned off.
      Options -MultiViews
      # Uncomment this if you're on Apache >= 2.4:
      Require all granted
   </Directory>

   # Request browser to cache assets
   <Location /assets/>
#     ExpiresActive On ExpiresDefault "access plus 1 year"
   </Location>

</VirtualHost>

Désactiver le site par défaut et activer openproject :

[root@host] a2dissite 000-default
[root@host] a2ensite openproject

Installer le cron

su --login openproject
crontab -e

et ajouter la ligne

*/10 * * * * cd /home/openproject/openproject-ce; /home/openproject/.rbenv/versions/2.4.1/bin/rake jobs:workoff

pour qu’il se lance toute les 10 minutes

Et pour l’avoir sur localhost/openproject

  • editer le fichier /etc/apache2/sites-available/openproject.conf:
SetEnv EXECJS_RUNTIME Disabled

<VirtualHost *:80>
   ServerName yourdomain.com
   # !!! Be sure to point DocumentRoot to 'public'!
   <Directory /home/openproject/openproject-ce/public>
      # This relaxes Apache security settings.
      AllowOverride all
      # MultiViews must be turned off.
      Options -MultiViews
      # Uncomment this if you're on Apache >= 2.4:
      Require all granted
   </Directory>

   # Request browser to cache assets
   <Location /assets/>
#     ExpiresActive On ExpiresDefault "access plus 1 year"
   </Location>

# These have been added:
    Alias /openproject /home/openproject/openproject-ce/public
    <Location /openproject>
        PassengerBaseURI /openproject
        PassengerAppRoot /home/openproject/openproject-ce

    </Location>
    <Directory /home/openproject/openproject-ce/public>
        Allow from all
        Options -MultiViews
        # Uncomment this if you're on Apache >= 2.4:
        #Require all granted
    </Directory>


</VirtualHost>
  • editer le fichier /home/openproject/openproject-ce/config/configuration.yml:
[...]
  rails_relative_url_root: "/openproject"
[...]
  • relancer la précompilation des assets avec le nouvel url
    RAILS_ENV="production" ./bin/rake assets:precompile

     

  • relancer le serveur apache
    sudo systemctl reload apache2

    Pour l’installer en tant que service sous windows, utiliser ‘thin’

    gem install thin
    gem install thin_service

Jenkins alternative : Buildbot

from this website : https://www.blazemeter.com/blog/jenkins-vs-other-open-source-continuous-integration-servers

Buildbot is another software development continuous integration tool which is trusted by the Mozilla Foundation for bringing excellence into their products, and is now used at Mozilla, Chromium, WebKit and many other projects.

Buildbot started as a lightweight alternative to Mozilla Tinderbox and currently it’s a fully functional continuous development and build server supporting a lot of integrations, distributed builds, custom (and often unique) build steps, notifications via multiple channels and many more.

Buildbot is a Python-based tool, and as such, it runs everywhere Python runs. You can deploy it onto any POSIX-compliant operating system. Moreover, Buildbot config files are basically Python scripts, meaning that the configuration is version-control friendly and you have all the power of the Python language while defining your build plan. It means extreme and unbeatable flexibility and capabilities.

As for July 2016, Buildbot supports out of the box:

Version Control Systems:
Mercurial
Subversion
Git
CVS
Perforce
Bzr
Repo
Gerrit
Monotone
Darcs
Builders:
Command-line
Configure (autoconf-style projects)
Compile (C projects)
VC++ (Microsoft compilers)
Robocopy
Test (analogue of make test)
TreeSize – check repo size
Perl Module Test
Mysql-test-run
Notifications
Email Notification
IRC Bot
PBListener
HTTP Status Push
Gerrit Status Push
Github Status Push
Stash Status Push

Buildbot installation and configuration is a separate large topic as the instructions may differ depending on each operating system and architecture, so it is better to refer to Buildbot documentation. However if you’re looking for quick and dirty way to get it running and see if it fits your needs, here are minimal instructions:

Install Python. Most Linux and MacOSX distributions come with Python, on Windows you’ll have to install it manually. Make sure you have at least the 2.7.X version.

Make sure you have the following binaries in your PATH (on Windows they should be located under the “Scripts” folder of your Python installation):

Python itself
pip – a Python package management system
Easy install – a script which simplifies installation of Python packages
Run the following commands:
pip install buildbot – installs the Buildbot master (or server)
buildbot create-master /path/to/buildbot/working/folder – sets up some of the initial configuration for the buildbot server

pip install buildbot-worker – installs the Buildbot worker
buildbot-worker create-worker worker localhost:9989 example-worker pass – creates the Buildbot agent with default parameters

Start the Buildbot server: buildbot start /path/to/buildbot/working/folder .
Start the Buildbot slave: buildbot-worker start worker .
Open the following url in your browser: http://localhost:8010 (unless you changed it to something different in the master.cfg file).
If you plan to run a JMeter test, add a Builder such as:

factory.addStep(steps.ShellCommand(command=[« c:/jmeter/bin/jmeter.bat -n -t c:/buildbot/Test.jmx -l C:/buildbot/test.jtl »]))

to your master.cfg file.

Here is the Buildbot dashboard with one build currently running along with the history of several previous test executions:

Increase image

Symfony and Co mposer

A little reminder for the current development.

With this test project : https://github.com/brunomartin/symfony-test

For using SQLite, need to modify conifig/config.yml :

doctrine:
dbal:
pdo_mysql -> pdo_sqlite
path: %kernel.cache_dir%/test.db

>symfony new comptes
>cd comptes/
>php bin/console server:run # to test
>php bin/console generate:controller # to create a controller
>php bin/console doctrine:generate:entity # to create entity
>php bin/console doctrine:database:create
>php bin/console doctrine:schema:update --force
>php bin/console doctrine:schema:validate

Si il y a eu mise à jour des entités :
php bin/console doctrine:generate:entities AppBundle
générera tous les getter et setter pour les champs.

Pour créer des entités à partir de la ligne de commande
bin/console doctrine:generate:entity -n --entity AppBundle:User --fields="name:string(100) age:int sexe:string(1)"

Pour créer des controller à partir de la ligne de commande
bin/console generate:controller -n --controller=AppBundle:User --actions="addUserAction:/add_user:AppBundle:User:add_user.html.twig"

Pour définir des relations entre entités:

class Operation
{
...
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="operations")
**/
private $user;
...
}

class User
{

/**
* @ORM\OneToMany(targetEntity= »Operation », mappedBy= »user »)
* @var Operation[] An ArrayCollection of Operation objects.
**/
private $operations = null;

}

Pour générer un form
php bin/console doctrine:generate:form AppBundle:User
Puis dans un action d’un controller
...
use AppBundle\Entity\User;
use AppBundle\Form\UserType;
use Symfony\Component\HttpFoundation\Request;
...
public function addUserAction(Request $request)
{
$em = $this->getDoctrine()->getManager();

$user = new User();
$user->setName(« Bruno »);

$form = $this->createForm(UserType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$user = $form->getData();
$em->persist($user);
$em->flush();
return $this->redirectToRoute(‘homepage’);
}

return $this->render(‘AppBundle:User:add_user.html.twig’, array(
‘form’ => $form->createView(),
));
}

And in the corresponding twig template :
{{ form_start(form) }}
{{ form_widget(form) }}
<input type="submit" value="Create" class="btn btn-default pull-right" />
{{ form_end(form) }}

Pour l’environnement de production :

php bin/console cache:clear --no-warmup --env=prod
php bin/console doctrine:schema:update --force --env=prod

Pour servir le site avec apache, installer libapach2-mod-php, installer le site dans /usr/share, donner les droits suffisants au user www-data, créer une configuration dans site-avaible symfony.conf

<VirtualHost *:80>
    ServerName home.brunocsmartin.fr
    ServerAlias www.home.brunocsmartin.fr

    DocumentRoot /usr/share/symfony/web
    <Directory /usr/share/symfony/web>
        AllowOverride All
        Order Allow,Deny
  Allow from all

        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ app.php [QSA,L]
        </IfModule>
    </Directory>

    Alias /symfony /usr/share/symfony/web/

    <Directory /usr/share/symfony/web/bundles>
        <IfModule mod_rewrite.c>
            RewriteEngine Off
        </IfModule>
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/project_error.log
    CustomLog ${APACHE_LOG_DIR}/project_access.log combined    

</VirtualHost>

<IfModule mod_ssl.c>

<VirtualHost *:443>
    ServerName home.brunocsmartin.fr
    ServerAlias www.home.brunocsmartin.fr

    DocumentRoot /usr/share/symfony/web

    Alias /symfony /usr/share/symfony/web/
    <Directory /usr/share/symfony/web>
  Options All
        AllowOverride All
        Order Allow,Deny
  Allow from all

        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ app.php [QSA,L]
        </IfModule>
    </Directory>

    <Directory /usr/share/symfony/bundles>
        <IfModule mod_rewrite.c>
            RewriteEngine Off
        </IfModule>
    </Directory>

    SSLEngine on
    SSLCertificateFile	/etc/letsencrypt/live/home.brunocsmartin.fr/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/home.brunocsmartin.fr/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/home.brunocsmartin.fr/chain.pem

    <FilesMatch "\.(cgi|shtml|phtml|php)$">
        SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory /usr/lib/cgi-bin>
        SSLOptions +StdEnvVars
    </Directory>


</VirtualHost>

</IfModule>

et appliquer les bonnes permissions :

sudo setfacl -R -m u:www-data:rX /usr/share/symfony/
sudo setfacl -R -m u:www-data:rwX /usr/share/symfony/
sudo setfacl -dR -m u:www-data:rwX /usr/share/symfony/

Compile linux kernel with a simple init.c

#!/bin/bash

if [ ! -f linux-3.2.tar.bz2 ]; then
    wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.tar.bz2
fi

if [ ! -d linux-3.2 ]; then
    tar xjf linux-3.2.tar.bz2
fi

cd linux-3.2
make defconfig
make all
cd ..

if [ ! -f init.c ]; then
    cat > init.c << EOF
    #include <stdio.h>
     
    void main() {
      printf("Hello World!\n");
      while(1);
    }
EOF
fi

gcc -static init.c -o init
echo init|cpio -o --format=newc > initramfs
qemu-system-x86_64 -kernel linux-3.2/arch/x86/boot/bzImage -initrd initramfs -serial stdio -append "console=tty1"

About Linux Modules

Create a SD card image :
– get the last Raspbian image ont the website : https://www.raspberrypi.org/downloads/raspbian/
– get the last applePi-Baker : http://www.tweaking4all.com/hardware/raspberry-pi/macosx-apple-pi-baker/
– unzip the image, connect the SD card and launch applePi-Baker

Connect the rpi using usb serial connexion :
– install the PL2303 driver
– install minicom
– connect the usb serial adapter to the rpi and ti the mac, check in dev (/dev/tty.usbserial)
– launch « minicom -s » in a terminal and enter the device address

minicom -s

– login : pi, password : raspberry
– activate root account :

sudo passwd root

– exit and log with root

Expand Filesystem:
– launch raspi-config

raspi-config

– choose « 1 Expand Filesystem »
– reboot

Get the module development environment :

apt-get install rpi-update
rpi-update

– get the kernel version :

uname -r

– download corresponding package at https://www.niksula.hut.fi/~mhiienka/Rpi/linux-headers-rpi/
– install with dpkg :

dpkg -i linux-headers...

Try module compilation :
– create hello.c file containing :


/*
* hello.c - The simplest kernel module.
*/
#include "linux/module.h" // included for all kernel modules
#include "linux/kernel.h" // included for KERN_INFO
#include "linux/init." // included for __init and __exit macros

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Martin");
MODULE_DESCRIPTION("A Simple Hello World module");

static int __init hello_init(void)
{
    printk(KERN_INFO "Hello world!\n");
    return 0; // Non-zero return means that the module couldn't be loaded.
}

static void __exit hello_cleanup(void)
{
    printk(KERN_INFO "Cleaning up module.\n");
}

module_init(hello_init);
module_exit(hello_cleanup);

– create Makefile file containing :

obj-m += hello.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

all:
    make -C $(KDIR) M=$(PWD) modules

clean:
    make -C $(KDIR) M=$(PWD) clean

– try to load and unload the module :

insmod hello.ko
rmmod hello.ko

– check the results through the kernel messages :
>dmesg | tail -20

– it should be written something like :

[ 2831.586831] Hello world.
[ 2846.286438] Goodbye world.

– And it’s good !

Install the new driver so it will be loaded at start up :
– copy the .ko file to the appropropriate directory : /lib/modules/`uname -r`/kernel/drivers/gpio
– run depmod
>depmod
– and reboot
>shutdown -r now

For the raspberry, the serial connexion is limited and graphical interface is not supplied. So create a ssh server is a good way to use geany for example. As I use a wifi connexion, the ssh server will hang up soon as you are connected so. To get rid of this, add the following lines at the end of /etc/ssh/sshd_config :

KeepAlive yes
ClientAliveInterval 60

Ok ?

Astuces en vrac

Voici des astuces en vrac le temps que je trouve le temps de les ranger

Compilation de Qt avec le strict nécessaire :

c:/Qt/5.5/Src/configure -developer-build -opensource -confirm-license -debug-and-release -make libs -qt-libjpeg -qt-libpng -no-openssl -no-icu -qt-zlib -qt-pcre -no-iconv -nomake examples -nomake tests -no-angle -opengl desktop -no-rtti -no-dbus -strip -plugin-sql-sqlite

Un exemple de CMakeLists.txt pour créer des applications avec Qt et produire les installeurs pour chaque plateforme.