Pages

Saturday, 22 September 2018

Fix Network Device Name for Wireless USB Dongle on Linux

Bought an el-cheapo TP-LINK TL-WN722N for my Desktop Machine. Wanted to ask udev to give the name stick for this device.

  • Plug it in
  • lsusb -> Seeing it's at Bus 001 Device 005: ID 2357:010c TP-Link TL-WN722N v2
  • ip l to display what is the device's name -> wlp0s20f0u3
  • Get udev information on it: udevadm info -a -n /dev/bus/usb/001/005
  • Get the HW address: cat /sys/class/net/wlp0s20f0u3/address
  • Add SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="HWADDR-COMES-HERE", NAME="stick" to /etc/udev/rules.d/10-network.rules
Special thanks for this:
https://wiki.archlinux.org/index.php/Network_configuration#Change_interface_name

Saturday, 2 December 2017

Edit Chrome preferences to get to Ctrl+Tab

I wanted to set Ctrl+Tab as a shortcut in Chrome to jump between the two most recent tabs. There is an extension that lets you do it. It is called "Recent Tabs". For me setting the shortcut to Ctrl-Tab wasn't possible through the UI. Use this instead:

cd [YOUR CHROME PROFILE DIR]
vi Default/Preferences

Problem is that Chrome just overwrites that setting every time. So what I had to do is add this line to my startup shell script

sed -i "s,Ctrl+Q,Ctrl+Tab,g" "$DATA_DIR/Default/Preferences"

Friday, 1 December 2017

Desktop notifications for dwm

I decided to configure desktop notifications for my environment. I ended up choosing dunst

Follow these instructions and join me using dunst!

To send an example notification

notify-send 'Hello world!' 'This is an example notification.' --icon=dialog-information

Thursday, 21 September 2017

Attribute path for chef searches

Do I need to specify the full path for the attribute when doing a search in chef?

Given that you have a node with some attributes (see that fqdn is a nested attribute)

