Created
September 4, 2015 17:08
-
-
Save mmarcon/932944c1fe343ae2799a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: all | |
sudo: yes | |
vars: | |
# list of apps to be managed by pm2 | |
pm2_apps: | |
- /var/apps/services/app.js | |
- /var/apps/services/otherapp.js | |
# franklinkim.nodejs | |
nodejs_version: 0.12 | |
nodejs_packages: | |
- pm2 | |
roles: | |
- franklinkim.nodejs | |
pre_tasks: | |
- name: create apps group | |
group: name=apps state=present | |
- name: create apps user | |
user: name=apps comment="Apps User" group=apps home=/var/apps | |
- name: create node apps directory | |
file: path=/var/apps state=directory owner=apps group=apps mode=0775 | |
- name: copy node app to apps directory | |
copy: src=./services dest=/var/apps owner=apps group=apps mode=0644 | |
tasks: | |
- name: install nginx | |
apt: name=nginx state=present update_cache=yes | |
notify: | |
- start nginx | |
- name: stop node apps | |
command: pm2 delete all | |
become: yes | |
become_user: apps | |
ignore_errors: yes | |
- name: start node apps | |
command: pm2 start {{ item }} | |
become: yes | |
become_user: apps | |
with_items: pm2_apps | |
- name: installing startup script | |
command: pm2 startup ubuntu -u apps | |
environment: | |
HOME: /var/apps | |
notify: | |
- start pm2 | |
handlers: | |
- name: start nginx | |
service: name=nginx state=started |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment