Skip to content

Commit

Permalink
Add ssh-agent control. Avoid halting for non-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhbramwell committed Oct 21, 2016
1 parent 99bb35a commit 72136bf
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
7 changes: 6 additions & 1 deletion habitat/scripts/PushInstallerScriptsToTarget.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,15 @@ ping -c 1 ${TARGET_SERVER} >/dev/null || errorCannotPingRemoteServer "${TARGET_S



# ----------------
echo -e "${PRTY} Start up SSH agent... [ exec ssh-agent bash; ssh-add; ]";
eval $(ssh-agent) > /dev/null;
ssh-add > /dev/null;


# ----------------
echo -e "${PRTY} Testing SSH using... [ ssh ${TARGET_USER}@${TARGET_SERVER} 'whoami'; ]";
if [[ "X${TARGET_USER}X" = "XX" ]]; then errorNoUserAccountSpecified "null"; fi;
# without problemsssh -oBatchMode=yes -l you habsrv whoami
REMOTE_USER=$(ssh -qt -oBatchMode=yes -l ${TARGET_USER} ${TARGET_SERVER} whoami) || errorCannotCallRemoteProcedure "${TARGET_USER}@${TARGET_SERVER}";
[[ 0 -lt $(echo "${REMOTE_USER}" | grep -c "${TARGET_USER}") ]] || errorUnexpectedRPCResult;

Expand Down
8 changes: 3 additions & 5 deletions habitat/scripts/target/PrepareChefHabitatTarget.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ sudo -A DEBIAN_FRONTEND=noninteractive apt-get update >> ${LOG};
sudo -A DEBIAN_FRONTEND=noninteractive apt-get install -y mongodb-org-shell=3.2.10 >> ${LOG};

echo -e "${PRTY} Purging any existing user '${HAB_USER}' . . . " | tee -a ${LOG};
sudo -A deluser --quiet --remove-home ${HAB_USER} >> ${LOG};
set +e; sudo -A deluser --quiet --remove-home ${HAB_USER} >> ${LOG}; set -e;
sudo -A rm -fr "/etc/sudoers.d/${HAB_USER}" >> ${LOG};

echo -e "${PRTY} Creating user '${HAB_USER}' . . . " | tee -a ${LOG};
Expand Down Expand Up @@ -155,17 +155,15 @@ VL_SUDO_ASK_PASS=".supwd.sh";
EXPORT_SUDO_ASK_PASS="export ${KY_SUDO_ASK_PASS}=\"\${HOME}/.ssh/${VL_SUDO_ASK_PASS}\"";
export BASH_LOGIN="${HOME}/.bash_login";
touch ${BASH_LOGIN};
CNTSAP=$(cat ${BASH_LOGIN} | grep ${KY_SUDO_ASK_PASS} | grep -c ${VL_SUDO_ASK_PASS});
cat ${BASH_LOGIN};
set +e; CNTSAP=$(cat ${BASH_LOGIN} | grep ${KY_SUDO_ASK_PASS} | grep -c ${VL_SUDO_ASK_PASS}); set -e;
if [[ "${CNTSAP}" -lt "1" ]]; then
echo ${EXPORT_SUDO_ASK_PASS} > ${BASH_LOGIN};
# else
# echo -e "Already is : $(cat ${BASH_LOGIN})";
fi;





echo -e "${PRTY} Obtaining 'hab'.";

DEST_DIR="/usr/local/bin";
Expand Down
23 changes: 12 additions & 11 deletions habitat/scripts/target/habitat_package_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,19 @@ echo -e "";
echo -e " * * * Some commands you might find you need * * * ";
echo -e " . . . . . . . . . . . . . ";
echo -e "";
echo -e " Status of services : systemctl list-unit-files --type=service | grep ${SERVICE_UID} ";
echo -e " Enable it : sudo systemctl enable ${UNIT_FILE} ";
echo -e " Disable it : sudo systemctl disable ${UNIT_FILE} ";
echo -e "# Strategic";
echo -e " It's state : systemctl list-unit-files --type=service | grep ${SERVICE_UID} ";
echo -e " Enable it : sudo systemctl enable ${UNIT_FILE} ";
echo -e " Disable it : sudo systemctl disable ${UNIT_FILE} ";
echo -e "";
echo -e " # Controlling it ";
echo -e " systemctl status ${UNIT_FILE} ";
echo -e " sudo systemctl stop ${UNIT_FILE} ";
echo -e " sudo systemctl start ${UNIT_FILE} ";
echo -e " sudo systemctl restart ${UNIT_FILE} ";

echo -e "";
echo -e " sudo journalctl -fb -u ${UNIT_FILE} ";
echo -e "# Tactical";
echo -e " systemctl status ${UNIT_FILE} ";
echo -e " sudo systemctl stop ${UNIT_FILE} ";
echo -e " sudo systemctl start ${UNIT_FILE} ";
echo -e " sudo systemctl restart ${UNIT_FILE} ";

echo -e "# Surveillance";
echo -e " sudo journalctl -fb -u ${UNIT_FILE} ";
echo -e "";
echo -e "";

Expand Down
5 changes: 5 additions & 0 deletions habitat/scripts/target/secrets.sh.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export MONGODB_PWD="coocoo4cocoa"; # The password the Meteor app will use to connect to a localhost MongoDB
export TARGET_USER_PWD="okok"; # The sudoer password for the account that will install Habitat
export HABITAT_USER_PWD="okok"; # The sudoer password to give the 'hab' user account when it is created
export HABITAT_USER_SSH_KEY_PATH="/home/you/.ssh/id_rsa.pub"; # a key to be added to the remote host authorized_keys file

0 comments on commit 72136bf

Please sign in to comment.