-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wip: group RUN's, conditionalize starting of services #18
base: master
Are you sure you want to change the base?
Changes from all commits
67d1e23
b15d947
8fd43ff
1239d34
a8135f7
cc0fe17
c70f353
5fd8c0d
4932edf
1bd6804
993f3cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,52 +3,35 @@ FROM centos:latest | |
MAINTAINER Humble Chirammal [email protected] | ||
|
||
ENV container docker | ||
VOLUME [ "/sys/fs/cgroup", "/etc/glusterfs", "/var/lib/glusterd", "/var/log/glusterfs", "/var/lib/heketi" ] | ||
EXPOSE 2222 111 245 443 24007 2049 8080 6010 6011 6012 38465 38466 38468 38469 49152 49153 49154 49156 49157 49158 49159 49160 49161 49162 | ||
|
||
RUN yum --setopt=tsflags=nodocs -y update; yum clean all; | ||
|
||
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \ | ||
rm -f /lib/systemd/system/multi-user.target.wants/*;\ | ||
rm -f /etc/systemd/system/*.wants/*;\ | ||
rm -f /lib/systemd/system/local-fs.target.wants/*; \ | ||
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \ | ||
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \ | ||
rm -f /lib/systemd/system/basic.target.wants/*;\ | ||
rm -f /lib/systemd/system/anaconda.target.wants/*; | ||
|
||
RUN yum --setopt=tsflags=nodocs -y install wget nfs-utils attr iputils iproute centos-release-gluster | ||
|
||
RUN wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm; rpm -ivh epel-release-latest-7.noarch.rpm; rm epel-release-latest-7.noarch.rpm; | ||
|
||
RUN yum --setopt=tsflags=nodocs -y install openssh-server openssh-clients ntp rsync tar cronie sudo xfsprogs glusterfs glusterfs-server glusterfs-geo-replication;yum clean all; | ||
|
||
RUN sed -i '/Defaults requiretty/c\#Defaults requiretty' /etc/sudoers | ||
|
||
# Changing the port of sshd to avoid conflicting with host sshd | ||
RUN sed -i '/Port 22/c\Port 2222' /etc/ssh/sshd_config | ||
|
||
# Backing up gluster config as it overlaps when bind mounting. | ||
RUN mkdir -p /etc/glusterfs_bkp /var/lib/glusterd_bkp /var/log/glusterfs_bkp;\ | ||
cp -r /etc/glusterfs/* /etc/glusterfs_bkp;\ | ||
cp -r /var/lib/glusterd/* /var/lib/glusterd_bkp;\ | ||
cp -r /var/log/glusterfs/* /var/log/glusterfs_bkp; | ||
|
||
# Adding script to move the glusterfs config file to location | ||
ADD gluster-setup.service /etc/systemd/system/gluster-setup.service | ||
RUN chmod 644 /etc/systemd/system/gluster-setup.service | ||
|
||
# Adding script to move the glusterfs config file to location | ||
ADD gluster-setup.sh /usr/sbin/gluster-setup.sh | ||
RUN chmod 500 /usr/sbin/gluster-setup.sh | ||
|
||
RUN echo 'root:password' | chpasswd | ||
VOLUME [ “/sys/fs/cgroup” ] | ||
|
||
RUN systemctl disable nfs-server.service | ||
RUN systemctl enable ntpd.service | ||
RUN systemctl enable rpcbind.service | ||
RUN systemctl enable glusterd.service | ||
RUN systemctl enable gluster-setup.service | ||
|
||
EXPOSE 2222 111 245 443 24007 2049 8080 6010 6011 6012 38465 38466 38468 38469 49152 49153 49154 49156 49157 49158 49159 49160 49161 49162 | ||
RUN yum --setopt=tsflags=nodocs -y install centos-release-gluster epel-release && \ | ||
yum --setopt=tsflags=nodocs -y install wget nfs-utils attr iputils iproute \ | ||
openssh-server openssh-clients ntp rsync tar cronie sudo xfsprogs \ | ||
glusterfs glusterfs-server glusterfs-geo-replication && \ | ||
yum clean all && \ | ||
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done) && \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure but doesn't this wipe the service files of gluster too, since its done after installation of the packages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, yes. It wipes the annotation that they are to be started (if they start automatically). The unit files themselves don't reside there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we copy our service file here thought everyone will be doing the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But that one does not get deleted. Only the unit links in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah my bad did not notice the "xxx.wants" there. Thanks |
||
rm -f /lib/systemd/system/multi-user.target.wants/* && \ | ||
rm -f /etc/systemd/system/*.wants/* && \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the way |
||
rm -f /lib/systemd/system/local-fs.target.wants/* && \ | ||
rm -f /lib/systemd/system/sockets.target.wants/*udev* && \ | ||
rm -f /lib/systemd/system/sockets.target.wants/*initctl* && \ | ||
rm -f /lib/systemd/system/basic.target.wants/* && \ | ||
rm -f /lib/systemd/system/anaconda.target.wants/* && \ | ||
sed -i '/Defaults requiretty/c\#Defaults requiretty' /etc/sudoers && \ | ||
sed -i '/Port 22/c\Port 2222' /etc/ssh/sshd_config && \ | ||
for dir in /etc/glusterfs /var/lib/glusterd /var/log/glusterfs; do \ | ||
mkdir -p ${dir}_bkp && \ | ||
cp -r $dir/* ${dir}_bkp ; \ | ||
done && \ | ||
chmod 644 /etc/systemd/system/gluster-setup.service && \ | ||
chmod 500 /usr/sbin/gluster-setup.sh && \ | ||
systemctl disable nfs-server.service && \ | ||
systemctl enable glusterd.service gluster-setup.service && \ | ||
echo 'root:password' | chpasswd | ||
|
||
CMD ["/usr/sbin/init"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
This dockerfile can be used to build a CentOS Gluster Container. | ||
|
||
|
||
## Automounting bricks | ||
|
||
If you volume-mount an `fstab(5)` file, the container will mount all bricks in that file. | ||
Specify the name with environment variable `FSTAB`. | ||
|
||
A deprecated way is volume mounting /var/lib/heketi/fstab without setting `FSTAB` to that file. | ||
|
||
|
||
## Enabling additional services | ||
|
||
By default, only glusterd will be enabled. To enable other services, set the following env variables to `yes`. | ||
|
||
* `ENABLE_NTPD` | ||
* `ENABLE_SSHD` | ||
* `ENABLE_RPCBIND` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/bash | ||
#!/bin/bash -e | ||
|
||
### | ||
# Description: Script to move the glusterfs initial setup to bind mounted directories of Atomic Host. | ||
|
@@ -12,58 +12,60 @@ | |
# cases as published by the Free Software Foundation. | ||
### | ||
|
||
DIRS_TO_RESTORE="/etc/glusterfs /var/log/glusterfs /var/lib/glusterd" | ||
FSTAB=${FSTAB-/var/lib/heketi/fstab} | ||
ENABLE_NTPD="${ENABLE_NTPD-yes}" | ||
ENABLE_SSHD="${ENABLE_SSHD-no}" | ||
ENABLE_RPCBIND="${ENABLE_RPCBIND-yes}" | ||
|
||
err() { | ||
echo -ne $* 1>&2 | ||
} | ||
|
||
enable_start_unit_if_env() { | ||
local unit="$1" | ||
local env_var="$1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be $2, let me know if I am wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course! |
||
case ${env_var,,} in | ||
yes|y|true|t) | ||
echo "Enable and start $unit" | ||
systemctl enable $unit | ||
systemctl start $unit | ||
;; | ||
esac | ||
} | ||
|
||
main () { | ||
if test "$(ls /var/lib/heketi/fstab)" | ||
if [ -f "$FSTAB" ] | ||
then | ||
mount -a --fstab /var/lib/heketi/fstab | ||
if [ $? -eq 1 ] | ||
then | ||
echo "mount failed" | ||
exit 1 | ||
fi | ||
echo "Mount Successful" | ||
if ! mount -a --fstab "$FSTAB" | ||
then | ||
err "mount failed" | ||
exit 1 | ||
fi | ||
echo "Mount Successful" | ||
else | ||
echo "heketi-fstab not found" | ||
echo "fstab file $FSTAB not found" | ||
fi | ||
DIR_1="/etc/glusterfs" | ||
DIR_2="/var/log/glusterfs" | ||
DIR_3="/var/lib/glusterd" | ||
var=0 | ||
for i in $DIR_1 $DIR_2 $DIR_3 | ||
|
||
for dir in $DIRS_TO_RESTORE | ||
do | ||
if test "$(ls $i)" | ||
if test "$(ls $dir)" | ||
then | ||
echo "$i is not empty" | ||
var=$((var+1)) | ||
echo "$dir is not empty" | ||
else | ||
if ! cp -r ${dir}_bkp/* $dir | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel we should copy only if all the directory in the list are empty. Say if they miss a volume -v /var/lib/glusterd:/var/lib/glusterd:z, In this case it will copy the default options and start the container which is not IMO is persisting the state of container. I feel It should fail in these cases and let the user notified that failed due to this directory. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree. |
||
then | ||
err "Failed to copy $dir" | ||
exit 1 | ||
fi | ||
fi | ||
done | ||
|
||
if [ $var -eq 3 ] | ||
then | ||
exit 1 | ||
fi | ||
|
||
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 | ||
enable_start_unit_if_env rpcbind.service "$ENABLE_RPCBIND" | ||
enable_start_unit_if_env ntpd.service "$ENABLE_NTPD" | ||
enable_start_unit_if_env sshd.service "$ENABLE_SSHD" | ||
|
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add
yum --setopt=tsflags=nodocs -y update
? @humblec what do you think will we need this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT there is no consensus re
yum update
within Dockerfiles. (See e.g. this discussion). I tend not to include them if the base image gets updated regularly. I rely on my build triggers in that case. Note that if the image is not updated, you still have to make sure to rebuild the image. And how should you know you'll have to do that :/.The advantage of not using
yum update
is reproducibility.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. So we will depend on the image rebuilds and trigger accordingly. BTW link"this discussion" points to 404 page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never get the github issue links right. corrected above.