#!/bin/bash # sl_initmongo.sh # Initialize both CG and MongoDB server instance on this host. # # Usage: <> # sl_initmongo.sh # # This will check and correct permissions, and will overwrite or # destroy existing keys, uuid's, etc. # Requires: # No Tomcat requirements in MongoDB setup # What this does: # . Verifies environment; if something is mis-configured, exits # * You must have a running mongod and valid /etc/mongod.conf file # . Generates a 36 character UUID and writes the value to # $SEQUENCELOGICHOME/cg/public/uuid.txt # If the file already exists, requires confirmation to overwrite # . Creates a public/private key pair for the localhost # H1) Places private key into $SEQUENCELOGICHOME/cg/private/cg-{uuid}.pem # H2) Places public key into $SEQUENCELOGICHOME/cg/public/cg-{uuid}.pem # . Configures database if necessary # . Creates the 000000 VAN # NOTE - when initializing a MongoDB contained in a replica set, # initialize the DB only once, on the primary. # setup SCRIPT=$0 echo "[OK] Script: ${SCRIPT}" # Absolute path this script is in, thus /home/user/bin SCRIPTPATH=`dirname ${SCRIPT}` echo "[OK] This script is located at: $SCRIPTPATH" # Source the mongo helpers script. It performs mongo-set specific required "helping" source ${SCRIPTPATH}/sl_mongohelp.sh # need to be root isUser root if [ $? = 0 ]; then echo "[ERROR] You must be root to run this script" exit 1; fi # env #verifyEnvironment; # CG public/private keys if [ ! -f "${SEQUENCELOGICHOME}/cg/public/cg-public.pem" ]; then # This server createKeys private/cg-private.pem public/cg-public.pem rm ${SEQUENCELOGICHOME}/cg/private/cloudguard-keyring.iks rm ${SEQUENCELOGICHOME}/cg/private/cloudguard-keyring.iks.public else echo "[OK] Using existing server keys; server public: " cat ${SEQUENCELOGICHOME}/cg/public/cg-public.pem fi # Check that mongo is working MPID=`ps auxwww | grep mongod | grep "$MONGO_CONFIG" | grep -v grep` if [ "$MPID" = "" ]; then echo "[ERROR] Unable to detect running mongod process using config file: ${MONGO_CONFIG}" #exit 2; fi # create DB (just adds a row to the dummy "initialized" collection) now=`date '+%Y%m%dT%H:%M:%S'` mongoPutDoc initialized "$now" "{_id:\"${now}\", initialized:true}" ### DEFAULT VAN/PMO VANUUID=000000 if [ ! -f $SEQUENCELOGICHOME/cg/public/vanpub-${VANUUID}.pem ]; then createKeys private/van-${VANUUID}.pem public/vanpub-${VANUUID}.pem fi # ... remainder "destroys" existing values but that's OK # create VAN vanname="SEQUENCELOGIC VAN" vanid="urn:sl:${VANUUID}:::" #vantp=`getTtyInput "" "VAN token passphrase?" "echo"` #vansp=`getTtyInput "" "VANstatus passphrase?" "echo"` #suggest=`hostname | sed 's/[.].*$//'` #vanalias=`getTtyInput "" "VAN alias (suggest you use: ${suggest})?" "echo"` vantp="madman12" vansp="madman12" vanalias="sleds" vandoc="{_id:\"${vanid}\", name:\"${vanname}\", activationBypassCode:\"NickiLovesMariah\", alias:\"${vanalias}\", statusPassphrase:\"${vansp}\", tokenPassphrase:\"${vantp}\"}" mongoPutDoc van "${vanid}" "${vandoc}" #Now fetch any needed system variables SEQUENCE_LOGIC_ENV = facter --external-dir=/etc/facter/facts.d sequence_logic_env source /sl/scat/sl_setvanpolicy.sh ${vanid} source /sl/scat/sl_setvanquota.sh ${vanid} source /sl/scat/sl_setteams.sh ${VANUUID} CTRLDOC="{_id:\"scat-0\", recipe:\"mongo\", flavor:\"instance\", van:\"${VANID}\", device:\"0001\", status:\"enabled\"}" # No mongo! mongoPutDoc scat_control "scat-0" "$CTRLDOC" CTRLDOC="{_id:\"scat-1\", recipe:\"k2daemon\", flavor:\"instance\", van:\"${VANID}\", device:\"0001\", status:\"enabled\"}" mongoPutDoc scat_control "scat-1" "$CTRLDOC" CTRLDOC="{_id:\"scat-2\", recipe:\"tomcat\", flavor:\"all\", van:\"${VANID}\", device:\"0001\", status:\"enabled\"}" mongoPutDoc scat_control "scat-2" "$CTRLDOC" CTRLDOC="{_id:\"scat-3\", recipe:\"robot-infrastructure\", flavor:\"all\", van:\"${VANID}\", device:\"0001\", status:\"enabled\"}" mongoPutDoc scat_control "scat-3" "$CTRLDOC" CTRLDOC="{_id:\"scat-4\", recipe:\"robot-workflow\", flavor:\"ingest\", van:\"${VANID}\", device:\"0001\", status:\"enabled\"}" mongoPutDoc scat_control "scat-4" "$CTRLDOC" CTRLDOC="{_id:\"scat-5\", recipe:\"robot-workflow\", flavor:\"ocr\", van:\"${VANID}\", device:\"0001\", status:\"enabled\"}" mongoPutDoc scat_control "scat-5" "$CTRLDOC" CTRLDOC="{_id:\"scat-6\", recipe:\"robot-workflow\", flavor:\"classification\", van:\"${VANID}\", device:\"0001\", status:\"enabled\"}" mongoPutDoc scat_control "scat-6" "$CTRLDOC" CTRLDOC="{_id:\"scat-7\", recipe:\"k2proxy\", flavor:\"instance\", van:\"${VANID}\", device:\"0001\", status:\"enabled\"}" mongoPutDoc scat_control "scat-7" "$CTRLDOC" echo "[OK] sequencelogic/van database contains:" mongoExec "db.van.find()" echo # applies to all user/office creation below export PMOPREFS="{\"avatar\":\"\",\"sharePhone\":true,\"shareEmail\":true,\"shareAvatar\":true,\"shareUsername\":true,\"shareFullname\":true,\"searchUsername\":true,\"searchPhone\":true,\"searchEmail\":true,\"receiveOptInNews\":true,\"msgDR\":true,\"msgRR\":true,\"msgTBR\":true,\"msgTTL\":3600, \"EST\":true}" # Lastly, make sure sequencelogic owns everything... # not needed - chown -R sequencelogic:sequencelogic ${SEQUENCELOGICHOME}/* exit 0