Juju can sanely and efficiently remove something when you no longer need it. This section looks at how to remove services, units and environments.
Once a service is no longer required it can be removed with:
juju remove-service <service-name>
This is the order of events for removing a service:
- The Juju client tells the state server that every unit (in this service) is to be destroyed.
- The state server signals to the service (charm) that it is going to be destroyed.
- The charm breaks any relations to its service by calling
- The charm calls its 'stop hook' which should:
- Stop the service
- Remove any files/configuration created during the service lifecycle
- Prepare any backup(s) of the service that are required for restore purposes.
- The service and all its units are then removed.
A service can take a while to "die", but if
juju status reveals that the
service is listed as dying, but also reports an error state, then the removed
service will not go away. See the 'Caveats' section below for how to manage services
stuck in a dying state.
Any associated instances are tagged "dirty" to ensure they will not be reused. These can then be removed manually. See the 'Removing Machines' section below.
It is possible to spin down individual units instead of the entire service:
juju remove-unit mediawiki/1
To remove multiple units:
juju remove-unit mediawiki/1 mediawiki/2 mediawiki/3 mysql/2
Note: Like service removal, unit removal will not remove corresponding machines/instances. More details can be found in the Scaling Services section.
See section 'Caveats' below for how to manage units in a dying state.
Machines (instances) can be removed like this:
juju remove-machine <number>
However, it is not possible to remove an instance which is currently allocated to a service. If attempted, this message will be emitted:
error: no machines were destroyed: machine 3 has unit "mysql/0" assigned
Destroying the environment means to remove all running services, their associated instances and the bootstrap node itself:
juju destroy-environment <environment>
Due to the gravity of this action, you will be prompted for a confirmation.
To remove relations between deployed services, see Charm relations.
These are caveats which you may encounter while removing items.
If you have a unit or service that persists in a dying state check to see if that unit, or any units within the associated service, are in an error state. A "removal" is an event within the queue of a unit's lifecycle so when a unit enters an error state all events within the queue are blocked. To unblock the unit's error you need to resolve it. Do so like this:
juju resolved <unit>
The above command may need to be repeated to resolve other errors on the unit.
There may be errors on other units caused by the breaking of relations that occur when removing a unit or service. Therefore also verify that the associated units are not in an error state and apply the above command to them if they are.