diff --git a/ansible/play-oldeworld--api-3-setup.yml b/ansible/play-oldeworld--api-2-setup.yml similarity index 99% rename from ansible/play-oldeworld--api-3-setup.yml rename to ansible/play-oldeworld--api-2-setup.yml index 4ad6cdd1..f739d752 100644 --- a/ansible/play-oldeworld--api-3-setup.yml +++ b/ansible/play-oldeworld--api-2-setup.yml @@ -21,6 +21,7 @@ owner: freecodecamp group: freecodecamp mode: 0644 + - name: Get the Node.js version shell: cmd: | @@ -53,6 +54,7 @@ export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" + pm2 update pm2 install pm2-logrotate sudo env PATH=$PATH:/home/freecodecamp/.nvm/versions/node/{{ node_version }}/bin /home/freecodecamp/.nvm/versions/node/{{ node_version }}/lib/node_modules/pm2/bin/pm2 startup systemd -u freecodecamp --hp /home/freecodecamp pm2 save diff --git a/ansible/play-oldeworld--client-2-setup.yml b/ansible/play-oldeworld--client-2-setup.yml new file mode 100644 index 00000000..4254f8cf --- /dev/null +++ b/ansible/play-oldeworld--client-2-setup.yml @@ -0,0 +1,83 @@ +--- +- name: Setup Olde World Cluster - API + hosts: '{{ variable_host | default("null") }}' + gather_facts: false + tasks: + - name: Clone the Git Repository + git: + name: https://github.com/freeCodeCamp/client-config.git + dest: /home/freecodecamp/client + clone: true + update: false + single_branch: true + version: master + + - name: Get the Node.js version + shell: + cmd: | + export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] + printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" + [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" + node -v + chdir: /home/freecodecamp/client + executable: /bin/bash + register: node_version_output + + - name: Set the Node.js version fact + set_fact: + node_version: '{{ node_version_output.stdout }}' + + - name: Install Global Dependencies + shell: + cmd: | + export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] + printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" + [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" + npm i -g npm + npm i -g pm2 + npm install -g serve@13 + pm2 install pm2-logrotate + chdir: /home/freecodecamp/client + executable: /bin/bash + + - name: Setup PM2 & Logrotate + shell: + cmd: | + export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] + printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" + [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" + pm2 update + pm2 install pm2-logrotate + sudo env PATH=$PATH:/home/freecodecamp/.nvm/versions/node/{{ node_version }}/bin /home/freecodecamp/.nvm/versions/node/{{ node_version }}/lib/node_modules/pm2/bin/pm2 startup systemd -u freecodecamp --hp /home/freecodecamp + pm2 save + chdir: /home/freecodecamp/client + executable: /bin/bash + register: pm2_setup_output + + - name: Start up Client services + shell: + cmd: | + export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] + printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" + [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" + echo "serve -c ../serve.json -p 50505 www" > client-start-primary.sh + chmod +x client-start-primary.sh + pm2 delete client-primary + pm2 start ./client-start-primary.sh --name client-primary + echo "serve -c ../serve.json -p 52525 www" > client-start-secondary.sh + chmod +x client-start-secondary.sh + pm2 delete client-secondary + pm2 start ./client-start-secondary.sh --name client-secondary + pm2 save + chdir: /home/freecodecamp/client + executable: /bin/bash + + - name: Save the running process + shell: + cmd: | + export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] + printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" + [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" + pm2 save + chdir: /home/freecodecamp/client + executable: /bin/bash