From d54ffcf306ac8147da66a0ada9638c96d2438629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20W=C3=A4lti?= Date: Tue, 24 Jul 2018 16:23:38 +0200 Subject: [PATCH 1/2] stderr redirect to stdout log file --- defaults/main.yml | 2 ++ templates/service/upstart.conf.j2 | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index c32af6d..d053837 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -102,6 +102,8 @@ deploy_log_stdout: True deploy_log_stdout_path: "{{ deploy_dir_logs }}/stdout.log" +deploy_redirect_error_to_stdout: True + # Service ############################################### diff --git a/templates/service/upstart.conf.j2 b/templates/service/upstart.conf.j2 index b444cf6..68c6de7 100644 --- a/templates/service/upstart.conf.j2 +++ b/templates/service/upstart.conf.j2 @@ -37,4 +37,4 @@ end script {% endif %} # Execute deploy_service_start_command and log stdout -exec su -c "{{ deploy_service_start_command }} {% if deploy_log_stdout == True %}>>{{ deploy_log_stdout_path }}{% endif %}" {{ deploy_app_user }} -- --pid $PIDFILE +exec su -c "{{ deploy_service_start_command }} {% if deploy_log_stdout == True %}>>{{ deploy_log_stdout_path }}{% endif %} {% if deploy_redirect_error_to_stdout == True and deploy_log_stdout == True %}2>&1{% endif %}" {{ deploy_app_user }} -- --pid $PIDFILE From 48099784d611e34a2298ebebfdcfa5a8307ea63b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20W=C3=A4lti?= Date: Wed, 25 Jul 2018 13:10:17 +0200 Subject: [PATCH 2/2] added some more config options for the upstart script --- defaults/main.yml | 13 ++++++++++++- templates/service/upstart.conf.j2 | 16 +++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index d053837..edb0e84 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -102,7 +102,9 @@ deploy_log_stdout: True deploy_log_stdout_path: "{{ deploy_dir_logs }}/stdout.log" -deploy_redirect_error_to_stdout: True +deploy_log_stderr: True + +deploy_log_stderr_path: "{{ deploy_dir_logs }}/stderr.log" # Service ############################################### @@ -119,6 +121,15 @@ deploy_service_start_command: "bin/{{ deploy_app_name }}" # PID file location for service installation deploy_service_pidfile: "/var/run/{{ deploy_service_name }}.pid" +# If true, use deploy_service_prestop_script to run every time before the service is stopped +deploy_service_has_preststop_script: False + +# Shell script to run if deploy_service_has_prestart_script is true +deploy_service_preststop_script: "" + +# If true, service will start at boot time +deploy_start_at_boot_time: False + # Which service wrapper / systemloader you want to use # # This can be default, upstart, systemd or none diff --git a/templates/service/upstart.conf.j2 b/templates/service/upstart.conf.j2 index 68c6de7..06704f2 100644 --- a/templates/service/upstart.conf.j2 +++ b/templates/service/upstart.conf.j2 @@ -26,6 +26,13 @@ env PIDFILE={{ deploy_service_pidfile }} respawn respawn limit 3 60 +{% if deploy_start_at_boot_time == True %} +# When to start the service +start on runlevel [2345] +# When to stop the service +stop on runlevel [016] +{% endif %} + # Change directory to current version of Tankmin chdir {{ deploy_dir_app }} @@ -37,4 +44,11 @@ end script {% endif %} # Execute deploy_service_start_command and log stdout -exec su -c "{{ deploy_service_start_command }} {% if deploy_log_stdout == True %}>>{{ deploy_log_stdout_path }}{% endif %} {% if deploy_redirect_error_to_stdout == True and deploy_log_stdout == True %}2>&1{% endif %}" {{ deploy_app_user }} -- --pid $PIDFILE +exec su -c "{{ deploy_service_start_command }} {% if deploy_log_stdout == True %}1>>{{ deploy_log_stdout_path }}{% endif %} {% if deploy_log_stderr == True %}2>>{{ deploy_log_stderr_path }}{% endif %}" {{ deploy_app_user }} -- --pid $PIDFILE + +{% if deploy_service_has_prestop_script == True %} +# Pre-Stop Script +pre-stop script + {{ deploy_service_prestop_script }} +end script +{% endif %} \ No newline at end of file