Deploy a service¶
As with other deployment tasks, do the setup tasks before (and the cleanup tasks after) the steps below. If you run into trouble, read the Troubleshoot guide.
1. Run Salt function¶
To deploy a service, indicate the desired target and the state.apply
function, for example:
./run.py 'docs' state.apply
To limit the output to changes and failures, add a --state-output=changes option
, for example:
./run.py --state-output=changes option 'docs' state.apply
To run a specific state file, run, for example:
./run.py 'docs' state.sls elasticsearch
To run a specific SLS ID, run, for example:
./run.py '*' state.sls_id root_authorized_keys core.sshd
If the output has an error of Unable to detect Python-2 version
, you don’t have Python 2.7 in your PATH. To fix this, if you use pyenv
, run, for example:
pyenv shell system
The state.apply
function often completes within one minute. You can ignore this warning: DeprecationWarning: encoding is deprecated, Use raw=False instead
.
Note
If you want to check whether a deployment is simply slow (frequent) or actually stalled (rare), watch Salt’s activity.
2. Check Salt output¶
Look for these lines at the end of the output in the primary terminal:
Summary for docs
-------------
Succeeded: ## (changed=#)
Failed: 0
Then:
- Check that the app is still responding in your web browser.
- If there are any failed states, look for each in the output (red text) (or search for
Result: False
) and debug. - If there are any changed states, look for each in the output (blue text) (or grep for
Changes: \n[^\n-]
) and verify the changes.
Common changed states are:
- Function: service.running, ID: apache2
- Apache was reloaded
For a Django app, common changed states are:
- Function: git.latest
- A new commit was deployed
- Function: cmd.run, Name: . .ve/bin/activate; pip-sync -q –pip-args “–exists-action w”
- Requirements were installed
- Function: cmd.run, Name: . .ve/bin/activate; DJANGO_SETTINGS_MODULE=… python manage.py migrate –noinput
- Django migrations were applied
- Function: cmd.run, Name: . .ve/bin/activate; DJANGO_SETTINGS_MODULE=… python manage.py compilemessages
- Message catalogs were compiled
- Function: cmd.run, Name: . .ve/bin/activate; DJANGO_SETTINGS_MODULE=… python manage.py collectstatic –noinput
- Static files were collected
- Function: service.running, ID: uwsgi
- uWSGI was reloaded
States that always report changes:
- cmd.run, unless
onchanges
is specified - pip.installed, if
upgrade
is set postgres_privileges.present
, ifobject_name
isALL
3. Manual cleanup¶
If you changed the server name of a virtual host that uses HTTPS, you will need to Acquire SSL certificates for the new server name.
If you removed a Salt configuration, follow the linked steps to cleanup manually.