root@crowbar:~ # knife node show d52-54-77-77-01-01.virtual.cloud.suse.de -F json | head
{
  "name": "d52-54-77-77-01-01.virtual.cloud.suse.de",
  "chef_environment": "_default",
  "run_list": [
    "role[crowbar-d52-54-77-77-01-01_virtual_cloud_suse_de]"
  ],
  "normal": {
    "fqdn": "d52-54-77-77-01-01.virtual.cloud.suse.de",
    "crowbar": {
      "network": {

You want to do some searches:

root@crowbar:~ # knife search node 'name:d52-54-77-77-01-01.virtual.cloud.suse.de' -i
1 items found


d52-54-77-77-01-01.virtual.cloud.suse.de

And if you are interested in the fqdn, you do not need to specify the full path:

root@crowbar:~ # knife search node 'fqdn:d52-54-77-77-01-01.virtual.cloud.suse.de' -i
1 items found

d52-54-77-77-01-01.virtual.cloud.suse.de




Wednesday, 30 August 2017

Adding a new node to a role in crowbar

I had some issues with the swift proposal. Proxy nodes were clustered but not all nodes of the cluster were part of the storage nodes. Therefore it always failed with a message like:

See that the proposal has issues:

crowbarctl proposal show --format=json swift default > swift.json

The relevant part:
      "elements": {
        "swift-dispersion": [
          "d52-54-77-77-01-01.vh6.cloud.suse.de"
        ],
        "swift-proxy": [
          "cluster:data"
        ],
        "swift-ring-compute": [
          "d52-54-77-77-01-01.vh6.cloud.suse.de"
        ],
        "swift-storage": [
          "d52-54-77-77-01-05.vh6.cloud.suse.de",
          "d52-54-77-77-01-03.vh6.cloud.suse.de",
          "d52-54-77-77-01-04.vh6.cloud.suse.de",
          "d52-54-77-77-01-02.vh6.cloud.suse.de"
        ]

      },

Then edit the file, so you create a swift-new.json like so:

{
  "deployment": {
    "swift": {
      "elements": {
        "swift-storage": [
          "d52-54-77-77-01-05.vh6.cloud.suse.de",
          "d52-54-77-77-01-03.vh6.cloud.suse.de",
          "d52-54-77-77-01-04.vh6.cloud.suse.de",
          "d52-54-77-77-01-01.vh6.cloud.suse.de",
          "d52-54-77-77-01-02.vh6.cloud.suse.de"
        ]
      }
    }
  }
}

And edit the proposal:

crowbarctl proposal edit --merge --file swift-new.json swift default
crowbarctl proposal commit swift default

Rabbitmq Cheatsheet

I am new to rabbit, so here are some notes:

First find out where rabbit api listens:
ss -na | grep 15672

And then get the management cli:
wget  192.168.243.81:15672/cli/rabbitmqadmin
chmod +x rabbitmqadmin

Get a message from a queue:
./rabbitmqadmin --host 192.168.243.81 -u nova -p gD6Yzyvr4E7h  -V /nova get queue=notifications.info

Thursday, 25 May 2017

Associate a file extension with an application in Linux

Let's try to associate a file extension to a specific application. For the sake of this example, I would like to associate .somefile to be opened with sublime /usr/bin/subl

Before beginning, let's set a baseline. If you use the xdg-mime utility to query a file's type, you most probably will get something like text/plain. To try this out, let's create a sample file:

touch x.somefile

And then see what the system thinks about this filetype:

xdg-mime query filetype x.somefile

Most probably it will print out something, like text/plain. The first exercise is to change it.
Let's create a new mime type. For this, I'll need to create an xml file, with the name of lakat-somefile.xml (lakat is a vendor string, you might want to replace it with something else):

<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
  <mime-type type="application/x-somefile">
    <comment>somefile type file</comment>
    <glob pattern="*.somefile"/>
  </mime-type>
</mime-info>

Now let's install this mimetype:

xdg-mime install lakat-somefile.xml

And see that now the type of our dummy file is recognised:

xdg-mime query filetype x.somefile

We are expecting application/x-somefile there. If you are seeing something like inode/x-empty there, you most likely need to install some mime specific packages. In arch linux, what you need is:

sudo pacman -S perl-file-mimeinfo

Once that's done, the next thing to do is to create an "application" that will be used to open this file. If you already have an application, you don't need to do this.

Create a file, called somefile.desktop with the following contents:

[Desktop Entry]
Name=Somefile opener
Comment=Opens with sublime
Exec=/usr/bin/subl
Version=1.0
Type=Application
MimeType=application/x-somefile

now move this file to your home directory, as a per user application:

cp somefile.desktop ~/.local/share/applications/

Now we need to associate the two. Before we do that, let's make sure that we have the correct files in place. Some old applications refer to this config file as  ~/.local/share/applications/mimeapps.list, others refer to it as ~/.config/mimeapps.list. But both should be the same, so let's say that ~/.config/mimeapps.list is a symlink to ~/.local/share/applications/mimeapps.list:

ln -s ~/.local/share/applications/mimeapps.list ~/.config/mimeapps.list

Now before we start to edit this file, let's see what is the situation now, what application is used to open application/x-somefile type files:

xdg-mime query default application/x-somefile

That should yield nothing at the moment. So let's add some associations. Open ~/.config/mimeapps.list, and add something like this:

[Default Applications]
application/x-somefile=somefile.desktop

Now doing the query again, you should see that:

xdg-mime query default application/x-somefile

returns somefile.desktop as expected. Now you should be all set, and you can open your files with xdg-open:

xdg-open x.somefile


Tuesday, 23 May 2017

Git - find a specific version by stacktrace

So you have a stacktrace, something that tells you that on line XXX an exception has been raised. You want to find out what was the exact version of the code that was running at that time.

git log origin/neutron-ha-tool-maintenance --oneline -- files/default/neutron-ha-tool.py |
cut -d " " -f 1 |
while read revision; do echo $revision; git show $revision:files/default/neutron-ha-tool.py |
sed -n 576,577p ; done |
less

Friday, 19 May 2017

OpenStack - Launch your First VM

Some notes on how to get started with a freshly baked OpenStack (Liberty)


  • First, an image needs to be uploaded:


wget -qO - http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img | openstack image create cirros --public --container-format=bare --disk-format=qcow2


  • Then we need to create a network:


openstack network create testnetwork


  • Within the network, a subnet needs to be created:


neutron subnet-create --name testsubnet testnetwork 192.168.37.0/24


  • Please note that a more recent version of OpenStack might support the openstack subnet create command as well.



  • Let's create a router now:


neutron router-create testrouter


  • Now set the router's default gateway by connecting it to a network:


neutron router-gateway-set testrouter floating


  • And link the router to the subnet:


neutron router-interface-add testrouter testsubnet


  • Now launch your instance:


nova boot --flavor m1.tiny --image cirros --nic net-id=a6a6c271-a391-4bff-9eda-79a97a8e1154 i1


  • Create a floating IP:


neutron floatingip-create floating
nova floating-ip-associate i1 192.168.122.131


  • Add rules to security group for icmp and ssh


openstack security group rule create --proto icmp default
openstack security group rule create --proto tcp --dst-port 22:22 default

Saturday, 29 April 2017

Remove Already Merged Branches from Git

In case you need that, here is the draft:

git branch --merged master | sed -n 's,^ \+\(.*\)$,\1,p' | xargs git branch -d

Wednesday, 26 April 2017

Tmate cheatsheet

If you detached tmate, you might want to re-attach by:
tmate -S /tmp/tmate-0/DpfNjI attach

Tuesday, 25 April 2017

iptables - deny connecting to a host

I would like to test a scenario where server A cannot reach server B. To establish this, I will add iptables rules on server A so ssh connections fail. After some research (basically reading this article) I managed to come up with the rules I need. Before doing anything it is good to know the state of the system. Use
iptables -S
to find out existing rules on your system. To block connections to ssh, use:
iptables -A OUTPUT -p tcp --dport ssh -d 192.168.124.82 -j REJECT
removing the rule is simple, list the rules with iptables -S and replace -A with -D:
iptables -D OUTPUT -d 192.168.124.82/32 -p tcp -m tcp --dport 22 -j REJECT --reject-with icmp-port-unreachable

Friday, 10 March 2017

Running Cinder Migration Unit Tests

Cinder has some unit tests for migration. If you want to run them on your computer, you'll need to set up database administrator accounts for your backends, and export an environment variable before running the test:
One-liner:
for backend in \
    mysql+pymysql://root:secret@localhost/mysql \
    postgresql://postgres:secret@localhost/cinder \
    sqlite:///somefile.db \
; do
    OS_TEST_DBAPI_ADMIN_CONNECTION=$backend \
        python -m subunit.run cinder.tests.unit.test_migrations |
            subunit2pyunit
done


MySQL
OS_TEST_DBAPI_ADMIN_CONNECTION='mysql+pymysql://root:secret@localhost/mysql'\
 python -m subunit.run cinder.tests.unit.test_migrations | subunit2pyunit

PostgreSQL
OS_TEST_DBAPI_ADMIN_CONNECTION='postgresql://postgres:secret@localhost/cinder'\
 python -m subunit.run cinder.tests.unit.test_migrations | subunit2pyunit

SQLite
OS_TEST_DBAPI_ADMIN_CONNECTION='sqlite:///somefile.db'\
 python -m subunit.run cinder.tests.unit.test_migrations | subunit2pyunit

Friday, 24 February 2017

PostgreSQL Notes

Backup a Database

sudo -u postgres --format=custom --file=<file name> <database name>

Restore a Database

First, create an empty database:
create database <database name> with encoding='utf-8';
Then grant all permissions to your user:
grant all on database <database name> to <user name>;
Then restore the dump:
sudo -u postgres pg_restore \
    --schema=public \
    --dbname=<database name> \
    --no-owner \
    --no-privileges \
    --role=<user name> \
    <file name>

Saturday, 25 July 2015

System backup

  • Transfer all the files to the new partition

    rsync -aAXvHS --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/data"} /* /mnt/backup/
    
  • Get the UUID for the new partition

    [root@archie /]# blkid /dev/sda2 
    /dev/sda2: UUID="ca2f7146-122f-4746-8725-7aeb4ca792e6" TYPE="ext4" PARTUUID="48c724bf-02"
    
  • Edit mountpoints

    [root@archie /]# vim /etc/fstab
    
  • Edit the new system's boot configuration

    [root@archie /]# vim /mnt/backup/boot/syslinux/syslinux.cfg
    
  • Enter the new system and fix booting

    [root@archie /]# arch-chroot /mnt/backup/
    sh-4.3# syslinux-install_update -i -a -m
    Syslinux BIOS install successful
    Boot Flag Set - /dev/sda2
    Installed MBR (/usr/lib/syslinux/bios/mbr.bin) to /dev/sda
    

Sunday, 5 July 2015

Burning Blu Ray Discs

Look at this blog
For mkudffs, see arch: udftools

What I get is

24712708096/25000000000 (98.9%) @0.9x, remaining 1:08 RBU 100.0% UBU  76.6%
24726929408/25000000000 (98.9%) @0.9x, remaining 1:04 RBU 100.0% UBU  79.7%
24741150720/25000000000 (99.0%) @0.9x, remaining 1:01 RBU 100.0% UBU  85.9%
24755372032/25000000000 (99.0%) @0.9x, remaining 0:58 RBU 100.0% UBU  73.4%
:-[ WRITE@LBA=b87400h failed with SK=5h/END OF USER AREA ENCOUNTERED ON THIS TRACK]: Input/output error
:-( write failed: Input/output error
/dev/sr2: flushing cache
/dev/sr2: closing track
/dev/sr2: closing session
:-[ CLOSE SESSION failed with SK=5h/INVALID FIELD IN CDB]: Input/output error
/dev/sr2: reloading tray

Friday, 28 November 2014

Ubuntu - Update hostname from DHCP

This script is basically a mutation of the script found in drwindsor's post :
#!/bin/sh
# Filename:     /etc/dhcp/dhclient-exit-hooks.d/hostname
# Purpose:      Used by dhclient-script to set the hostname of the system
#               to match the DNS information for the host as provided by
#               DHCP.
#

if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] \
   && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]
then
        return
fi

echo dhclient-exit-hooks.d/hostname: Dynamic IP address = $new_ip_address
hostname=$(host $new_ip_address | cut -d ' ' -f 5 | cut -d "." -f 1)
echo $hostname > /etc/hostname
hostname $hostname
echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = $hostname

Git mirror without cloning

What I want to do is to set up a bare mirror git repository without fetching the changes. It should be a fast operation compared to:
git clone --mirror $REPOURL
Here are the steps that I did to achieve the same results as a full clone:
# Create and update with the clone command
git clone --mirror https://github.com/matelakat/vimide vimide-with-clone
cd vimide-with-clone/
git fetch
cd ..
And let's create the equivalent:
git init --bare vimide-manual
cd vimide-manual
git remote add --mirror origin https://github.com/matelakat/vimide
git fetch
git pack-refs --all --prune
cd ..
You can see that the two directories are the same:
diff -r vimide-with-clone/ vimide-manual/ && echo "ALL the same"
ALL the same

Monday, 4 August 2014

Differences between git branches

The problem

Given I have two branches, A and B within a git repository, I would like to come up with two sets of changes: (A-B) and (B-A). So I would like to find all the commits that are in A but not in B, and vice versa.

Introducing the same change to two branches

Let's set up a git repository to play with. As a first step, I create an initial commit, with only one file in it, a simple greeting:
$ git init
$ echo "hello there" > hello.txt
$ git add hello.txt
$ git commit -m "Initial commit"
And now, make the branching, and introduce the same change to each of those branches:
$ git checkout -b A
$ echo "blah" > blah.txt
$ git add blah.txt
$ git commit -m "Added blah"
And see the B branch:
$ git checkout master -b B
$ echo "blah" > blah.txt
$ git add blah.txt
$ git commit -m "Added blah"
See if git is smart enough to find out that the two changes are the same:
$ git log A..B --oneline | wc -l
1
Of course, they are not the same, they are copies of the other. So let's see the other command, called git-cherry:
$ git cherry A B
This shows only one line, with a minus sign. From the documentation of git cherry:
git cherry [-v] [<upstream> [<head> [<limit>]]]

       Every commit that doesn’t exist in the <upstream> branch has its id (sha1) reported,
       prefixed by a symbol. The ones that have equivalent change already in the <upstream>
       branch are prefixed with a minus (-) sign, and those that only exist in the <head>
       branch are prefixed with a plus (+) symbol:

Saturday, 21 June 2014

SSD - Bytes written

I Have an Intel 520 SSD. I can use smartmontools to ask how much bytes have been written to it:
sudo ./smartctl -q noserial -i -l devstat,0 -l devstat /dev/sda
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.2.0-32-generic] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Intel 520 Series SSDs
Device Model:     INTEL SSDSC2CW240A3
Firmware Version: 400i
User Capacity:    240,057,409,536 bytes [240 GB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    Solid State Device
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ACS-2 T13/2015-D revision 3
SATA Version is:  SATA 3.0, 3.0 Gb/s (current: 3.0 Gb/s)
Local Time is:    Sat Jun 21 08:42:06 2014 BST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

Device Statistics (GP Log 0x04) supported pages
Page Description
  0  List of supported log pages
  1  General Statistics
  4  General Errors Statistics
  6  Transport Statistics
  7  Solid State Device Statistics

Device Statistics (GP Log 0x04)
Page Offset Size         Value  Description
  1  =====  =                =  == General Statistics (rev 2) ==
  1  0x008  4             1129  Lifetime Power-On Resets
  1  0x010  4             8660  Power-on Hours
  1  0x018  6       5401949881  Logical Sectors Written
  1  0x028  6       5794864033  Logical Sectors Read
  4  =====  =                =  == General Errors Statistics (rev 1) ==
  4  0x008  4                0  Number of Reported Uncorrectable Errors
  4  0x010  4             9232  Resets Between Cmd Acceptance and Completion
  6  =====  =                =  == Transport Statistics (rev 1) ==
  6  0x008  4             9232  Number of Hardware Resets
  6  0x010  4             4085  Number of ASR Events
  6  0x018  4                0  Number of Interface CRC Errors
  7  =====  =                =  == Solid State Device Statistics (rev 1) ==
  7  0x008  1              255  Percentage Used Endurance Indicator