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

Add ability to set working directory #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ forever_stop_on: "[!2345]"
forever_env: {}
forever_node_bin_dir: "/usr/local/bin"
forever_node_path: "/usr/local/lib/node_modules"
forever_applications: []
forever_applications: []
forever_restart: true
12 changes: 10 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@
- name: Upstart scripts for Forever managed applications
template: src=upstart.j2 dest=/etc/init/{{item.name}}.conf owner=root group=root mode=0644
with_items: forever_applications
- name: Ensure enabled Forever applications are (re)started
register: forever_upstart

- name: Ensure enabled Forever applications are restarted if changed
action: service name={{item.name}} state=restarted
with_items: forever_applications
when: (forever_restart or forever_upstart.changed) and item.enabled|default(True)

- name: Ensure enabled Forever applications are started regardless of change
action: service name={{item.name}} state=started
with_items: forever_applications
when: item.enabled|default(True)

- name: Ensure disabled Forever applications are stopped
action: service name={{item.name}} state=stopped
with_items: forever_applications
when: not item.enabled|default(True)
when: not item.enabled|default(True)
3 changes: 3 additions & 0 deletions templates/upstart.j2
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ env NODE_PATH="{{ forever_node_path }}"
env FOREVER_ROOT="{{ forever_root }}"
# The application startup Javascript file path.
env APPLICATION_PATH="{{ item.file }}"
# Working directory when started
env WORKING_PATH="{{ item.working_dir|default('/') }}"
# Process ID file path.
env PIDFILE="{{ item.pid_file|default('/var/run/%s.pid' % item.name) }}"
# Log file path.
Expand Down Expand Up @@ -60,6 +62,7 @@ PATH=$NODE_BIN_DIR:$PATH
exec forever \
-c "$COMMAND" \
--pidFile $PIDFILE \
--workingDir $WORKING_PATH \
-a \
-l $LOG \
--minUptime $MIN_UPTIME \
Expand Down