Skip to content

Commit

Permalink
Adapted shell scripts to eskimo shell code standards
Browse files Browse the repository at this point in the history
  • Loading branch information
eskimo committed Feb 9, 2023
1 parent c211402 commit ef4c747
Show file tree
Hide file tree
Showing 87 changed files with 384 additions and 489 deletions.
2 changes: 1 addition & 1 deletion services_setup/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ are searched, respectively injected, in the text stream:
* `CONTEXT_PATH` will be resolved by the context root at which the eskimo web application is deployed, such as for
instance `eskimo`
* `PREFIX_PATH` will be resolved by the specific context path of the service web console context, such as for instance
for kibana `{CONTEXT_PATH}/kibana`, e.g. `eskimo/kibana` or `kibana` if no context root is used.
for kibana `\{CONTEXT_PATH\}/kibana`, e.g. `eskimo/kibana` or `kibana` if no context root is used.
* `APP_ROOT_URL` will be resolved to the full URL used to reach eskimo, e.g. `http://localhost:9191/eskimo`


Expand Down
4 changes: 2 additions & 2 deletions services_setup/base-eskimo/containerWatchDog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ while true; do

sleep 10

if [[ `ps -o pid= -p $BACKGROUND_PID 2>>$LOG_FILE` == "" ]]; then
if [[ $(ps -o pid= -p $BACKGROUND_PID 2>>$LOG_FILE) == "" ]]; then

echo "$(date +'%Y-%m-%d %H:%M:%S') - Process with PID $BACKGROUND_PID could not be found Killing $MAIN_PID" \
>> $LOG_FILE
Expand All @@ -112,7 +112,7 @@ while true; do
break
fi

if [[ `ps -o pid= -p $MAIN_PID 2>>$LOG_FILE` == "" ]]; then
if [[ $(ps -o pid= -p $MAIN_PID 2>>$LOG_FILE) == "" ]]; then

echo "$(date +'%Y-%m-%d %H:%M:%S') - Process with PID $MAIN_PID could not be found Killing $BACKGROUND_PID" \
>> $LOG_FILE
Expand Down
14 changes: 9 additions & 5 deletions services_setup/base-eskimo/eskimo-kube-exec
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ parse_cli_docker_volume_mounts \
"$@"

# Add standard folders if not already part of it
if [[ `echo $DOCKER_VOLUMES_ARGS | grep /var/log` == "" ]]; then
if [[ $(echo $DOCKER_VOLUMES_ARGS | grep /var/log) == "" ]]; then
export DOCKER_VOLUMES_ARGS=" -v /var/log:/var/log:shared $DOCKER_VOLUMES_ARGS"
fi
if [[ `echo $DOCKER_VOLUMES_ARGS | grep /home/eskimo` == "" ]]; then
if [[ $(echo $DOCKER_VOLUMES_ARGS | grep /home/eskimo) == "" ]]; then
export DOCKER_VOLUMES_ARGS=" -v /home/eskimo:/home/eskimo:shared $DOCKER_VOLUMES_ARGS"
fi

Expand All @@ -65,11 +65,15 @@ if [[ $? != 0 ]]; then
exit 21
fi

KUBE_SERVICES_HOSTS_FILE=`create_kube_services_hosts_file`
if [[ ! -f $KUBE_SERVICES_HOSTS_FILE ]]; then
echo "Fail to create 'Kube services host file' with create_kube_services_hosts_file"
KUBE_SERVICES_HOSTS_FILE=$(create_kube_services_hosts_file)
if [[ $? == 0 ]]; then
echo "Failed to list kube services and create host file"
exit 1
fi
if [[ ! -f $KUBE_SERVICES_HOSTS_FILE ]]; then
echo "Failed to create 'Kube services host file' with create_kube_services_hosts_file"
exit 2
fi

