Thursday, December 28, 2017

Custom Gitlab Hooks

8:12 PM Posted by Dilli Raj Maharjan No comments

Gitlab installation

Update linux machine with yum update.
yum -y update


Once update is completed install postfix for notifications. 
yum install postfix
service postfix start
chkconfig postfix on



Add the GitLab package repository and install the package
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | bash


Install gitlab package. Here specify the External URL you want gitlab to be accessed.
EXTERNAL_URL="http://192.168.100.25" yum -y install gitlab-ee



If you need to change EXTERNAL_URL or IP address of the host where gitlab is installed following are the steps.
1. Modify external_url parameter in file /etc/gitlab/gitlab.rb
2. gitlab-ctl reconfigure

Start gitlab with command below
gitlab-ctl start



Configure gitlab on 8888 port so that apache can be started on port 80.
Open /etc/gitlab/gitlab.rb and modify 
nginx['listen_port'] = nil to nginx['listen_port'] = 8888
external_url 'http://192.168.100.25' to external_url 'http://192.168.100.25:8888'






Once modification completes execute reconfigure command
gitlab-ctl reconfigure



Restart gitlab to get the new setting in effect.
gitlab-ctl restart



Login to gitlab external url with following address
http://192.168.100.25:8888

Once you open page for the first time you need to set the root user password. Type root user password and click on Submit.


Now register new user. Click on Create project to add new gitlab project.



Set Project name. Click on Create Project.


 Clone git repository locally.
git clone http://192.168.100.25:8888/dmaharjan/dilli_com_np.git


Add index page on local repository.
cd dilli_com_np
echo "This is index page" >> index.html



Add file, commit and push to git remote repository.
git add .
git commit -m "Adding index.html"
git push


Install apache. In our case apache server is web hosting for the client.
yum -y install httpd


Change directory to /var/www/html and clone git repo.
git clone http://dmaharjan@192.168.100.25:8888/dmaharjan/dilli_com_np.git



The page is accessible with the URL below:
http://192.168.100.25/dilli_com_np/index.html


Change directory to remote repository in our case /var/opt/gitlab/git-data/repositories/dmaharjan/dilli_com_np.git . Here dmaharjan is repos user and dilli_com_np is repository directory.
cd /var/opt/gitlab/git-data/repositories/dmaharjan/dilli_com_np.git
Create directory custom_hooks


Create hook file named post-receive with the content below
#!/bin/bash

cd /var/www/html/dilli_com_np
sudo /usr/bin/git stash
sudo /usr/bin/git pull



Change ownership of hook file and make it executable.
chown -R git:git post-receive 
chmod 755 post-receive 



Change sudo configuration and add following
git         ALL=NOPASSWD: /usr/bin/git stash, /usr/bin/git pull



Change ownership of /var/www/html/dilli_com_np
chown -R apache:apache /var/www/html/dilli_com_np


Login as user git and verify sudo is working for user git. Make sure Password is not required for sudo and git pull



Now change the content of the local repo, add the file, commit it and push it. The hook should be executed and change should be reflected immediately on the web directory.
Change directory to local repository and add content to the file.
echo "Adding new line 1" >> index.html 
git add .
git commit -m "Testing hook"
git push




View change on the web directory.






Troubleshooting:
Error: sudo: sorry, you must have a tty to run sudo while performing git push.



Search for Add Following lines "Defaults  requiretty" and add Defaults:git !requiretty below the line.



You will get successfully push and hook file executed.




Monday, December 18, 2017

Configure samba to share oracle files with Windows server

10:00 PM Posted by Dilli Raj Maharjan No comments

Environment: CentOS/Windows Machine


Configure following on linux server with Oracle database.


Add os group for samba
groupadd smbgrp

Create Linux OS user with useradd command. In my case I am adding user ajay and setting password using command passwd.
useradd ajay -G smbgrp
passwd ajay


Create directory that will be shared with Windows server.  I am using this directory to store my oracle dump files which will be shared with my Windows Server. Owner and group of this folder have permission of read, write and execute. If you do not need write permission to group then you may use chmod 750 instead of 770.
mkdir /u01/app/oracle/dumpdir
chmod 770 /home/oracle/dumpdir
chown oracle:smbgrp /u01/app/oracle/dumpdir



Create oracle directory with SQL command below. Oracle directory object need to be created which will point to OS directory. We will use this directory object name while using expdp.
create directory dir_dump as '/u01/app/oracle/dumpdir';



If samba linux package is not installed then install samba package and its dependency with yum command.
yum install samba -y



Use smbpasswd command to configure username and password that will be used to access the share directory. Note you can use different password from the password used for OS user ajay. 
smbpasswd -a ajay


Open samba configuration file with editor to configure samba.
vi /etc/samba/smb.conf


Change workgroup to your existing workgroup 
workgroup = WORKGROUP


Add following samba configuration parameters at the end of the configuration files.
[Share]
path=/u01/app/oracle/dumpdir
valid users=ajay
read only=yes
public=no
writable=no
valid host=192.168.100.44



Explanation:
[Share] Share directory name that will be visible to the user
path OS location of the directory we are sharing
valid users list of the trusted users. The user need to supply password to authenticate 
read only defines the shared directory is read only or read write.
public defines this shared directory is publicly available or not. If the value is set to yet then username/password will not be prompted while accessing shared directory.
writable defines the share directory is writeable or not 
valid host list of the trusted hosts that have access on share directory.

Restart samba service to reflect the configuration added.
/etc/init.d/smb restart



Now export dump from the database server, make sure that shared directory is used
expdp system directory=dir_dump dumpfile=system.dmp logfile=system.log schemas=system

    .....................

Windows host

Now open Windows server with the IP address specified above. If my case my windows machine's IP address is 192.168.100.44. Only this machine has access to this share directory.

Type \\192.168.100.101  on run or \\hostname of linux. You may also click on network which will list the name of the linux server.



Since public=no is set on configuration, you will be prompt for the password. Please provide the samba user and the password for samba server. In my case I am using ajay as the user and the passwod that I have provided with smbpasswd.


Now we can easily access the dump files created on the shared directory of Linux server.