Thursday, November 22, 2018

github - get patch file from PR



So, you have a PR like this:
https://github.com/openshift/openshift-ansible/pull/10077


To get the corresponding patch, just add .patch to the PR number.

https://github.com/openshift/openshift-ansible/pull/10077.patch




https://owenou.com/ten-things-you-didnt-know-git-and-github-could-do


Wednesday, November 21, 2018

Get IP address of the VM from the host



Get IP address of the VM from the host

First:
# virsh net-list
< list of networks>


Next:
# virsh net-dhcp-leases   

Expiry Time          MAC address        Protocol  IP address                Hostname        Client ID or DUID
< get hostname and the corresponding IP address here  >



Monday, November 19, 2018

interesting challenges for fun :)


interesting challenges to try for 30 days :) :)

http://hackerella.com/30-day-challenge-ideas/






file command in linux


file command

file command can be used to determine filetype.

For example.

# file file.txt
file.txt: ASCII text

# file testfile.pdf

testfile.pdf PDF document, version 1.5


You can also check disk files.: ( you need root permission though)

file -s  /dev/sda1 

$ sudo file -s /dev/sda1
/dev/sda1: Linux rev 1.0 ext4 filesystem data, UUID=ABCD-ABCD-XYZ (needs journal recovery) (extents) (large files) (huge files)



 

systemctl list units




systemctl list-units

Show only the failed units:

systemctl list-units   --state=failed





Sunday, November 18, 2018

Running heketi commands in Kubernetes / OpenShift


heketi is the REST API client/server to manage glusterfs volumes.

https://github.com/heketi/heketi


Before, running heketi commands you need to export three variables.

HEKETI_CLI_SERVER
HEKETI_CLI_USER
HEKETI_CLI_KEY


1.
oc get route


use the above url with http:// added in the front.

#export HEKETI_CLI_SERVER=http://url above


2.
username configured

# export HEKETI_CLI_KEY=admin

3.

Get the admin key from the command
# oc get pods heketi-cns-1-sgwwg -o yaml | grep HEKETI_ADMIN_KEY -A1
    - name: HEKETI_ADMIN_KEY
      value: admin

# export HEKETI_CLI_USER=admin

Note: use kubectl in case of kubernetes.  example shows oc which is for openshift.
---------------------------


Now, you can verify the heketi commands as:

# heketi-cli cluster list


Friday, November 9, 2018

git - check source code of a file for a range of commits



See history for two lines in a file

 git log --pretty=short -u -L 6,7:Dockerfile


here, 6,7 represents the line no. Adjust according to your needs.

git version should be 1.8.4  or later .


originally from : https://stackoverflow.com/questions/8435343/retrieve-the-commit-log-for-a-specific-line-in-a-file/31985012

Installing git from source



While trying to install git from source faced this error:
Can't locate ExtUtils/MakeMaker.pm


You can fix it by installing :

yum install perl-ExtUtils-MakeMaker



Note1:
for installing git followed this link:
Source: https://git-scm.com/book/eo/v1/Ekkomenci-Installing-Git ;

In general, avoid installing from source. 
Try to install using repo. so that dependencies are taken care automatically.



Monday, November 5, 2018

Writing a simple systemd script

cd /usr/lib/systemd/system/
edit a file named simple.service with following contents:
===========================
[Unit]
Description=Simple Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/test
Restart=on-abort

[Install]
WantedBy=multi-user.target
===========================

Here, /usr/bin/test is the example program.

Now, check the status by default
$ systemctl status simple

● simple.service - Simple Service
   Loaded: loaded (/usr/lib/systemd/system/simple.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

Start the service
$ sudo systemctl start simple

Now, check the status:
$ sudo systemctl status simple
output :
● simple.service - Simple Service
   Loaded: loaded (/usr/lib/systemd/system/simple.service; disabled; vendor preset: disabled)
   Active: active (running) since
 Main PID: 23791 (test)
   CGroup: /system.slice/simple.service
           └─23791 /usr/bin/test
systemd[1]: Started Simple Service.
systemd[1]: Starting Simple Service...

To stop the service:
$ sudo systemctl stop simple

To enable the service by default
sudo systemctl enable simple

Created symlink from /etc/systemd/system/multi-user.target.wants/simple.service to /usr/lib/systemd/system/simple.service.

$ ls -l /etc/systemd/system/multi-user.target.wants/simple.service

lrwxrwxrwx 1 root root  /etc/systemd/system/multi-user.target.wants/simple.service -> /usr/lib/systemd/system/simple.service

To get more idea about different keywords used in systemd script, refer man 5 systemd.service

For example in the above one following keywords are used:

ExecStart = command executed when service is started.
After = after the specific service started.
Restart= when to restart the service.
WantedBy= which run level this is required.