Bug 1309401

Summary: setup.sh Enhancement
Product: Red Hat Gluster Storage Reporter: Mohamed Ashiq <mliyazud>
Component: rhgs-server-containerAssignee: Mohamed Ashiq <mliyazud>
Status: CLOSED CURRENTRELEASE QA Contact: Prasanth <pprakash>
Severity: urgent Docs Contact:
Priority: unspecified    
Version: rhgs-3.1CC: asrivast, hchiramm, pprakash, rcyriac, sankarshan
Target Milestone: ---Keywords: ZStream
Target Release: RHGS 3.1.2   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: rhgs-server-docker-3.1.2-8 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-12-19 17:38:27 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Mohamed Ashiq 2016-02-17 17:08:06 UTC
Description of problem:
setup.sh is on the root directory and has to be made more like bash script rather than few commands. Also the permissions of the script has to be revisited.

Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:


Expected results:


Additional info:

Comment 2 Humble Chirammal 2016-02-18 02:50:32 UTC
The changes introduced:

The backup directory has been renamed to *_bkp instead of _bck
The path of setup.sh moved to /usr/sbin instead of /root
The permission of setup changed to 500
script modified to proper bash syntax.

Comment 5 Mohamed Ashiq 2016-02-18 07:23:37 UTC
So new things are:

# docker run --name=glusterdata -v /etc/glusterfs/:/etc/glusterfs/:z -v /var/lib/glusterd/:/var/lib/glusterd/:z -v /var/log/glusterfs/:/var/log/glusterfs/:z -v /sys/fs/cgroup:/sys/fs/cgroup:ro brew-pulp-docker01.web.prod.ext.phx2.redhat.com:8888/rhgs3/rhgs-server-rhel7:3.1.2-8 /usr/sbin/setup.sh

Changing it to run (from docker create and start) since it does the same operation. Docker create and start steps were followed docker document(https://docs.docker.com/engine/userguide/containers/dockervolumes/) which says docker run can also be used. moving to run since it skips one step.

Now about the script:

1) script will now not allow to copy anything into /var/log/glusterfs, /var/lib/glusterd and /etc/glusterfs if found some content in the directories already. This will be helpful if user runs the script again unknowingly.

2) copy function error handling has been done.

3) moved the setup.sh script from root to /usr/sbin/setup.sh.

4) permissions of script changed to 500.

Comment 6 Prasanth 2016-02-19 08:48:24 UTC
The enhanced setup.sh script is working as excepted as described in Comment 5. Hence marking this BZ as Verified.

############
-bash-4.2# docker run --name=glusterdata -v /etc/glusterfs/:/etc/glusterfs/:z -v /var/lib/glusterd/:/var/lib/glusterd/:z -v /var/log/glusterfs/:/var/log/glusterfs/:z -v /sys/fs/cgroup:/sys/fs/cgroup:ro brew-pulp-docker01.web.prod.ext.phx2.redhat.com:8888/rhgs3/rhgs-server-rhel7:3.1.2-8 /usr/sbin/setup.sh
Script Ran Successfully
 

-bash-4.2# docker ps -a
CONTAINER ID        IMAGE                                                                                  COMMAND                CREATED             STATUS                      PORTS               NAMES
562d8f1c1092        brew-pulp-docker01.web.prod.ext.phx2.redhat.com:8888/rhgs3/rhgs-server-rhel7:3.1.2-8   "/usr/sbin/setup.sh"   26 minutes ago      Exited (0) 26 minutes ago                       glusterdata


-bash-4.2# docker run --privileged --net=host --name=node4 -d -v /var/mount/brick1:/rhgs/b1 -v /var/mount/brick2:/rhgs/b2 -v /var/mount/brick3:/rhgs/b3 -v /var/mount/brick4:/rhgs/b4 --volumes-from glusterdata brew-pulp-docker01.web.prod.ext.phx2.redhat.com:8888/rhgs3/rhgs-server-rhel7:3.1.2-8
2ebc7b5be4b6fde31bbbd9b840e1b7bdfd5635466c11200fd6697520084a7d97


-bash-4.2# docker ps
CONTAINER ID        IMAGE                                                                                  COMMAND             CREATED             STATUS              PORTS               NAMES
2ebc7b5be4b6        brew-pulp-docker01.web.prod.ext.phx2.redhat.com:8888/rhgs3/rhgs-server-rhel7:3.1.2-8   "/usr/sbin/init"    7 seconds ago       Up 4 seconds                            node4


-bash-4.2# docker exec -ti 2ebc7b5be4b6 /bin/bash
[root@dhcp42-184 /]# cat /etc/redhat-storage-release 
Red Hat Gluster Storage Server 3.1 Update 2 ( Container)
[root@dhcp42-184 /]# 


[root@dhcp42-184 /]# ls -l /usr/sbin/setup.sh 
-r-x------. 1 root root 1095 Feb 17 23:45 /usr/sbin/setup.sh

[root@dhcp42-184 /]# cat /usr/sbin/setup.sh
#!/bin/bash

###
# Description: Script to move the glusterfs initial setup to bind mounted directories of Atomic Host.
# Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com>
#
# This file is part of GlusterFS.
#
# This file is licensed to you under your choice of the GNU Lesser
# General Public License, version 3 or any later version (LGPLv3 or
# later), or the GNU General Public License, version 2 (GPLv2), in all
# cases as published by the Free Software Foundation.
###

main () {
  DIR_1="/etc/glusterfs"
  DIR_2="/var/log/glusterfs"
  DIR_3="/var/lib/glusterd"
  for i in $DIR_1 $DIR_2 $DIR_3
  do
    if test "$(ls $i)"
    then
      echo "$i is not empty"
      exit 1
    fi
  done
  
  cp -r /etc/glusterfs_bkp/* /etc/glusterfs
  if [ $? -eq 1 ]
  then
        echo "Failed to copy $DIR_1" 
        exit 1
  fi
  cp -r /var/log/glusterfs_bkp/* /var/log/glusterfs
  if [ $? -eq 1 ]
  then
        echo "Failed to copy $DIR_2"
        exit 1
  fi 
  cp -r /var/lib/glusterd_bkp/* /var/lib/glusterd
  if [ $? -eq 1 ]
  then
        echo "Failed to copy $DIR_3"
        exit 1
  fi 
  echo "Script Ran Successfully"
}
main
############