From 47a65b9411939a865538711157358260d33a1ccc Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 14 Jul 2016 17:04:23 +0530 Subject: [PATCH] [fix] [test] supervisor restart --- bench/config/production_setup.py | 32 ++++++++++++++++--- .../production/includes/setup_prod_env.yml | 16 ++++++---- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/bench/config/production_setup.py b/bench/config/production_setup.py index cc7d9c61..df19398e 100755 --- a/bench/config/production_setup.py +++ b/bench/config/production_setup.py @@ -95,12 +95,36 @@ def is_running_systemd(): return False def reload_supervisor(): - try: - exec_cmd('sudo supervisorctl reread') - exec_cmd('sudo supervisorctl update') + supervisorctl = find_executable('supervisorctl') + try: + # first try reread/update + exec_cmd('sudo {0} reread'.format(supervisorctl)) + exec_cmd('sudo {0} update'.format(supervisorctl)) + return except CommandFailedError: - exec_cmd('sudo supervisorctl reload') + pass + + try: + # something is wrong, so try reloading + exec_cmd('sudo {0} reload'.format(supervisorctl)) + return + except CommandFailedError: + pass + + try: + # then try restart for centos + service('supervisord', 'restart') + return + except CommandFailedError: + pass + + try: + # else try restart for ubuntu / debian + service('supervisor', 'restart') + return + except CommandFailedError: + pass def reload_nginx(): subprocess.check_output(['sudo', find_executable('nginx'), '-t']) diff --git a/playbooks/production/includes/setup_prod_env.yml b/playbooks/production/includes/setup_prod_env.yml index bbe9da21..3f2d454b 100644 --- a/playbooks/production/includes/setup_prod_env.yml +++ b/playbooks/production/includes/setup_prod_env.yml @@ -90,11 +90,6 @@ become_user: root when: ansible_distribution == 'Ubuntu' - - name: Stat supervisor.conf - stat: - path: /etc/supervisord.conf - register: supervisor_conf - - name: Check whether default supervisor.conf exists service: name: supervisord @@ -102,4 +97,13 @@ enabled: yes become: yes become_user: root - when: supervisor_conf.stat.exists + when: ansible_distribution == 'CentOS' + + - name: Check whether default supervisor.conf exists + service: + name: supervisor + state: started + enabled: yes + become: yes + become_user: root + when: ansible_distribution == 'Ubuntu'