Buscar este blog

domingo, 12 de febrero de 2017

Centos 6 - Configure SonarQube with PostgreSQL

Just for my reminder.
How to configure SonarQube 5.X with PostgreSQL 8.X in Centos 6.6

Install postgresql.
yum install postgresql-server

service postgresql initdb

chkconfig postgresql on
service postgresql start

Configure access.
Edit /var/lib/pgsql/data/pg_hba.conf file and set the following config:
local all all trust
host all 127.0.0.1/32 trust

Create sonar user and database (you have to restart the service before).
psql -U postgres
postgres=# create user sonar with password 'sonar';
postgres=# create database sonar with owner sonar encoding 'UTF8';

Configure sonar.
Edit /usr/local/sonarqube/conf/sonar.properties file:
(...)

# User credentials.
# Permissions to create tables, indices and triggers must be granted to JDBC user.
# The schema must be created first.
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar

#----- Embedded Database (default)
# H2 embedded database server listening port, defaults to 9092
#sonar.embeddedDatabase.port=9092

(...)

#----- PostgreSQL 8.x/9.x
# If you don't use the schema named "public", please refer to http://jira.sonarsource.com/browse/SONAR-5000
sonar.jdbc.url=jdbc:postgresql://localhost/sonar

(...)

Done.

Apache httpd - ap_proxy_connect_backend disabling worker for (XXXX)

Problem

I have a web service which is published (by Camel y JBoss Fuse) in http://fuse-01:8888/conversor.
The service clients, instead of accessing the service directly, they will use an Apache httpd server as proxy.

I configure the proxy in this way, in /etc/httpd/conf.d:
<VirtualHost *:80>
    ServerName fuse-01   
    DocumentRoot /var/www/fuse-01

    <Directory /var/www/fuse-01>
        Options FollowSymLinks
        AllowOverride None
        Order deny,allow
        Allow from all
    </Directory>    


    # Configuración conversor PDF
    ProxyRequests     Off
    ProxyPreserveHost On

    <Location /conversor> 
 ProxyPass http://localhost:8888/conversor
 ProxyPassReverse http://localhost:8888/conversor
    </Location>


    ErrorLog logs/fuse-01-error_log
    CustomLog logs/fuse-01-access_log common
</VirtualHost>

But when I try http://fuse-01/conversor?wsdl I get the following error in the browser:
Error 503
Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
By checking Apache logs files I see this in fuse-01-error_log:
[Sun Feb 12 11:28:59 2017] [error] (13)Permission denied: proxy: HTTP: attempt to connect to 192.168.56.103:8888 (fuse-01) failed
[Sun Feb 12 11:28:59 2017] [error] ap_proxy_connect_backend disabling worker for (fuse-01)

Solution

Execute the following command:
/usr/sbin/setsebool -P httpd_can_network_connect true

SELinux (Security-Enhanced Linux) is a security module for supporting access control security policies.
There are lots of boolean variables which control multiple security aspects of the system, and you can check then all by using:
getsebool -a

Statted from Redhat official doc:

httpd_can_network_connectWhen disabled, this Boolean prevents HTTP scripts and modules from initiating a connection to a network or remote port. Enable this Boolean to allow this access.

sábado, 11 de febrero de 2017

CentOS 6 - Install LibreOffice - Offline installation

In the previous post CentOS 6 - Install LibreOffice as a service I installed libre office by using yum repositories. But if your client machine does not have access to the yum repository wich contains these packages, you have a problem.

In my local installation, I used my CentOS-Base.repo yum repo (check appendix I). This is the repo in /etc/yum.repos.d/CentOS-Base.repo file:
(...)
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
(...)

This mirror is resolved as http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os&infra=stock (check appendix II)

So, you can add this repo to the client machine or you can prepare a "bundle" which contains all packages needed to your installation. I tried this second one.

In my local machine I used yum downloadonly plugin in order to download the libreoffice packages and all their dependencies, and save them in a directory.
yum install yum-plugin-downloadonly

yum install --downloadonly --downloaddir=/tmp/libreoffice libreoffice-headless
yum install --downloadonly --downloaddir=/tmp/libreoffice libreoffice-writer

cd /tmp
tar -zcvf libreoffice-4.3.7.gz libreoffice

Once you have all the RPM files, you only need to put them in the client machine and make a local install.
tar -xvf libreoffice-4.3.7.gz
cd libreoffice

yum localinstall *.rpm

Appendix I - How to know which repo a package came from

I you have a package installed and you want to know where it came from, you can use repoquery. This is a utility of yum-utils:
yum install yum-utils

repoquery -i libreoffice-writer

Appendix II - How to resolve yum properties

Yum properties like "releasever", "basearch" and "infra" can be resolved by using a python script:
/usr/bin/python -c 'import yum;yb=yum.YumBase();yb.doConfigSetup(init_plugins=False);print yb.conf.yumvar["rleaseserver"]'
/usr/bin/python -c 'import yum;yb=yum.YumBase();yb.doConfigSetup(init_plugins=False);print yb.conf.yumvar["basearch "]'
/usr/bin/python -c 'import yum;yb=yum.YumBase();yb.doConfigSetup(init_plugins=False);print yb.conf.yumvar["infra"]'

