Removal within Juju
Juju isn't just about magically spinning up services as and when you need them, it is also about quickly, sanely and efficiently destroying everything when you no longer need it. This section deals with the sort of things you can ruthlessly destroy, and how to go about it.
Once a service is no longer required it can be removed with a simple command.
juju destroy-service <service-name>
Warning!: Destroying a service which has active relations with another running service will break that relation. This can cause errors in both services, as such review and potentially remove any relationships first.
A service can take a while to "die", but if running a juju status reveals that the service is listed as dying, but also reports an error state, then the zombied service will still be hanging around. See caveats for how to manage services in a dying state.
Note: Destroying a service removes that service, but not any nodes which may have been created for it to run on. This is juju's way of preserving data to the best of its ability. See Destroying Machines for additional details.
It is also possible to spin down individual units, or a sequence of units running within a service:
juju remove-unit mediawiki/1
remove-unit command is an alias for
destroy-unit, and can be used interchangeably, so the above is identical to:
juju destroy-unit mediawiki/1
If you wish to remove more than one unit, you may list them all following the command:
juju remove-unit mediawiki/1 mediawiki/2 mediawiki/3 mysql/2 ...
Note: As with destroying a service, removing units will NOT actually remove any instances which were created, it only removes the service units. More details can be found in the Scaling Services section.
As with destroying services, See caveats for how to manage units in a dying state.
Instances or machines which have no currently assigned workload can be removed from your cloud using the following command:
juju destroy-machine <number>
A machine which is currently idle will be removed almost instantaneously from the cloud, along with anything else which may have been on the instance which juju was not aware of. To prevent accidents and awkward moments with running services, it is not possible to remove an instance which is currently allocated to a service. If you try to do so, you will get a polite error message in the form:
error: no machines were destroyed: machine 3 has unit "mysql/0" assigned
To completely remove and terminate all running services, the instances they were running on and the bootstrap node itself, simply run the command:
This will completely remove all instances running under the current environment profile. You can of course specify a different environment profile using the
-e switch, or any one of these other methods:
juju destroy-environment -e mycloud
You should be pretty sure that this is what you want to do, as there is no undo command! Everything in the selected environment will be removed.
To remove relations between deployed services, you should see the docs section on charm relationships.
These are caveats which you may encounter while trying to remove items within Juju
If you have a unit or serving in a dying state that has not gone away check to see if that unit, or any units within the service, are in an error state. Since Juju is an event driven orchestration client, the "removal" of a unit and service is also modeled as an event within Juju. As such, when a unit enters an error state all other events within that unit's lifecycle are queued. To clear this run
juju resolved <unit>to have the next event processed. You may need to run the
resolvedcommand run several times against a unit.
If the unit isn't in an error state, there may be an error elsewhere in the environment. Since removing a unit or destroying a service also breaks the relation, if there's an error in the relation-removal event on one or more of the connected services that may also halt the event loop for that unit. Check to make sure no other units are in an error state and clear those using the
juju resolved command.