# Finding out if we have y TTY here
tty -s && USE_TTY="-t"
Expand Down
20 changes: 10 additions & 10 deletions services_setup/base-eskimo/eskimo-kubectl
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ function call-kubectl () {
# all args as "$@"
tmpfile=$(mktemp /tmp/kube-ctl-error-logs.XXXXXX)

for i in `seq 1 4`; do
for i in $(seq 1 4); do

result=`kubectl "$@" 2> $tmpfile`
result=$(kubectl "$@" 2> $tmpfile)
retCode=$?

if [[ $retCode == 0 ]]; then
Expand All @@ -93,7 +93,7 @@ function call-kubectl () {
return 0
fi

if [[ $(cat $tmpfile | grep "did you specify the right host or port") != "" && $i -lt 4 ]]; then
if [[ $(grep -F "did you specify the right host or port" $tmpfile) != "" && $i -lt 4 ]]; then
# kube-api is not answering, retry in 4 seconds
sleep 4
else
Expand Down Expand Up @@ -130,7 +130,7 @@ function get_multiple_service_pod() {
NODE=$2

export IS_MULTIPLE=
if [[ `echo "$MULTIPLE_SERVICES_NAMES" | grep $SERVICE` ]]; then
if [[ $(echo "$MULTIPLE_SERVICES_NAMES" | grep $SERVICE) ]]; then
export IS_MULTIPLE=true
fi

Expand All @@ -139,7 +139,7 @@ function get_multiple_service_pod() {
exit 3
fi

CANDIDATES=`echo "$MULTIPLE_SERVICES_PODS" | grep $SERVICE`
CANDIDATES=$(echo "$MULTIPLE_SERVICES_PODS" | grep $SERVICE)
IFS=$'\n'
for pod in $(call-kubectl get pods --all-namespaces -o custom-columns=NAME:metadata.name,NODE:status.hostIP); do
for candidate in $(echo "$CANDIDATES"); do
Expand Down Expand Up @@ -186,7 +186,7 @@ function get_pod() {
POD=$(echo "$SINGLE_SERVICES_PODS" | grep $SERVICE)
fi

if [[ "$POD" == "" || `echo $POD | grep "ERROR"` != "" ]]; then
if [[ "$POD" == "" || $(echo $POD | grep "ERROR") != "" ]]; then
echo "ERROR: Failed to get pod for $SERVICE on $NODE"
echo "$POD"
exit 3
Expand Down Expand Up @@ -229,7 +229,7 @@ function show_log() {

echo " - Showing logs for Service $SERVICE on $NODE"

POD=`get_pod $SERVICE $NODE`
POD=$(get_pod $SERVICE $NODE)
if [[ $POD == "" || $(echo $POD | grep "ERROR") != "" ]]; then
echo "ERROR: Couldn't get POD"
echo "$POD"
Expand All @@ -238,7 +238,7 @@ function show_log() {

echo " + POD is $POD"

NAMESPACE=`get_namespace $POD`
NAMESPACE=$(get_namespace $POD)
if [[ $NAMESPACE == "" || $(echo $NAMESPACE | grep "ERROR") != "" ]]; then
echo "ERROR: Couldn't get NAMESPACE"
echo "$NAMESPACE"
Expand Down Expand Up @@ -318,7 +318,7 @@ function stop_service() {
IS_MULTIPLE=true
fi

POD=`get_pod $SERVICE $NODE`
POD=$(get_pod $SERVICE $NODE)
if [[ $POD == "" || $(echo $POD | grep "ERROR") != "" ]]; then
echo "ERROR: Couldn't get POD"
echo "$POD"
Expand All @@ -327,7 +327,7 @@ function stop_service() {

echo " + POD is $POD"

NAMESPACE=`get_namespace $POD`
NAMESPACE=$(get_namespace $POD)
if [[ $NAMESPACE == "" || $(echo $NAMESPACE | grep "ERROR") != "" ]]; then
echo "ERROR: Couldn't get NAMESPACE"
echo "$NAMESPACE"
Expand Down
31 changes: 25 additions & 6 deletions services_setup/base-eskimo/eskimo-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ take_global_lock() {
return 1
fi

take_lock $1 $2 $3 || (echo "Couldn't flock file handle - $1 $2 $3" && exit 4)
take_lock $1 $2 $3 || (echo "Couldn't flock file handle - $1 $2 $3" && return 4)

export GLOBAL_LOCK=$LAST_LOCK_HANDLE

Expand All @@ -150,6 +150,14 @@ get_kube_domain_names() {
PATH=$PATH:/usr/local/bin
fi
local DOMAIN_NAMES=" "

# ensuring access to kube
kubectl get cm coredns -n kube-system > /dev/null 2>&1
if [[ $? != 0 ]]; then
echo "Access to kube failed. Do you have proper kube credentials ?"
return 1
fi

for i in $(kubectl get cm coredns -n kube-system -o jsonpath="{.data.Corefile}" | grep ".local "); do
if [[ "$i" != "{" ]]; then
DOMAIN_NAMES="$i $DOMAIN_NAMES "
Expand All @@ -176,7 +184,7 @@ __get_kube_service_IP() {
PATH=$PATH:/usr/local/bin
fi

if [[ `echo $1 | grep '.'` == "" ]]; then
if [[ $(echo $1 | grep '.') == "" ]]; then
echo "Expecting service in format NAME.NAMESPACE"
return 1
fi
Expand Down Expand Up @@ -222,7 +230,12 @@ __dump_service_ip_dns() {
fi

if [[ "$ESKIMO_DOMAINS" == "" ]]; then
local ESKIMO_DOMAINS=$(get_kube_domain_names)
local ESKIMO_DOMAINS
ESKIMO_DOMAINS=$(get_kube_domain_names)
if [[ $? != 0 ]]; then
echo "Fail to access kube domain"
return 5
fi
fi

for eskimo_domain in $(echo $ESKIMO_DOMAINS); do
Expand All @@ -245,7 +258,13 @@ get_kube_services_IPs() {
unset gks_format
fi

local ESKIMO_DOMAINS=$(get_kube_domain_names)
ESKIMO_DOMAINS=$(get_kube_domain_names)
if [[ $? != 0 ]]; then
echo "Fail to get kube domains list"
return 5
fi
# Need to export that one to make it available to further calls
export ESKIMO_DOMAINS

local KUBE_SERVICES
KUBE_SERVICES=$(get_kube_services)
Expand All @@ -254,7 +273,7 @@ get_kube_services_IPs() {
return 1
fi
for service in $KUBE_SERVICES; do
if [[ $(echo $service | sed 's/ *$//g') != "" ]]; then
if [[ ${service/ *$//} != "" ]]; then

local SERVICE=$(echo $service | cut -d '.' -f 1)
local NAMESPACE=$(echo $service | cut -d '.' -f 2)
Expand All @@ -265,7 +284,7 @@ get_kube_services_IPs() {
HOST=$(echo $endpoint | cut -d '/' -f 1)
IP=$(echo $endpoint | cut -d '/' -f 2)

if [[ $(echo $HOST | sed 's/ *$//g') == "" ]]; then
if [[ ${HOST/ *$//} == "" ]]; then
__dump_service_ip_dns $SERVICE:$NAMESPACE:$IP $gks_format
else
type=many
Expand Down
16 changes: 8 additions & 8 deletions services_setup/base-eskimo/glusterMountChecker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ if command -v docker &> /dev/null ; then
echo "$(date +'%Y-%m-%d %H:%M:%S') - Checking whether gluster container is running" \
>> /var/log/gluster/gluster-mount-checker.log

if [[ `docker ps --filter "name=gluster" | grep -v CREATED` == "" ]]; then
if [[ $(docker ps --filter "name=gluster" | grep -v CREATED) == "" ]]; then
echo "$(date +'%Y-%m-%d %H:%M:%S') - gluster container is NOT running. Skipping ..." \
>> /var/log/gluster/gluster-mount-checker.log
exit 0
fi
fi


for MOUNT_POINT in `cat /etc/fstab | grep glusterfs | cut -d ' ' -f 2`; do
for MOUNT_POINT in $(cat /etc/fstab | grep glusterfs | cut -d ' ' -f 2); do

VOLUME=`cat /etc/fstab | grep glusterfs | grep $MOUNT_POINT | cut -d ' ' -f 1 | cut -d '/' -f 2 `
VOLUME=$(cat /etc/fstab | grep glusterfs | grep $MOUNT_POINT | cut -d ' ' -f 1 | cut -d '/' -f 2)

echo "$(date +'%Y-%m-%d %H:%M:%S') - Handling $VOLUME" \
>> /var/log/gluster/gluster-mount-checker.log
Expand All @@ -82,17 +82,17 @@ for MOUNT_POINT in `cat /etc/fstab | grep glusterfs | cut -d ' ' -f 2`; do
rm -Rf /tmp/gluster_mount_checker_error

# check if working only if it is supposed to be mounted
if [[ `grep $MOUNT_POINT /etc/mtab | grep glusterfs` != "" ]]; then
if [[ $(grep $MOUNT_POINT /etc/mtab | grep glusterfs) != "" ]]; then

# give it a try
ls -la $MOUNT_POINT >/dev/null 2>/tmp/gluster_mount_checker_error

# unmount if it's not working
if [[ $? != 0 ]]; then

if [[ `grep "Transport endpoint is not connected" /tmp/gluster_mount_checker_error` != "" \
|| `grep "Too many levels of symbolic links" /tmp/gluster_mount_checker_error` != "" \
|| `grep "No such device" /tmp/gluster_mount_checker_error` != "" ]]; then
if [[ $(grep "Transport endpoint is not connected" /tmp/gluster_mount_checker_error) != "" \
|| $(grep "Too many levels of symbolic links" /tmp/gluster_mount_checker_error) != "" \
|| $(grep "No such device" /tmp/gluster_mount_checker_error) != "" ]]; then

echo "$(date +'%Y-%m-%d %H:%M:%S') - There is an issue with $MOUNT_POINT. Unmounting" \
>> /var/log/gluster/gluster-mount-checker.log
Expand Down Expand Up @@ -123,7 +123,7 @@ for MOUNT_POINT in `cat /etc/fstab | grep glusterfs | cut -d ' ' -f 2`; do
fi

# try to mount / remount
if [[ `grep $MOUNT_POINT /etc/mtab | grep glusterfs` == "" ]]; then
if [[ $(grep $MOUNT_POINT /etc/mtab | grep glusterfs) == "" ]]; then

echo "$(date +'%Y-%m-%d %H:%M:%S') - $MOUNT_POINT is not mounted, remounting" \
>> /var/log/gluster/gluster-mount-checker.log
Expand Down
26 changes: 13 additions & 13 deletions services_setup/base-eskimo/install-eskimo-base-system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ fi

# make sure systemd is installed
echo " - checking if systemd is running"
pidof_command=`which pidof`
pidof_command=$(which pidof)
if [[ -f "/etc/debian_version" ]]; then
systemd_command=`which systemd`
if [[ ! `$pidof_command $systemd_command` ]]; then
systemd_command=$(which systemd)
if [[ ! $($pidof_command $systemd_command) ]]; then
echoerr "Systemd is not running on node !"
exit 101
fi
else
# works for both suse and RHEL
if [[ ! `$pidof_command /usr/lib/systemd/systemd` ]]; then
if [[ ! $($pidof_command /usr/lib/systemd/systemd) ]]; then
echoerr "Systemd is not running on node !"
exit 102
fi
Expand Down Expand Up @@ -305,7 +305,7 @@ function install_debian_eskimo_dependencies() {
rm -Rf /tmp/setup_log

# Extract Linux distribution
export LINUX_DISTRIBUTION=$(cat /etc/os-release | grep -e "^ID=" | cut -d '=' -f 2 | sed s/'"'//g)
export LINUX_DISTRIBUTION=$(grep -e "^ID=" /etc/os-release | cut -d '=' -f 2 | sed s/'"'//g)
echo " - Linux distribution is $LINUX_DISTRIBUTION"

if [[ "$LINUX_DISTRIBUTION" == "rhel" ]]; then
Expand Down Expand Up @@ -441,7 +441,7 @@ echo " - Enabling docker"
enable_docker

# Docker is likely running on systemd cgroup driver or cgroup2, need to bring it back to using systemd as cgroup driver
if [[ `grep native.cgroupdriver=systemd /etc/docker/daemon.json` == "" ]]; then
if [[ $(grep native.cgroupdriver=systemd /etc/docker/daemon.json) == "" ]]; then

sudo sed -i -n '1h;1!H;${;g;s/'\
'{\n'\
Expand All @@ -465,21 +465,21 @@ if [[ -d "/proc/sys/net/ipv6" ]]; then
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1 >> /tmp/setup_log 2>&1
fail_if_error $? "/tmp/setup_log" -1

for i in `/sbin/ip -o -4 address | awk '{print $2}'`; do
for i in $(/sbin/ip -o -4 address | awk '{print $2}'); do
sudo sysctl -w net.ipv6.conf.$i.disable_ipv6=1 >> /tmp/setup_log 2>&1
fail_if_error $? "/tmp/setup_log" -1
done

if [[ `grep net.ipv6.conf.all.disable_ipv6=1 /etc/sysctl.conf` == "" ]]; then
if [[ $(grep net.ipv6.conf.all.disable_ipv6=1 /etc/sysctl.conf) == "" ]]; then
sudo bash -c 'echo -e "\nnet.ipv6.conf.all.disable_ipv6=1" >> /etc/sysctl.conf'
fi

if [[ `grep net.ipv6.conf.default.disable_ipv6=1 /etc/sysctl.conf` == "" ]]; then
if [[ $(grep net.ipv6.conf.default.disable_ipv6=1 /etc/sysctl.conf) == "" ]]; then
sudo bash -c 'echo -e "net.ipv6.conf.default.disable_ipv6=1" >> /etc/sysctl.conf'
fi

for i in `/sbin/ip -o -4 address | awk '{print $2}'`; do
if [[ `grep net.ipv6.conf.$i.disable_ipv6=1 /etc/sysctl.conf` == "" ]]; then
for i in $(/sbin/ip -o -4 address | awk '{print $2}'); do
if [[ $(grep net.ipv6.conf.$i.disable_ipv6=1 /etc/sysctl.conf) == "" ]]; then
sudo bash -c "echo -e \"net.ipv6.conf.$i.disable_ipv6=1\" >> /etc/sysctl.conf"
fi
done
Expand All @@ -497,14 +497,14 @@ if [[ -f /etc/selinux/config ]]; then
sudo setenforce 0 2>/dev/null # ignoring errors
fi

if [[ `mount | grep /sys/fs/cgroup/systemd` == "" ]]; then
if [[ $(mount | grep /sys/fs/cgroup/systemd) == "" ]]; then
echo " - cgroup creation hack"
sudo mkdir /sys/fs/cgroup/systemd
sudo mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd
fi

echo " - Create group eskimoservices"
sudo /usr/bin/getent group eskimoservices 2>&1 > /dev/null || sudo /usr/sbin/groupadd eskimoservices
sudo /usr/bin/getent group eskimoservices > /dev/null 2>&1 || sudo /usr/sbin/groupadd eskimoservices

echo " - Creating common system users"

Expand Down
6 changes: 3 additions & 3 deletions services_setup/base-eskimo/install-kubernetes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ function fail_if_error(){

echo "-- INSTALLING KUBERNETES ------------------------------------------------------"

saved_dir=`pwd`
saved_dir=$(pwd)
function returned_to_saved_dir() {
cd $saved_dir
cd $saved_dir || return
}
trap returned_to_saved_dir 15
trap returned_to_saved_dir EXIT
Expand Down Expand Up @@ -165,7 +165,7 @@ fi

if [[ -z $TEST_MODE ]]; then
echo " - Create / update eskimo K8S version file"
sudo bash -c "echo K8S_VERSION=`find /usr/local/lib/ -mindepth 1 -maxdepth 1 ! -type l | grep \"k8s-*.*\" | cut -d '-' -f 2` > /etc/eskimo_k8s_environment"
sudo bash -c "echo K8S_VERSION=$(find /usr/local/lib/ -mindepth 1 -maxdepth 1 ! -type l | grep 'k8s-*.*' | cut -d '-' -f 2) > /etc/eskimo_k8s_environment"

echo " - Checking eskimo K8S version file"
if [[ ! -f /etc/eskimo_k8s_environment ]]; then
Expand Down
1 change: 1 addition & 0 deletions services_setup/base-eskimo/kube_do
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ fi
sudo -E /bin/bash /usr/local/sbin/import-hosts.sh

# Run command passed in argument
# shellcheck disable=SC2068
$@
5 changes: 0 additions & 5 deletions services_setup/cerebro/inContainerSetupCerebro.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

echo "-- SETTING UP CEREBRO ----------------------------------------------------------"

echo " - Getting elasticsearch user_id"
set +e
elasticsearch_user_id=`id -u elasticsearch 2> /tmp/cerebro_install_log`
set -e

echo " - Simlinking logs to /var/log/cerebro/"
sudo rm -Rf /usr/local/lib/cerebro/logs
sudo ln -s /var/log/elasticsearch/cerebro /usr/local/lib/cerebro/logs
Expand Down
Loading

0 comments on commit ef4c747

Please sign in to comment.