Apendix III - Why I did not install the latest version of libreoffice

My Unix skills are quite meager. I tried to download and install the latest stable libreoffice RPMs by downloading them from the official site: https://es.libreoffice.org/descarga/libreoffice-estable/?type=rpm-x86_64&version=5.2 , but after the installation I got a lot of errors like:
/opt/libreoffice5.1/program/oosplash: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

Each time I installed the missing library, another one missing library appeared. I think this is due to the fact that I was using a CentOS server installation, without Gnome or KDE...

sábado, 4 de febrero de 2017

CentOS 6 - Install LibreOffice as a service

The purpose of this post is to show how to install LibreOffice in CentOS 6, without GUI. My requirements were to use LibreOffice as a PDF converter.

Install LibreOffice by using yum:
yum install libreoffice-headless

yum install libreoffice-writer

libreoffice --version

The install directory will be /usr/lib64/libreoffice

In order to make a test, you can try convert a file:
echo 'hola' > prueba.txt

libreoffice --headless --convert-to pdf prueba.txt

If you want to install it as a service, just create the following file and save it in /etc/init.d (I copied this file from here):
#!/bin/sh
#
# ooffice       openoffice conversion service
#
#
# chkconfig: 345 50 25
# description: Startup script for the Open Office conversion process
# pidfile: /var/run/ooffice.pid

# Source function library.
. /etc/rc.d/init.d/functions

proc="/usr/lib64/libreoffice/program/soffice.bin"
options="--headless --accept=\"socket,host=0,port=8100,tcpNoDelay=1;urp\" --nodefault --nofirststartwizard --nolockcheck --nologo --norestore --invisible &"
if [ ! -f $proc ]; then
        proc="/usr/lib64/openoffice.org3/program/soffice.bin"
        options="--headless --accept=\"socket,host=0,port=8100,tcpNoDelay=1;urp\" --nodefault --nofirststartwizard --nolockcheck --nologo --norestore --invisible &"
fi


prog=ooffice
PID_FILE=/var/run/ooffice.pid

LOG=/var/log/ooffice
if [ ! -f $LOG ]; then
        touch $LOG
        chmod 644 $LOG
fi


start() {
        echo -n $"Starting $prog: "
        umask 000
        daemon $prog $options
        RETVAL=$?
        echo
        sleep 1
        pidofproc $proc > $PID_FILE
        echo "`date +\"%Y-%m-%d %T\"`  Starting ooffice." >> $LOG
        return $RETVAL
}

stop() {
        echo -n $"Stopping $prog: "
        killproc -p $PID_FILE $prog
        RETVAL=$?
        echo
        echo "`date +\"%Y-%m-%d %T\"`  Stopping ooffice." >> $LOG
        return $RETVAL
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                stop
                sleep 1
                start
                ;;
        status)
                status -p $PID_FILE $prog
                ;;
        *)
                echo $"Usage: $prog {start | stop | restart | status}"
                exit 1
esac

exit $RETVAL

Finally configure this script as an executable and set the service as autostart:
chmod +x /etc/init.d/soffice
chkconfig --add soffice
chkconfig soffice on
service soffice start

domingo, 8 de enero de 2017

Chrome DevTools persist changes on page reload

Chrome DevTools allow you, amongst much other things, to edit HTML and JS files and save them in a workspace.
When debugging, you can add a local folder as a workspace. Then you can map any JS file served by the server to a local file in this workspace. Any change you made in this file, by using chrome editor, is automatically saved in the workspace.
You can check the full explanation here.

There is a problem though, each time you reload the page, the browser request again de JS file and your changes are "lost". Indeed, the changes still are saved in the workspace, but you see again the file loaded from the server.


There is a solution for this. Just set the workspace as the server resources folder. In this way, you edit the same file the browser is loading.
But what happens when you does not have direct access to the server resources folder?


My solution is to combine chrome DevTools with Fiddler Autoresponder.

Fiddler is a proxy tool that captures all http traffic and allows you to inspect and change it. With the autoresponder option you can return a local response when the browser request some URL, based on a set of rules. In this way you can build your own responses or modify some previous ones, instead to request them to the server.
The problem is that the fiddler response file is not editable by chrome. The fiddler file has two parts: headers and body, being the body the JS file. So, you need two files, the fiddler response and the JS body.


You edit the JS file by using chrome editor, then copy the body to the fiddler response file, and when the page is reloaded fiddler will return the modified response.

Instead editing the fiddler response file manually, I created a python script wich inspects the chrome workspace folder looking for JS files. For each of them, the script creates a fiddler file response by appending a set of headers. These headers are also in other common file.

This script read recursively all files in a root folder, keeping only th JS files. For each one create the corresponding fiddler response file by appending a common response headers.

You can check the script here: https://github.com/evazquezma/python/blob/master/fiddlerResponse/generateResponses.py