diff --git a/parse_server/defaults/main.yml b/parse_server/defaults/main.yml index f502ab50..8b4a4ab5 100644 --- a/parse_server/defaults/main.yml +++ b/parse_server/defaults/main.yml @@ -1,6 +1,8 @@ --- parse_server_user: parsesrv parse_server_user_home: /srv/parse +parse_server_config_dir: '{{ parse_server_user_home }}/config' +parse_server_logs_dir: '{{ parse_server_user_home }}/logs' parse_server_npm_modules: - parse-server - pm2 @@ -8,7 +10,10 @@ parse_server_npm_modules: parse_server_http_port: 1337 parse_server_db: parse_db parse_server_mongodb_uri: 'mongodb://localhost:27017/{{ parse_server_db }}' - +parse_server_verbose_mode: 0 +# VERBOSE, INFO, ERROR, NONE +parse_server_log_level: ERROR +parse_server_json_logs: 0 parse_server_app_id: 'foo' #parse_server_master_key: 'use a vault file' parse_server_app_name: '{{ parse_server_app_id }}' diff --git a/parse_server/tasks/main.yml b/parse_server/tasks/main.yml index 0accb629..4111ede8 100644 --- a/parse_server/tasks/main.yml +++ b/parse_server/tasks/main.yml @@ -6,10 +6,16 @@ - name: Create the parse home directory file: dest={{ parse_server_user_home }} owner={{ parse_server_user }} group={{ parse_server_user }} mode=0755 state=directory + - name: Create the parse config directory + file: dest={{ parse_server_config_dir }} owner={{ parse_server_user }} group={{ parse_server_user }} mode=0750 state=directory + - name: Install the parse server npm: name={{ item }} global=yes state=present production=true with_items: '{{ parse_server_npm_modules }}' + - name: Install the parse server environment file + template: src=parse-server.env dest={{ parse_server_config_dir }}/parse-server.env owner={{ parse_server_user }} group={{ parse_server_user }} mode=0640 + - name: Install the parse server startup script template: src=parse_server.upstart.j2 dest=/etc/init/parse_server.conf mode=0644 @@ -25,10 +31,10 @@ with_items: '{{ parse_server_dashboard_npm_modules }}' - name: Install the parse dashboard environment variables file - template: src=parse-server-dashboard dest=/etc/default/parse-server-dashboard + template: src=parse-server-dashboard.env dest={{ parse_server_config_dir }}/parse-server-dashboard.env owner={{ parse_server_user }} group={{ parse_server_user }} mode=0640 - name: Install the parse dashboard configuration file - template: src=parse-dashboard-config.json dest={{ parse_server_user_home }}/parse-dashboard-config.json + template: src=parse-dashboard-config.json dest={{ parse_server_config_dir }}/parse-dashboard-config.json owner={{ parse_server_user }} group={{ parse_server_user }} mode=0640 - name: Install the parse dashboard startup script template: src=parse_server_dashboard.upstart.j2 dest=/etc/init/parse_server_dashboard.conf mode=0644 diff --git a/parse_server/templates/parse-server-dashboard b/parse_server/templates/parse-server-dashboard.env similarity index 100% rename from parse_server/templates/parse-server-dashboard rename to parse_server/templates/parse-server-dashboard.env diff --git a/parse_server/templates/parse-server.env b/parse_server/templates/parse-server.env new file mode 100644 index 00000000..28b04137 --- /dev/null +++ b/parse_server/templates/parse-server.env @@ -0,0 +1,7 @@ +export MASTER_KEY='{{ parse_server_master_key }}' +export APPLICATION_ID='{{ parse_server_app_id }}' +export LOG_LEVEL='{{ parse_server_log_level }}' +export JSON_LOGS={{ parse_server_json_logs }} +export PARSE_SERVER_LOGS_FOLDER='{{ parse_server_logs_dir }}' +export VERBOSE={{ parse_server_verbose_mode }} +export DATABASE_URI='{{ parse_server_mongodb_uri }}' diff --git a/parse_server/templates/parse_server.upstart.j2 b/parse_server/templates/parse_server.upstart.j2 index 2bf04d2e..587a3a39 100644 --- a/parse_server/templates/parse_server.upstart.j2 +++ b/parse_server/templates/parse_server.upstart.j2 @@ -8,5 +8,13 @@ setuid {{ parse_server_user }} setgid {{ parse_server_user }} script - exec /usr/bin/parse-server --appId "{{ parse_server_app_id }}" --masterKey "{{ parse_server_master_key }}" --databaseURI {{ parse_server_mongodb_uri }} + . {{ parse_server_config_dir }}/parse-server.env + export MASTER_KEY + export APPLICATION_ID + export LOG_LEVEL + export PARSE_SERVER_LOGS_FOLDER + export JSON_LOGS + export VERBOSE + export DATABASE_URI + exec /usr/bin/parse-server --appId "$APPLICATION_ID" --masterKey "$MASTER_KEY" --databaseURI $DATABASE_URI > {{ parse_server_logs_dir }}/parse_server_startup.log 2>&1 end script diff --git a/parse_server/templates/parse_server_dashboard.upstart.j2 b/parse_server/templates/parse_server_dashboard.upstart.j2 index ee79fafe..8e023cb7 100644 --- a/parse_server/templates/parse_server_dashboard.upstart.j2 +++ b/parse_server/templates/parse_server_dashboard.upstart.j2 @@ -8,8 +8,8 @@ setuid {{ parse_server_user }} setgid {{ parse_server_user }} script - . /etc/default/parse-server-dashboard + . {{ parse_server_config_dir }}/parse-server-dashboard.env export PARSE_DASHBOARD_TRUST_PROXY export MOUNT_PATH - exec /usr/bin/parse-dashboard --config parse-dashboard-config.json + exec /usr/bin/parse-dashboard --config {{ parse_server_config_dir }}/parse-dashboard-config.json > {{ parse_server_logs_dir }}/parse_server_dashboard_startup.log 2>&1 end script