Failed to run chromium headless from cron job

I have a cron job that starts chromium headless (without window) every night to test a website.

The job works fine when started from the command line. It did execute well until the last snap upgrade a few days ago.

Since then I get the error message: /system.slice/cron.service is not a snap cgroup

It is not possible to install chromium without snap. While I understand the security rational, I assume that it is possible to get around the security restriction when chromium is run in this particular configuration. The profile directory is erased to start from scratch every night.

I would prefer avoiding to install the Debian Chromium or switch to Debian.

MaximTimeClock@Chmike ,

Running Chromium in headless mode from a cron job after a Snap update can indeed present some challenges, especially with the way Snap enforces security constraints. The error message /system.slice/cron.service is not a snap cgroup indicates that there are issues with the way Snap is interacting with the cgroups, which are part of the security and resource management features of the system. First Understand the Environment and Modify the Cron Job then Use a Wrapper Script at last try to Additional Troubleshooting. By setting the appropriate environment variables in your cron job or using a wrapper script, you can work around the issues caused by the Snap update. This should allow you to run Chromium headless as intended. If problems persist, further investigation into system logs and considering alternative scheduling methods may be necessary.

Thank you very much for taking the time to read and answer to my question.

I basically would like to know how I could run my program launching chromium nightly without any user connected to the host.

I thought that a cron job would run on behalf of the user, but it’s not valid anymore with snap.

Apparently, snap chromium is allowed to be used for a selenium or puppeteer like usage. But this works only when executed from the command line.

What do I need to do to be able to run it nightly for an automated web site testing for instance.

Sorry, there’s a 99% chance that user responding to you is a Large Language Model and not a real user.

Unfortunately I’m less familiar with cron but any system with snap almost always has systemd, I’m wondering does this change if you were to swap to systemd-timerd functionality which I believe replicates Cron to some degree but might fit in better here.

The snapd 2.63 update was released to stable yesterday. You could potentially try sudo snap revert snapd and see if it helps, in which case I’d assume it might be a regression with Fix to not use cgroup for non-strict confined snaps (devmode, classic).

Thank you, I finally found the solution and it worked this night. The solution is to use a user systemd service and timer.

Here is a link to the recipe that I gave on askubuntu.

It is the equivalent of a cron performed with systemd.