Restarting services from configure hook: race condition

It seems I am hitting a case where this race condition is still present.

One of the services I am queuing for a restart (flanneld) has to have access to a few files to start correctly (eg /var/snap/microk8s/873/args/flanneld). The configure hook places these files in the right locations and does the queuing of the restart (flanneld has to wait for etcd and containerd https://github.com/ubuntu/microk8s/pull/649/files#diff-8f4e953fdcce135fef1df9e88717ab5dR288).

If you look at the logs below you will see that the first time flanneld starts with the right path. If it fails and systemd restarts it it switches to the yet uncommitted path where files like /var/snap/microk8s/873/args/flanneld do not exist yet.

Sep 16 15:22:36 ip-172-31-20-243 systemd[1]: Started Service for snap application microk8s.daemon-flanneld.
Sep 16 15:22:39 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: Error:  100: Key not found (/coreos.com) [4]
Sep 16 15:22:39 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: /coreos.com/network/config is not in etcd. Probably a first time run.
Sep 16 15:22:39 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: {"Network": "10.1.0.0/16", "Backend": {"Type": "vxlan"}}
Sep 16 15:22:42 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: I0916 15:22:42.327351    2093 main.go:514] Determining IP address of default interface
Sep 16 15:22:42 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: I0916 15:22:42.327682    2093 main.go:527] Using interface with name eth0 and address 172.31.20.243
Sep 16 15:22:42 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: I0916 15:22:42.327696    2093 main.go:544] Defaulting external address to interface address (172.31.20.243)
Sep 16 15:22:42 ip-172-31-20-243 flanneld[2093]: warning: ignoring ServerName for user-provided CA for backwards compatibility is deprecated
Sep 16 15:22:42 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: I0916 15:22:42.349349    2093 main.go:244] Created subnet manager: Etcd Local Manager with Previous Subnet: None
Sep 16 15:22:42 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: I0916 15:22:42.349473    2093 main.go:247] Installing signal handlers
Sep 16 15:22:42 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: I0916 15:22:42.360704    2093 main.go:386] Found network config - Backend type: vxlan
Sep 16 15:22:42 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: I0916 15:22:42.362613    2093 vxlan.go:120] VXLAN config: VNI=1 Port=0 GBP=false DirectRouting=false
Sep 16 15:22:42 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: I0916 15:22:42.374094    2093 local_manager.go:234] Picking subnet in range 10.1.1.0 ... 10.1.255.0
Sep 16 15:22:42 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: I0916 15:22:42.375058    2093 local_manager.go:220] Allocated lease (10.1.75.0/24) to current node (172.31.20.243)
Sep 16 15:22:42 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: I0916 15:22:42.378865    2093 main.go:317] Wrote subnet file to /var/snap/microk8s/common/run/flannel/subnet.env
Sep 16 15:22:42 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: I0916 15:22:42.378877    2093 main.go:321] Running backend.
Sep 16 15:22:42 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: I0916 15:22:42.378915    2093 vxlan_network.go:60] watching for new subnet leases
Sep 16 15:22:42 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: I0916 15:22:42.385354    2093 main.go:429] Waiting for 22h59m59.989196432s to renew lease
Sep 16 15:22:50 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: E0916 15:22:50.823603    2093 watch.go:171] Subnet watch failed: client: etcd cluster is unavailable or misconfigured; error #0: unexpected EOF
Sep 16 15:22:50 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: E0916 15:22:50.823632    2093 watch.go:43] Watch subnets: client: etcd cluster is unavailable or misconfigured; error #0: unexpected EOF
Sep 16 15:23:29 ip-172-31-20-243 systemd[1]: Stopping Service for snap application microk8s.daemon-flanneld...
Sep 16 15:23:29 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: I0916 15:23:29.865057    2093 main.go:370] shutdownHandler sent cancel signal...
Sep 16 15:23:29 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: I0916 15:23:29.865112    2093 main.go:437] Stopped monitoring lease
Sep 16 15:23:29 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: I0916 15:23:29.865122    2093 main.go:339] Waiting for all goroutines to exit
Sep 16 15:23:29 ip-172-31-20-243 microk8s.daemon-flanneld[2093]: I0916 15:23:29.865565    2093 main.go:342] Exiting cleanly...
Sep 16 15:23:29 ip-172-31-20-243 systemd[1]: Stopped Service for snap application microk8s.daemon-flanneld.
Sep 16 15:25:37 ip-172-31-20-243 systemd[1]: Started Service for snap application microk8s.daemon-flanneld.
Sep 16 15:25:38 ip-172-31-20-243 microk8s.daemon-flanneld[8329]: cat: /var/snap/microk8s/873/args/flanneld: No such file or directory
Sep 16 15:25:38 ip-172-31-20-243 microk8s.daemon-flanneld[8329]: cat: /var/snap/microk8s/873/args/flanneld: No such file or directory
Sep 16 15:25:38 ip-172-31-20-243 microk8s.daemon-flanneld[8329]: cat: /var/snap/microk8s/873/args/flanneld: No such file or directory
Sep 16 15:25:38 ip-172-31-20-243 microk8s.daemon-flanneld[8329]: cat: /var/snap/microk8s/873/args/flanneld: No such file or directory
Sep 16 15:25:38 ip-172-31-20-243 microk8s.daemon-flanneld[8329]: cat: /var/snap/microk8s/873/args/flannel-network-mgr-config: No such file or directory
Sep 16 15:25:38 ip-172-31-20-243 systemd[1]: snap.microk8s.daemon-flanneld.service: Main process exited, code=exited, status=1/FAILURE
Sep 16 15:25:38 ip-172-31-20-243 systemd[1]: snap.microk8s.daemon-flanneld.service: Failed with result 'exit-code'.
Sep 16 15:25:38 ip-172-31-20-243 systemd[1]: snap.microk8s.daemon-flanneld.service: Service hold-off time over, scheduling restart.
Sep 16 15:25:38 ip-172-31-20-243 systemd[1]: snap.microk8s.daemon-flanneld.service: Scheduled restart job, restart counter is at 1.
Sep 16 15:25:38 ip-172-31-20-243 systemd[1]: Stopped Service for snap application microk8s.daemon-flanneld.
Sep 16 15:25:38 ip-172-31-20-243 systemd[1]: Started Service for snap application microk8s.daemon-flanneld.
Sep 16 15:25:38 ip-172-31-20-243 microk8s.daemon-flanneld[8859]: cat: /var/snap/microk8s/873/args/flanneld: No such file or directory
Sep 16 15:25:38 ip-172-31-20-243 microk8s.daemon-flanneld[8859]: cat: /var/snap/microk8s/873/args/flanneld: No such file or directory
Sep 16 15:25:38 ip-172-31-20-243 microk8s.daemon-flanneld[8859]: cat: /var/snap/microk8s/873/args/flanneld: No such file or directory
Sep 16 15:25:38 ip-172-31-20-243 microk8s.daemon-flanneld[8859]: cat: /var/snap/microk8s/873/args/flanneld: No such file or directory
Sep 16 15:25:38 ip-172-31-20-243 microk8s.daemon-flanneld[8859]: cat: /var/snap/microk8s/873/args/flannel-network-mgr-config: No such file or directory
Sep 16 15:25:38 ip-172-31-20-243 systemd[1]: snap.microk8s.daemon-flanneld.service: Main process exited, code=exited, status=1/FAILURE
Sep 16 15:25:38 ip-172-31-20-243 systemd[1]: snap.microk8s.daemon-flanneld.service: Failed with result 'exit-code'.
Sep 16 15:25:38 ip-172-31-20-243 systemd[1]: snap.microk8s.daemon-flanneld.service: Service hold-off time over, scheduling restart.
Sep 16 15:25:38 ip-172-31-20-243 systemd[1]: snap.microk8s.daemon-flanneld.service: Scheduled restart job, restart counter is at 2.