#!/bin/sh # # Bootstrap installer for Portworx container v3.1.6 # # Check debug opt asap opt_debug=''; opt_yes=0 echo "$@" | grep -q -- -debug if [ $? -eq 0 ]; then opt_debug='--debug' export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' set -x fi MIN_DSK_SZ=8589934592 tmpdir=${TMPDIR:-/tmp} SUDO=sudo ; [ $(id -u) -eq 0 ] && SUDO='' # Colors Cg="$(tput setaf 2 2> /dev/null)" # NORMAL (green) Cb="$(tput bold 2> /dev/null; tput setaf 4 2> /dev/null)" # NORMAL (blue) Cr="$(tput bold 2> /dev/null; tput setaf 1 2> /dev/null)" # ERROR (red) Cy="$(tput bold 2> /dev/null; tput setaf 3 2> /dev/null)" # WARN (yellow) CR="$(tput sgr0 2> /dev/null)" # RESET usage() { cat << _EOF Usage: bootstrap-px.sh [-y|-F|--upgrade] Options: -y Assume YES on all interactive prompts -F Follow/Tail Portworx install log --upgrade Upgrade the existing installation Please see https://docs.portworx.com/runc/#options Example: curl -fsSL https://get.portworx.com | sh curl -fsSL https://get.portworx.com | sh -s -- -k etcd://myetc.acme.net:2379 curl -fsSL https://get.portworx.com | sh -s -- -c MY_CLUSTER_ID -k etcd://myetc.acme.net:2379 -s /dev/xvdb -s /dev/xvdc _EOF exit 1 } fatal() { echo "" 2>&1 echo "${Cr}$@$CR" 2>&1 exit 1 } ask() { prompt=${1:-"Continue [Y|*]?"} rval=1; answ='' echo -n "$prompt " >&2 if [ $opt_yes -gt 0 ]; then rval=0; answ='YES' echo $answ >&2 else # Ask interactively read answ < /dev/tty [ $? -eq 0 ] || fatal "ERROR: Could not ask for user input - please run via interactive shell" case "$answ" in Y*|y*) rval=0 ;; esac fi return $rval } find_free_disk_devices() { scratchFile="$tmpdir/scan_devs_temp.$$" lsblk -bnpP -o NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT > "$scratchFile" rc=$? if [ $rc -ne 0 ]; then echo "ERROR: Failed to collect list of block devices" >&2 exit $rc fi disks=""; DISK="" while read line; do eval $line if [ "x$TYPE" != xdisk ]; then DISK="" # reset, cause deps found elif [ "x$FSTYPE" = x ] && [ "x$SIZE" != x ] && [ $SIZE -ge $MIN_DSK_SZ ] ; then if [ "x$DISK" != "x" ]; then disks="$disks $DISK" DISK="" fi echo "$NAME" | egrep -q "/dev/pxd/|/dev/loop" if [ $? -ne 0 ]; then DISK="$NAME" fi fi done < "$scratchFile" rm "$scratchFile" [ "x$DISK" != "x" ] && disks="$disks $DISK" echo $disks } check_cmd() { cmd=$1; shift doc=${@:-"the appropriate package"} type $cmd > /dev/null 2>&1 \ || fatal "ERROR: Command '$cmd' not found! Please install $doc" } pxopts='' xtravols='' opt_img='portworx/px-enterprise:3.1.6' opt_upgrade='' typ='OCI container' cfg=/etc/pwx/config.json follow_log=0 need_confirm=0 while [ "$1" != "" ]; do case $1 in -px|--px) opt_img="$2"; shift ;; -debug|--debug) ;; # skip, already handled -v) xtravols="$xtravols -v $2"; shift ;; -y) opt_yes=1 ;; -upgrade|--upgrade) opt_upgrade=--upgrade ;; -F|--follow) follow_log=1 ;; -h|--help) usage ;; *) pxopts="$pxopts $1" ;; esac shift done check_cmd docker "docker package (see https://docs.docker.com/install/)" if [ -f $cfg ]; then echo "${Cb}Found old configuration file at ${cfg} -- will reuse.$CR" pxoptsDisp=" (reused from $cfg file)" else # Check KVDB echo "$pxopts" | grep -qw -- -k if [ $? -ne 0 ]; then kvdb="etcd://etcdv3-01.portworx.com:2379,etcd://etcdv3-02.portworx.com:2379,etcd://etcdv3-03.portworx.com:2379" echo "${Cy}WARN: No KVDB specified via \"-k url\", will use hosted ${kvdb}.$CR" pxopts="$pxopts -k $kvdb" need_confirm=1 fi # Check storage echo "$pxopts" | egrep -qw -- "-s|-a|-A|-z" if [ $? -ne 0 ]; then free_devs=$(find_free_disk_devices) if [ $? -eq 0 ] && [ "x$free_devs" != x ]; then echo "${Cy}WARN: No storage devices specified via \"-s /dev/xxx\", will try to use unformatted drives (${free_devs}).$CR" pxopts="$pxopts -a" need_confirm=1 else fatal "ERROR: No storage devices specified via \"-s /dev/xxx\", and no free/unformatted disks found." fi fi # Check ClusterID echo "$pxopts" | grep -qw -- -c if [ $? -ne 0 ]; then cid="$(printf '%s-%x-%x\n' $(hostname --fqdn | tr . -) $(date +'%s 3%N') | tr '[:upper:]' '[:lower:]')" echo "${Cy}WARN: No ClusterID specified via \"-c ID\", will use randomized ${cid}.$CR" pxopts="$pxopts -c $cid" need_confirm=1 fi # Check network echo "$pxopts" | egrep -qw -- "-d|-m" if [ $? -ne 0 ]; then ip route | grep -q 'default via 10.0.2.2' \ && echo "${Cy}WARN: Possible Vagrant VM network detected! You might need to use NIC#2 network interface via (e.g. '-d eth1 -m eth1').$CR" fi fi xtravolsDisp=${xtravols:- (none)} pxoptsDisp=${pxoptsDisp:-$pxopts} cat << _EOM ${Cg}Will install Portworx as $typ using following options:$CR Portworx image: ${Cb}$opt_img$CR Install options:${Cb}$pxoptsDisp$CR Extra mounts: ${Cb}$xtravolsDisp$CR _EOM if [ $need_confirm -gt 0 ]; then echo ask || fatal "aborted." elif [ $opt_yes -le 0 ]; then sleep 5 fi check_cmd systemctl "systemd package" echo "${Cg}Step 1/5 : Stopping/Disabling old Portworx containers ...$CR" x=$($SUDO /bin/sh -c "docker rm -f portworx; systemctl stop portworx; systemctl disable portworx" 2>&1) echo "${Cg}Step 2/5 : Downloading Portworx OCI ...$CR" $SUDO docker pull "$opt_img" \ || fatal "Error downloading Portworx OCI!" echo "${Cg}Step 3/5 : Installing Portworx OCI files ...$CR" $SUDO docker run --entrypoint /runc-entry-point.sh --rm --privileged=true \ -v /opt/pwx:/opt/pwx -v /etc/pwx:/etc/pwx $opt_img $opt_debug $opt_upgrade \ || fatal "Error installing Portworx OCI Container files!" echo "${Cg}Step 4/5 : Configuring Portworx OCI ...$CR" $SUDO /opt/pwx/bin/px-runc install $xtravols $pxopts \ || fatal "Error configuring Portworx OCI Container!" echo "${Cg}Step 5/5 : Enabling/Restarting Portworx OCI service ...$CR" $SUDO systemctl daemon-reload $SUDO /bin/sh -c "systemctl enable portworx && systemctl restart portworx" \ || fatal "Error enabling/[re]starting Portworx OCI service!" echo "${Cg}Successfully installed Portworx $typ.$CR" if [ $follow_log -gt 0 ]; then tailCmd="journalctl -fu portworx" echo "" echo "${Cy}WARN : Install DONE, running '$tailCmd' to follow PX-logs (press CTRL-C to abort) ...$CR" echo "" exec $tailCmd fi