[systemd-devel] directive for executing a script on service failure

George Karakougioumtzis mad-proffessor at hotmail.com
Sun Feb 8 04:48:45 PST 2015


Yes you r absolutely right, its kind of hackish and not architectural
correct.
I did something (simple but suits my needs for now) in python that gets
executed from gnome.
Here it is if someone is interested in knowing the state of some
services at specified intervals
#######
import dbus
from dbus import SystemBus,Interface
from gi.repository import Notify, GObject
from time import sleep
import threading;

class DbusNotify():
 def __init__(self):
  pass
  def doRun(self):
  threading.Timer(1200, self.doRun).start ();
  bus = SystemBus()
  systemd =
bus.get_object('org.freedesktop.systemd1','/org/freedesktop/systemd1')
  manager = Interface(systemd,
dbus_interface='org.freedesktop.systemd1.Manager')
 
array=["iptables.service","rc-local.service","polkit.service","systemd-logind.service","systemd-udevd.service","rpcgssd.service"]
  try:
     for a in array:
    getUnit=manager.GetUnitFileState(a);
    status= a + " status: %s" % getUnit
    Notify.init("myapp_name")
    n = Notify.Notification.new("systemd", status)
    n.show()
  except Exception as  e:
    raise

notif=DbusNotify()
notif.doRun()
#######
On 02/07/2015 06:15 PM, Mantas Mikulėnas wrote:
> On Sat, Feb 7, 2015 at 1:32 AM, George Karakougioumtzis
> <mad-proffessor at hotmail.com <mailto:mad-proffessor at hotmail.com>> wrote:
>
>     Interesting point, thanks for the clarifications. I thought that
>     it would be as simple as setting the environmental variables
>     DBUS_SESSION_BUS_ADRESS and DISPLAY at each unit file that you
>     would want to receive notifications from.
>
>
> At a technical level, yes, notify-send only needs one of them to
> connect to D-Bus.
>
> But beyond that, I am not going to touch /anything/ that assumes one
> user, one session, one unchanging display, and one unchanging session
> bus path. (You /could/ hardcode DISPLAY=:0, but there's no guarantee
> that it will still be :0 the next time – even on single-user systems
> I've seen Xorg crash, leaving :0 locked, and restarting at :1 or :2.)
> If you like such hacks, feel free to – systemd will not stop you. You
> can even use EnvironmentFile=.
>
> Perhaps it will change in the future. When the "user bus" is
> implemented in the upcoming months, this task will, hopefully, become
> a simple matter of contacting /run/user/$UID/bus for each logged in user.
>
> (It's odd; people always complain that systemd forgets Unix, but they
> themselves forget that Unix was a /massively/ multi-user system...
> Hell, even my old WinXP desktop spent most of this time with two
> people using it /at once/; one locally, one over RDP.)
>
> -- 
> Mantas Mikulėnas <grawity at gmail.com <mailto:grawity at gmail.com>>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20150208/222d6d76/attachment-0001.html>


More information about the systemd-devel mailing list