diff --git a/README.md b/README.md index 29617f7..513183b 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ supervisor_programs_present: stderr_logfile_maxbytes: 0 user: vagrant numprocs: 8 - process_name: %(program_name)s-%(process_num)s + process_name: '%(program_name)s-%(process_num)s' bar: command: 'sleep 10' directory: /tmp diff --git a/Vagrantfile b/Vagrantfile index ff1df01..bed95e9 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -18,6 +18,13 @@ boxes = [ :cpu => "50", :ram => "256" }, + { + :name => "ubuntu-1604", + :box => "bento/ubuntu-16.04", + :ip => '10.0.0.13', + :cpu => "50", + :ram => "256" + }, ] Vagrant.configure("2") do |config| diff --git a/defaults/main.yml b/defaults/main.yml index 5a65ce2..3bb7a48 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -15,6 +15,8 @@ supervisor_inet_http_server_port: 9001 supervisor_inet_http_server_username: admin supervisor_inet_http_server_password: '4ubA&Et=ASPe' +supervisor_supervisord_restart_sec: 5 + supervisor_supervisord_nodaemon: false supervisor_supervisord_logfile: /var/log/supervisor/supervisord.log supervisor_supervisord_pidfile: /var/run/supervisord.pid diff --git a/meta/main.yml b/meta/main.yml index 1bf802b..d91fb14 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -7,10 +7,11 @@ galaxy_info: license: MIT min_ansible_version: 1.6 platforms: - - name: Ubuntu - versions: - - precise - - trusty + - name: Ubuntu + versions: + - precise + - trusty + - xenial galaxy_tags: - web - system diff --git a/tasks/configure.yml b/tasks/configure.yml index 89902a6..eaf6ab7 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -5,6 +5,7 @@ path: "{{ item }}/" register: stat_directories with_items: + - "{{ supervisor_default_file | dirname }}" - "{{ supervisor_configuration_file | dirname }}" - "{{ supervisor_unix_http_server_file | dirname }}" - "{{ supervisor_supervisord_logfile | dirname }}" @@ -28,26 +29,26 @@ - supervisor-configure-directories - supervisor-configure-directories-create -- name: configure | update configuration file - /etc/supervisor/supervisord.conf +- name: configure | update configuration file - /etc/default/supervisor template: - src: etc/supervisor/supervisord.conf.j2 - dest: "{{ supervisor_configuration_file }}" + src: "{{ supervisor_default_file.lstrip('/') }}.j2" + dest: "{{ supervisor_default_file }}" owner: "{{ supervisor_system_user }}" group: "{{ supervisor_system_group }}" - mode: 0640 + mode: 0644 notify: restart supervisor tags: - supervisor-configure-configuration - - supervisor-configure-configuration-supervisord-conf + - supervisor-configure-configuration-default-supervisor -- name: configure | update init script - /etc/init.d/supervisor +- name: configure | update configuration file - /etc/supervisor/supervisord.conf template: - src: etc/init.d/supervisor.j2 - dest: /etc/init.d/supervisor + src: "{{ supervisor_configuration_file.lstrip('/') }}.j2" + dest: "{{ supervisor_configuration_file }}" owner: "{{ supervisor_system_user }}" group: "{{ supervisor_system_group }}" - mode: 0755 + mode: 0640 notify: restart supervisor tags: - supervisor-configure-configuration - - supervisor-configure-configuration-init + - supervisor-configure-configuration-supervisord-conf diff --git a/tasks/main.yml b/tasks/main.yml index 5816cb8..c689725 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -12,6 +12,22 @@ - supervisor - supervisor-configure +- include: service-initd.yml + when: ansible_distribution_version | version_compare('15.04', '<') + tags: + - configuration + - supervisor + - supervisor-configure + - supervisor-configure-initd + +- include: service-systemd.yml + when: ansible_distribution_version | version_compare('15.04', '>=') + tags: + - configuration + - supervisor + - supervisor-configure + - supervisor-configure-systemd + - include: programs.yml tags: - configuration diff --git a/tasks/service-initd.yml b/tasks/service-initd.yml new file mode 100644 index 0000000..0998c4c --- /dev/null +++ b/tasks/service-initd.yml @@ -0,0 +1,12 @@ +# tasks file for supervisor +--- +- name: configure | initd | update script + template: + src: etc/init.d/supervisor.j2 + dest: /etc/init.d/supervisor + owner: "{{ supervisor_system_user }}" + group: "{{ supervisor_system_group }}" + mode: 0755 + notify: restart supervisor + tags: + - supervisor-service-upstart-update diff --git a/tasks/service-systemd.yml b/tasks/service-systemd.yml new file mode 100644 index 0000000..00f2d18 --- /dev/null +++ b/tasks/service-systemd.yml @@ -0,0 +1,19 @@ +# tasks file for supervisor +--- +- name: configure | systemd | update script + template: + src: templates/lib/systemd/system/supervisor.j2 + dest: /lib/systemd/system/supervisor.service + owner: "{{ supervisor_system_user }}" + group: "{{ supervisor_system_group }}" + mode: 0644 + register: _update_systemd_script + notify: restart supervisor + tags: + - supervisor-service-systemd-update + +- name: service | systemd | reload + command: systemctl daemon-reload + when: _update_systemd_script | changed + tags: + - supervisor-service-systemd-reload diff --git a/templates/etc/default/supervisor.j2 b/templates/etc/default/supervisor.j2 new file mode 100644 index 0000000..12e0695 --- /dev/null +++ b/templates/etc/default/supervisor.j2 @@ -0,0 +1,3 @@ +# {{ ansible_managed }} +# +DAEMON_OPTS="" diff --git a/templates/etc/init.d/supervisor.j2 b/templates/etc/init.d/supervisor.j2 index eaeef3d..20ace33 100644 --- a/templates/etc/init.d/supervisor.j2 +++ b/templates/etc/init.d/supervisor.j2 @@ -30,8 +30,8 @@ . /lib/lsb/init-functions PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -DAEMON=/usr/local/bin/supervisord -SUPERVISORCTL=/usr/local/bin/supervisorctl +DAEMON={{ supervisor_install_prefix }}/supervisord +SUPERVISORCTL={{ supervisor_install_prefix }}/supervisorctl NAME=supervisord DESC=supervisor @@ -39,14 +39,13 @@ test -x $DAEMON || exit 0 LOGDIR={{ supervisor_supervisord_logfile | dirname }} PIDFILE={{ supervisor_supervisord_pidfile }} -DODTIME=5 # Time to wait for the server to die, in seconds - # If this value is set too low you might not - # let some servers to die gracefully and - # 'restart' will not work +# Time to wait for the server to die, in seconds. If this value is set too low you might not let some servers to die +# gracefully and 'restart' will not work +DODTIME={{ supervisor_supervisord_restart_sec }} # Include supervisor defaults if available -if [ -f /etc/default/supervisor ] ; then - . /etc/default/supervisor +if [ -f {{ supervisor_default_file }} ] ; then + . {{ supervisor_default_file }} fi DAEMON_OPTS="-c {{ supervisor_configuration_file }} $DAEMON_OPTS" diff --git a/templates/lib/systemd/system/supervisor.j2 b/templates/lib/systemd/system/supervisor.j2 new file mode 100644 index 0000000..9e1309f --- /dev/null +++ b/templates/lib/systemd/system/supervisor.j2 @@ -0,0 +1,28 @@ +; {{ ansible_managed }} + +[Unit] +Description=Start/stop supervisor daemon and its configured subprocesses +After=network.target + +[Service] +Type=simple +EnvironmentFile={{ supervisor_default_file }} +PermissionsStartOnly=true +ExecStartPre=/usr/bin/test -x {{ supervisor_install_prefix }}/supervisord +ExecStartPre=/usr/bin/install -d \ + -o {{ supervisor_system_user }} \ + -g {{ supervisor_system_group }} \ + -m 0755 \ + {{ supervisor_supervisord_logfile | dirname }} +ExecStart={{ supervisor_install_prefix }}/supervisord -n -c {{ supervisor_configuration_file }} $DAEMON_OPTS +ExecStop={{ supervisor_install_prefix }}/supervisorctl -c {{ supervisor_configuration_file }} shutdown +KillMode=process +ExecReload={{ supervisor_install_prefix }}/supervisorctl -c {{ supervisor_configuration_file }} reload +PIDFile={{ supervisor_supervisord_pidfile }} +Restart=on-failure +RestartSec={{ supervisor_supervisord_restart_sec }}s +User={{ supervisor_system_user }} +Group={{ supervisor_system_group }} + +[Install] +WantedBy=multi-user.target diff --git a/vars/main.yml b/vars/main.yml index ac639de..d8ff066 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -2,3 +2,5 @@ --- supervisor_dependencies: - python +supervisor_install_prefix: /usr/local/bin +supervisor_default_file: /etc/default/supervisor