Ansible supervisorctl,状态'restarted'和'present'之间的区别

Ansible supervisorctl, difference between state 'restarted' and 'present'

我正在将 Django 应用程序部署到生产环境和暂存环境(碰巧在同一台服务器上)。为了做到这一点,我 运行 supervisord 为两种环境使用了两个不同的过程。

因此在我的 ansible-playbook 中,我模板化了我的 uwsgi 配置(根据环境变量)并将其复制到 /etc/supervisor/conf.d 文件夹。

假设我想第一次部署到新的暂存环境。由于没有任何配置文件,我需要 supervisorctl rereadsupervisorctl update.

正如我从 docs 中读到的那样:

When state = present, the module will call supervisorctl reread then supervisorctl add if the program/group does not exist.

When state = restarted, the module will call supervisorctl update then call supervisorctl restart.

但这是否意味着如果我想同时支持新的登台实例和我当前的登台实例,我需要同时调用它们?或者只使用 state=restarted 就足够了吗?还是我做错了什么?

这段代码可以吗?还是重复了一些信息?

    - name: Add uwsgi app (reread + add)
      become: yes
      supervisorctl: name={{uwsgi_app}} state=present

    - name: Start uwsgi app (update + restart)
      become: yes
      supervisorctl: name={{uwsgi_app}} state=restarted

您需要同时调用两者或在您的应用程序配置文件中设置(您在 /etc/supervisor/conf.d 中设置的那个)for the application to start automatically 添加一行:

autostart: true

虽然默认情况下是正确的,但我更愿意明确。