Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ansible): playbook for staring the clients #553

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading