{"action":"opened","issue":{"url":"https://api.github.com/repos/coreos/fleet/issues/1323","labels_url":"https://api.github.com/repos/coreos/fleet/issues/1323/labels{/name}","comments_url":"https://api.github.com/repos/coreos/fleet/issues/1323/comments","events_url":"https://api.github.com/repos/coreos/fleet/issues/1323/events","html_url":"https://github.com/coreos/fleet/issues/1323","id":99089607,"number":1323,"title":"Proposal: add ExecUnload directive to unit file","user":{"login":"acbodine","id":7049554,"avatar_url":"https://avatars.githubusercontent.com/u/7049554?v=3","gravatar_id":"","url":"https://api.github.com/users/acbodine","html_url":"https://github.com/acbodine","followers_url":"https://api.github.com/users/acbodine/followers","following_url":"https://api.github.com/users/acbodine/following{/other_user}","gists_url":"https://api.github.com/users/acbodine/gists{/gist_id}","starred_url":"https://api.github.com/users/acbodine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/acbodine/subscriptions","organizations_url":"https://api.github.com/users/acbodine/orgs","repos_url":"https://api.github.com/users/acbodine/repos","events_url":"https://api.github.com/users/acbodine/events{/privacy}","received_events_url":"https://api.github.com/users/acbodine/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-05T00:30:42Z","updated_at":"2015-08-05T00:30:42Z","closed_at":null,"body":"Would it be a bad idea to add `ExecUnload` directive in a unit file, so that a user can specify cleanup actions for when the unit is un-scheduled from the cluster?\r\n\r\nI have searched around for someone else that desires the same behavior: https://github.com/coreos/fleet/issues/612\r\n\r\nThe suggested unit file directive combos (`ExecStartPre`, `ExecStart`, `ExecStop`) to handle cleaning up unit artifacts (maybe Docker containers) really don't solve the issue of when I `fleetctl stop && fleetctl unload` a unit I still have a Docker container (hopefully stopped) on the host that the unit was running on.\r\n\r\nFor example:\r\n\r\nLet's say we want to have multiple etcd instances running on a single host. We don't have to do this in Docker containers, but for the sake of example let's say we do, such that:\r\n```\r\n$ docker images | grep etcd\r\netcd          2.1.1          d90a4ab8affa        7 days ago          179.1 MB\r\n```\r\n\r\nAnd we have a unit file `etcd-container@.service` like so:\r\n```\r\n[Unit]\r\nDescription=Etcd Cluster\r\nAfter=docker.service\r\nRequires=docker.service\r\n\r\n[Service]\r\nRestart=always\r\nRestartSec=50s\r\nTimeoutStartSec=0\r\nEnvironmentFile=/etc/sysconfig/etcd\r\nExecStart=/bin/bash -c \"\\\r\n\t\tdocker start %p_%i && docker logs -f %p_%i || \\\r\n\t\teval $(etcdctl --peers=${IP}:2379 member add %p_%i http://${IP}:$PEER_PORT | tail -n 3 | tr -d '\\\"' ) ; \\\r\n\t\tdocker run -p 2379 -p $PEER_PORT:$PEER_PORT --name %p_%i \\\r\n\t\t\t-e ETCD_ADVERTISE_CLIENT_URLS=\\\"http://${IP}:${CLIENT_PORT}\\\" \\\r\n\t\t\t-e ETCD_INITIAL_ADVERTISE_PEER_URLS=\\\"http://${IP}:$PEER_PORT\\\" \\\r\n\t\t\t-e ETCD_INITIAL_CLUSTER=\\\"$ETCD_INITIAL_CLUSTER\\\" \\\r\n\t\t\t-e ETCD_INITIAL_CLUSTER_STATE=\\\"$ETCD_INITIAL_CLUSTER_STATE\\\" \\\r\n\t\t\t-e ETCD_NAME=$ETCD_NAME \\\r\n\t\t\t-e ETCD_LISTEN_PEER_URLS=\\\"http://0.0.0.0:$PEER_PORT\\\" \\\r\n\t\t\t-e ETCD_LISTEN_CLIENT_URLS=\\\"http://0.0.0.0:2379\\\" \\\r\n\t\t\tetcd:2.1.1\"\r\nExecStop=/usr/bin/docker stop %p_%i\r\n\r\n[X-Fleet]\r\nMachineID=%i\r\n```\r\nAs you can see when we `fleetctl start etcd-container@$(cat /etc/machine-id).service`, first we try to start an existing etcd container that matches the %p_%i on the host which should allow a stopped/running etcd container to start talking to the etcd cluster if it exists. Otherwise add a new member to the etcd cluster, and start a new Docker container with the relevant port binding information.\r\n\r\nNow please entertain the use case where we have an existing etcd cluster that is deployed across multiple hosts with the above unit file. If we need to re-deploy that cluster completely from scratch (maybe because etcd is in a bad state), I would think that running `fleetctl stop && fleetctl unload` for each etcd unit would remove the etcd cluster and it's artifacts (i.e. Docker containers that contain etcd snapshots) Then simply just `fleetctl load && fleetctl start` a new etcd cluster.\r\n\r\nIn practice this won't work without removing all of the Docker etcd containers across the fleet machines before re-deploying the etcd cluster becuase without doing that, the new units will simply start the existing etcd containers from the previous cluster. Whereas if I could tell fleet that when unloading an etcd-container@.service unit that I wanted it to remove the Docker container, it seems that the exercise of re-deploying the etcd cluster could be totally managed by fleet."}}