Skip to content

Commit

Permalink
feat(ansible): playbook for staring the clients
Browse files Browse the repository at this point in the history
  • Loading branch information
raisedadead committed Jul 17, 2023
1 parent 6aff628 commit 74510d5
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
owner: freecodecamp
group: freecodecamp
mode: 0644

- name: Get the Node.js version
shell:
cmd: |
Expand Down Expand Up @@ -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
Expand Down
83 changes: 83 additions & 0 deletions ansible/play-oldeworld--client-2-setup.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 74510d5

Please sign in to comment.