Adding a MOTD notice with a snap

I’m trying to add an /etc/update-motd.d script when my snap installs. The way I’ve been trying to achieve this is by declaring a system-files plug:

plugs:
  config-motd:
    interface: system-files
    read:
      -  /etc/update-motd.d/99-upgrade-required
    write:
      -  /etc/update-motd.d/99-upgrade-required

and copying a file in the connect-plug-config-motd hook. This seems to work, however there is a problem when it comes to removing the file. I’ve tried to do that in the remove and disconnect-plug-config-motd hooks, but the plug hook does not seem to get invoked and the remove hook results in this syslog entry:

apparmor="DENIED" operation="unlink" profile="snap.canonical-livepatch.hook.remove" name="/etc/update-motd.d/99-livepatch-kernel-upgrade-required" pid=10875 comm="rm" requested_mask="d" denied_mask="d" fsuid=0 ouid=0

Is there a better way of going about this?

have you defined config-motd as a plug for the remove hook in your snapcraft.yaml (a thing that people often forget … hooks need plug definitions set if they want to use these plugs)

Yes, I have.

hooks:
  connect-plug-config-motd:
    plugs: [config-motd]    
  disconnect-plug-config-motd:
    plugs: [config-motd]    
  remove:
    plugs: [config-motd]