since this recently comes up more often here, i quickly threw together a snap:
name: reboot-test
base: core20
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: Single-line elevator pitch for your amazing snap # 79 char long summary
description: |
This is my-snap's description. You have a paragraph or two to tell the
most important story about your snap. Keep it under 100 words though,
we live in tweetspace and your description wants to look good in the snap
store.
grade: stable
confinement: strict
apps:
reboot:
command: usr/bin/reboot
environment:
PYTHONPATH: $SNAP/usr/lib/python3/dist-packages:$PYTHONPATH
plugs:
- shutdown
parts:
reboot:
plugin: dump
source: .
organize:
reboot.py: usr/bin/reboot
stage-packages:
- python3-dbus
and the reboot.py
script:
#! /usr/bin/env python3
import dbus
bus = dbus.SystemBus()
bus_object = bus.get_object("org.freedesktop.login1", "/org/freedesktop/login1")
bus_object.Reboot(True, dbus_interface="org.freedesktop.login1.Manager")
calling it as: sudo reboot-test.reboot
will then reboot your system …