Friday, May 13, 2016

fedora: Install HipChat 4

Atlassian team wasn't able to release rpm package for the latest hipchat for more than 2 months. Fortunately, it is possible to intsall hipchat from the debian package. Download the latest available debian package from here.

Install alien package which will convert deb package to the rpm package:
sudo dnf install alien
Convert hipchat debian package to rpm package:
sudo alien HipChat4-4.0.1635-Linux.deb -r
Install hipchat:
sudo dnf install hipchat4-4.0.1635-2.x86_64.rpm

fedora: X11 forwarding issue

Here I have a nice post how to open browser window on the remote machine. On fedora 23 that method stopped to work. It was possible to start simple application like xclock, but firefox or chrome.
The problem is in the xorg-x11-drv-intel package. The latest version which is available in the official fedora repo is xorg-x11-drv-intel-2.99.917-19.20151206.fc23 (as for 13 May 2016). Downgrading the package to the previous version fixes the issue.
The latest version of the package which is known to work is xorg-x11-drv-intel-2.99.917-19.20151206.fc23. Let's install it:
sudo dnf install xorg-x11-drv-intel-2.99.917-16.20150729.fc23.x86_64
It would be also nice to lock the package version, so the next time you start updating the system it won't be updated:
sudo dnf install 'dnf-command(versionlock)'
sudo dnf versionlock add xorg-x11-drv-intel

Monday, May 2, 2016

How to format USB stick as FAT32

First step is to find the name of the USB stick in the system:
sudo fdisk -l
In my case the name of the device is /dev/sdc If the USB stick is mounted, unmount it with command:
sudo unmount /dev/sdc
Finally, run the command to format USB stick:
mkdosfs -F 32 -I /dev/sdc

Monday, April 18, 2016

apt-get: Install package with specific version and hold it on the next upgrade

If you need to install specific version of the package in your system, you can list all available package versions with the command:
apt-cache madison varnish
After you know the package version you can install it with:
sudo apt-get install varnish=4.0.2-1
To hold the package on the selected version during the next upgrade:
sudo apt-mark hold varnish
You can also "unhold it" with:
sudo apt-mark unhold varnish

Sunday, March 13, 2016

fedora: Install accidentally removed sqlite package

If sqlite package (or, for example, sqlite-libs package) was accidentally removed from your system, you can't reinstall it using dnf or yum because they depend on it. To fix this problem, download missing rpm package from https://admin.fedoraproject.org/pkgdb/package/rpms/sqlite/. From the downloaded file location, run command:
rpm2cpio sqlite-libs-3.11.0-3.fc23.x86_64.rpm | cpio -idmv
It will create usr folder with extracted files. Run next command to copy them to the right location:
sudo cp -R usr/ /
Pay attention to the package architecture. You should be able to use dnf again. It would be good to reinstall missed package with dnf again:
sudo dnf --best --allowerasing install sqlite-libs

Thursday, February 18, 2016

Set up logging with Flask and gunicorn

Let's say that we want to be able to log in the specified log file and syslog. Our application - is a simple app.py file. The first step, I suggest, is to set logger name:
import os

from flask import Flask


app = Flask(__name__)
app.logger_name = "flask.app"

# ...

if __name__ == "__main__":
    app.run()
You can log in your project like this:
app.logger.info("Hello")
A log configuration file for the gunicorn may look something like this:
[loggers]
keys=root, gunicorn.error, gunicorn.access, requests.packages.urllib3.connectionpool, __main__

[handlers]
keys=log_file, syslog

[formatters]
keys=generic

[logger_root]
level=INFO
handlers=log_file, syslog

[logger___main__]
level=DEBUG
handlers=log_file, syslog
propagate=0
qualname=__main__

[logger_gunicorn.error]
level=INFO
handlers=log_file, syslog
propagate=0
qualname=gunicorn.error

[logger_gunicorn.access]
level=INFO
handlers=log_file, syslog
propagate=0
qualname=gunicorn.access

[logger_requests.packages.urllib3.connectionpool]
level=WARN
handlers=log_file, syslog
propagate=0
qualname=requests.packages.urllib3.connectionpool

[handler_syslog]
class=logging.handlers.SysLogHandler
formatter=generic
args=()

[handler_log_file]
class=logging.FileHandler
formatter=generic
args=('/home/myuser/log/gunicorn.log',)

[formatter_generic]
format=%(asctime)s [%(process)d:%(name)s:%(lineno)s] [%(levelname)s] %(message)s
datefmt=%Y-%m-%d %H:%M:%S
class=logging.Formatter
The last step is starting gunicorn:
gunicorn app:app --log-config /home/myuser/gunicorn_logging.conf

Conditions in the Vagrantfile

Every developer could have different hardware configuration. Let's say one is ready to provision a virtual machine with 4 cpus and another - only with 2 cpus. It would be nice to handle this situation with environmental variables:
Vagrant.configure(2) do |config|
  config.vm.box = "box-cutter/debian81"

  config.vm.network "private_network", ip: "192.168.33.10"
  config.ssh.forward_agent = true

  config.vm.provider "virtualbox" do |vb|
    vb.memory = "4096"
    if ENV.has_key?('VAGRANT_CPUS')
      vb.cpus = ENV['VAGRANT_CPUS']
    else
      vb.cpus = "2"
    end
  end
end
With that config the number of the provisioned cpus can be controled via VAGRANT_CPUS environmental variable.