How do system services work in snaps
From https://developer.ubuntu.com/en/snappy/build-apps/debug/
Testing a service
To test a service it must be installed first. Once it is installed, systemd's systemctl
command can be used to see if the service starts and runs as expected, for example:
systemctl status snap.<name>.<appname>
Finding the logs
The journalctl
command can be used to inspect the messages that the service sends to stdout
/stderr
, for example:
journalctl -u snap.<name>.<appname>
Services may log additional data to syslog (/var/log/syslog
) or to custom log directories. Note that custom log directories must be in a path that the service can write to (usually SNAP_DATA
).
Getting a core dump
To enable core dumps you have to configure a place to write them to through sysfs. For instance you can use
$ echo "/tmp/core.%e.%p" > /proc/sys/kernel/core_pattern
to ensure that your coredumps get written into the /tmp
directory regardless of where CWD
of the process that received a signal was.
Related videos on Youtube
David Planella
I work at GitLab as Director of Community Relations. Before, I worked for Canonical as the former Ubuntu Community Team Manager. As an Open Source contributor, I am mostly involved in app development and localization: I'm the developer of Qreator, former lead the Ubuntu Catalan Translators team and also a GNOME translator. In the past I've contributed to other projects, such as Debian or Mozilla. Blog Google+ Twitter
Updated on September 18, 2022Comments
-
David Planella over 1 year
When creating a snap, and according to the syntax of the snapcraft.yaml file, the
daemon
keyword can be added to specify that the app will be run as a system service. As an example of such declaration:apps: tinyproxy: command: ./launcher.sh daemon: simple plugs: [network,network-bind]
However, what does it exactly mean to be a system service in a snap? That is, what's their lifecycle (start, restart, stop...)? Can I monitor them running in the system with the usual tools (
ps
,top
, etc)? -
David Planella almost 8 yearsThanks! Also, I got a tip that an easy way to debug issues with a service not starting is to temporarily uncomment the
daemon: simple
line to make it behave as a regular app, and then manually start the "appified" service assudo /snap/bin/<servicename>
-
Ankur Bhatia over 4 yearsis it possible to redirect the logs to a custom file instead of journal?