3 # Copyright (C) The Arvados Authors. All rights reserved.
5 # SPDX-License-Identifier: CC-BY-SA-3.0
10 # Helps manage the configuration in a git repository, and then deploy
11 # nodes by pushing a copy of the git repository to each node and
12 # running the provision script to do the actual installation and
19 declare CONFIG_FILE=local.params
21 # The salt template directory
22 declare CONFIG_DIR=local_config_dir
24 # The 5-character Arvados cluster id
25 # This will be populated by loadconfig()
28 # The parent domain (not including the cluster id)
29 # This will be populated by loadconfig()
32 # A bash associative array listing each node and mapping to the roles
33 # that should be provisioned on those nodes.
34 # This will be populated by loadconfig()
37 # The ssh user we'll use
38 # This will be populated by loadconfig()
41 # The git repository that we'll push to on all the nodes
42 # This will be populated by loadconfig()
52 if [[ -n "$MISSING" ]] ; then
53 echo "Some tools are missing, please make sure you have the 'git' and 'iproute2' packages installed"
62 # Synchronizes the configuration by creating a git repository on
63 # each node, pushing our branch, and updating the checkout.
65 if [[ "$NODE" != localhost ]] ; then
66 if ! ssh $DEPLOY_USER@$NODE test -d ${GITTARGET}.git ; then
68 # Initialize the git repository (1st time case). We're
69 # actually going to make two repositories here because git
70 # will complain if you try to push to a repository with a
71 # checkout. So we're going to create a "bare" repository
72 # and then clone a regular repository (with a checkout)
75 ssh $DEPLOY_USER@$NODE git init --bare ${GITTARGET}.git
76 if ! git remote add $NODE $DEPLOY_USER@$NODE:${GITTARGET}.git ; then
77 git remote set-url $NODE $DEPLOY_USER@$NODE:${GITTARGET}.git
79 git push $NODE $BRANCH
80 ssh $DEPLOY_USER@$NODE git clone ${GITTARGET}.git ${GITTARGET}
85 # Push to the bare repository on the remote node, then in the
86 # remote node repository with the checkout, pull the branch
87 # from the bare repository.
89 git push $NODE $BRANCH
90 ssh $DEPLOY_USER@$NODE "git -C ${GITTARGET} checkout ${BRANCH} && git -C ${GITTARGET} pull"
98 # Deploy a node. This runs the provision script on the node, with
99 # the appropriate roles.
101 if [[ -z "$ROLES" ]] ; then
102 echo "No roles specified for $NODE, will deploy all roles"
104 ROLES="--roles ${ROLES}"
107 logfile=deploy-${NODE}-$(date -Iseconds).log
109 if [[ "$NODE" = localhost ]] ; then
111 if [[ $(whoami) != 'root' ]] ; then
114 $SUDO ./provision.sh --config ${CONFIG_FILE} ${ROLES} 2>&1 | tee $logfile
116 ssh $DEPLOY_USER@$NODE "cd ${GITTARGET} && sudo ./provision.sh --config ${CONFIG_FILE} ${ROLES}" 2>&1 | tee $logfile
121 if [[ ! -s $CONFIG_FILE ]] ; then
122 echo "Must be run from initialized setup dir, maybe you need to 'initialize' first?"
124 source ${CONFIG_FILE}
125 GITTARGET=arvados-deploy-config-${CLUSTER}
132 if [[ -n "$subcmd" ]] ; then
137 if [[ ! -f provision.sh ]] ; then
138 echo "Must be run from arvados/tools/salt-install"
151 if [[ -z "$PARAMS" || ! -f local.params.example.$PARAMS ]] ; then
152 echo "Not found: local.params.example.$PARAMS"
153 echo "Expected one of multiple_hosts, single_host_multiple_hostnames, single_host_single_hostname"
157 if [[ -z "$SLS" || ! -d config_examples/$SLS ]] ; then
158 echo "Not found: config_examples/$SLS"
159 echo "Expected one of multi_host/aws, single_host/multiple_hostnames, single_host/single_hostname"
163 if [[ -z "$SETUPDIR" || -z "$PARAMS" || -z "$SLS" ]]; then
164 echo "installer.sh <setup dir to initialize> <params template> <config template>"
168 if [[ -n "$err" ]] ; then
172 echo "Initializing $SETUPDIR"
174 cp -r *.sh tests $SETUPDIR
176 cp local.params.example.$PARAMS $SETUPDIR/${CONFIG_FILE}
177 cp -r config_examples/$SLS $SETUPDIR/${CONFIG_DIR}
180 echo '*.log' > .gitignore
182 git add *.sh ${CONFIG_FILE} ${CONFIG_DIR} tests .gitignore
183 git commit -m"initial commit"
185 echo "setup directory initialized, now go to $SETUPDIR, edit '${CONFIG_FILE}' and '${CONFIG_DIR}' as needed, then run 'installer.sh deploy'"
196 if grep -rni 'fixme' ${CONFIG_FILE} ${CONFIG_DIR} ; then
198 echo "Some parameters still need to be updated. Please fix them and then re-run deploy."
202 BRANCH=$(git branch --show-current)
207 if ! git diff --cached --exit-code ; then
208 git commit -m"prepare for deploy"
211 if [[ -z "$NODE" ]]; then
212 for NODE in "${!NODES[@]}"
214 # First, push the git repo to each node. This also
215 # confirms that we have git and can log into each
220 for NODE in "${!NODES[@]}"
222 # Do 'database' role first,
223 if [[ "${NODES[$NODE]}" =~ database ]] ; then
224 deploynode $NODE "${NODES[$NODE]}"
229 for NODE in "${!NODES[@]}"
231 # then 'api' or 'controller' roles
232 if [[ "${NODES[$NODE]}" =~ (api|controller) ]] ; then
233 deploynode $NODE "${NODES[$NODE]}"
238 for NODE in "${!NODES[@]}"
240 # Everything else (we removed the nodes that we
241 # already deployed from the list)
242 deploynode $NODE "${NODES[$NODE]}"
245 # Just deploy the node that was supplied on the command line.
252 echo "Completed deploy, run 'installer.sh diagnostics' to verify the install"
262 if ! which arvados-client ; then
263 echo "arvados-client not found, install 'arvados-client' package with 'apt-get' or 'yum'"
267 if [[ -z "$LOCATION" ]] ; then
268 echo "Need to provide '-internal-client' or '-external-client'"
270 echo "-internal-client You are running this on the same private network as the Arvados cluster (e.g. on one of the Arvados nodes)"
271 echo "-external-client You are running this outside the private network of the Arvados cluster (e.g. your workstation)"
275 export ARVADOS_API_HOST="${CLUSTER}.${DOMAIN}:${CONTROLLER_EXT_SSL_PORT}"
276 export ARVADOS_API_TOKEN="$SYSTEM_ROOT_TOKEN"
278 arvados-client diagnostics $LOCATION
281 echo "Arvados installer"
283 echo "initialize initialize the setup directory for configuration"
284 echo "deploy deploy the configuration from the setup directory"
285 echo "diagnostics check your install using diagnostics"