[systemd-devel] Help writing a user service file that will exec a command upon system sleep

Mantas Mikulėnas grawity at gmail.com
Mon Nov 2 06:11:14 PST 2015


On Mon, Nov 2, 2015 at 3:34 PM, Richard Maw <richard.maw at codethink.co.uk>
wrote:

> On Mon, Nov 02, 2015 at 09:04:31AM +0100, Lennart Poettering wrote:
> > On Wed, 28.10.15 19:30, John (da_audiophile at yahoo.com) wrote:
> >
> > > I have a simple bash script that I would like to have a user service
> > > file run with an argument when the system enters a sleep or
> > > hibernation state but as I understand it, user service units do not
> > > use the sleep.target.  The goal is to have the following run before
> > > the system goes into sleep/hibernate triggered by whatever mechanism
> > > systemd uses to detect when the user sleeps or hibernates the
> > > system: '/usr/bin/psd sync'
> >
> > You can install a suspend delay inhibitor:
> >
> > https://wiki.freedesktop.org/www/Software/systemd/inhibit/
> >
> > That works from privileged code the same as for user code. However,
> > you cannot really do that from shell code. I fear for shell this is
> > simply not available, sorry.
>
> You may be able to abuse the hell out of systemd-inhibit to have it work:
>
> #!/bin/sh
> # Approach cribbed from http://www.opopop.net/Harnessing_DBus/


Might as well use ctypes.sh then... Or a more capable language:

https://gist.github.com/grawity/a10ee46d7ff58048d483

-- 
Mantas Mikulėnas <grawity at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20151102/7e30d1a2/attachment.html>


More information about the systemd-devel mailing list