fiber
January 8, 2021, 10:40pm
1
I am trying to reconnect to a wifi network on a Raspberry Pi with Ubuntu Core. In my snap I have:
reconnect:
command: systemctl restart systemd-networkd.service
daemon: oneshot
timer: '01:00'
plugs: [ network-control ]
but I keep getting a permission denied error.
/snap/.../command-reconnect.wrapper: 2: exec: /bin/systemctl: Permission denied
I did connect the network-control
plug manually.
I guess I am using the wrong plug?
I have a WiFi USB stick connected to the RPi but sometimes Ubuntu boots too fast, the stick hasn’t finished booting yet so the network isn’t up. My solution is to restart the networkd service but maybe there are better ways?
Thank you!
ogra
January 9, 2021, 12:23am
2
you wont be able to use systemctl from inside a snap, but with a connected network-control interface you can talk to netplan via dbus, like:
dbus-send --system --type=method_call --print-reply \
--dest=io.netplan.Netplan /io/netplan/Netplan io.netplan.Netplan.Apply
so make your snap ship a shellscript that calls the above line and your wifi should reconnect …
fiber
January 9, 2021, 10:39pm
3
Thanks for the suggestion. Would you know what permissions it needs?
script
#! /bin/sh
dbus-send --system --type=method_call --print-reply --dest=io.netplan.Netplan /io/netplan/Netplan io.netplan.Netplan.Apply
snapcraft.yaml
reconnect:
command: $SNAP/bin/reconnect.sh
daemon: oneshot
timer: '01:00'
plugs: [ dbus ]
But dbus
doesn’t seem to be a valid plug (on the Raspberry Pi at least).
warning: |
snap has bad plugs or slots: dbus (cannot find attribute ‘bus’)
I also tried with the network-control
plug which gives me:
Error org.freedesktop.DBus.Error.AccessDenied: An AppArmor policy prevents this sender from sending this message to this recipient; type=“method_call”, sender=":1.6" (uid=0 pid=3117 comm=“dbus-send --system --type=method_call --print-repl” label=“snap.snapname.reconnect (enforce)”) interface=“io.netplan.Netplan” member=“Apply” error name="(unset)" requested_reply=“0” destination=“io.netplan.Netplan” (bus)
ogra
January 10, 2021, 12:07am
4
just don’t forget to make it executable
you want just network-setup-control
that includes permissions for this dbus call
fiber
January 10, 2021, 10:59am
5
The network-setup-control
plug seems to do the trick. Thank you @ogra !