maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   [Announce] Dbuscron - the cron-like DBUS scheduler (https://talk.maemo.org/showthread.php?t=67194)

kstep 2010-12-20 01:16

[Announce] Dbuscron - the cron-like DBUS scheduler
 
Hello, all!

I was missing for simple dbus scheduler for a long time (dbus-scripts is a no op for me for some reasons), so I created my own dbuscron daemon to monitor DBUS events and run commands on them.

The source code lies on github at http://github.com/kstep/dbuscron and deb-package can be taken from my blog at http://kstep.me/dbuscron_en.html.

The main idea of the scheduler is simple: it's just like good old cron but for DBUS messages. It's configured with /etc/dbuscrontab file in a crontab-like format. Here're some simple examples from my own config:

Code:

# bus(*S*ystem/*s*session) message_type(signal|method_call|method_return|error) source interface object_path member destination arguments command
# Stop player on headphones plug out
S signal * org.freedesktop.Hal.Device /org/freedesktop/Hal/devices/platform_headphone Condition * ButtonPressed;connection grep -q disconnected /sys/devices/platform/gpio-switch/headphone/state && run-standalone.sh /opt/userscripts/mpcontrol.sh stop
# Connect to ISP via PPTP on home WiFi network connection
S signal * com.nokia.wlancond.signal /com/nokia/wlancond/signal connected * wlan0 run-standalone.sh /opt/userscripts/tasks/connect-pptp.sh
# Disconnect PPTP
S signal * com.nokia.wlancond.signal /com/nokia/wlancond/signal disconnected * wlan0 run-standalone.sh /opt/userscripts/tasks/disconnect-pptp.sh
# Forward all notifications to my notebook via SSH (sic!)
s method_call * org.freedesktop.Notifications /org/freedesktop/Notifications SystemNoteInfoprint,Notify * * /opt/userscripts/tasks/whitebook-notify.sh

I can give you a lot of such examples and using them is as easy as adding new line in config and sending HUP to dbuscron daemon to make it reread this config. I think this example tells you more than thousand words, and if not, you can read more about it at http://kstep.me/dbuscron_en.html, as there're too many options to mention all of them here (and actually I have wrote so much about it in my blog, I got a little tired of describing all of them, sorry =).

As of stability, I run it on my N900 all the time for several weeks and haven't mentioned any critical bugs (and if I do, I will not wait to fix them asap, as I'm the main user of this program).

P.S. If you are interested in some of my scripts mentioned in this example, I can provide them as well (except private parts with passwords etc. of cause =).

kstep 2010-12-21 13:03

Re: [Announce] Dbuscron - the cron-like DBUS scheduler
 
On similarity to dbus-scripts I want to mention the following points:

+ the command can be not only single script name w/o spaces, it can be any
arbitrary string, include spaces and different shell-orientent
expressions etc.,
+ it can listen to both session & system buses at the same time (which is
critical to me),
+ it can (hopefully) run without run-standalone.sh,
+ it provides full DBUS message info to script in environment variables,
+ arguments are matched as strings, and they are converted to them in a
quite smart way, so you can match even bools ('1' for true and '0'),
arrays as '1,2,3' or dicts as 'a:1,b:2,c:3' (well, there's still small
bug in it I will target in closest release, but it's a really quick and
easy fix),
+ any scripts written for dbus-scripts, are already compatible with dbuscron,
just use "scriptname $DBUS_ARG0 $DBUS_ARG1 $DBUS_ARG2" as command in dbuscrontab,
or replace $1,$2,... in script with $DBUS_ARG0,$DBUS_ARG1,...,

- it doesn't match rules with fnmatch(), but with simple string comparison,
so no wildcards (except for '*', which is not wildcard exactly), but it
is in my todo list.

kstep 2010-12-21 13:07

Re: [Announce] Dbuscron - the cron-like DBUS scheduler
 
BTW, I'm in garage now at https://garage.maemo.org/projects/dbuscron/ and version 1.4 is out. Changelog:

bus: interface to set custom session bus
--sessionaddr option to set custom session bus address
parser: fixed typo
support \xXX escape characters in args field
parser: fix bug in syntax checker on starred fields
genchangelog: indent shortlog correctly
run dbuscron as user
support \uXXXX as well as \xXX in args field
Makefile: better compilation

hawaii 2010-12-21 13:55

Re: [Announce] Dbuscron - the cron-like DBUS scheduler
 
Good stuff.

joerg_rw 2010-12-21 14:28

Re: [Announce] Dbuscron - the cron-like DBUS scheduler
 
Sounds nice.
You thought about some support scripts that will import and convert existing dbus-scripts settings? might be useful, as I'd not want to run both daemons concurrently, but rather migrate from dbus-scripts to Dbuscron.

Please give clear instructions how to install your program, so users don't need to figure out by themselves.

Many thanks, keep hacking :-)
/jOERG

Matan 2010-12-21 15:09

Re: [Announce] Dbuscron - the cron-like DBUS scheduler
 
Having a configuration directory in addition to (or instead of) a configuration file is essential for allowing other programs to easily use this daemon. I hope you plan to add this feature.

kstep 2010-12-21 15:16

Re: [Announce] Dbuscron - the cron-like DBUS scheduler
 
Thank you all to your comments. I will put your ideas on my todo list.

kstep 2010-12-22 16:29

Re: [Announce] Dbuscron - the cron-like DBUS scheduler
 
New 1.5 release.

Release notes: https://garage.maemo.org/frs/shownot...elease_id=4337
Download from: https://garage.maemo.org/frs/?group_id=2007

Please read release notes carefully. I have implemented ideas of all people in this thread.

kstep 2010-12-22 17:24

Re: [Announce] Dbuscron - the cron-like DBUS scheduler
 
I have petitioned for extras-devel upload account and now am waiting for approvement. When I got it, I will put dbuscron into extras-devel, so it can be installed via application manager. For now you can download it from my garage account and install either by opening deb-package with application manager or via command line:

$ sudo gainroot
# dpkg -i path/to/package/dbuscron_1.5-1_all.deb

kstep 2010-12-22 18:37

Re: [Announce] Dbuscron - the cron-like DBUS scheduler
 
If you like and use my dbuscron, please consider voting for it at my ohloh page (if it's not very difficult and time consuming for you, of cause):
https://www.ohloh.net/p/dbuscron
Thank you in advance!


All times are GMT. The time now is 03:34.

vBulletin® Version 3.8.8