Skip to content

Feature: Notifications #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
famfop opened this issue Jul 13, 2018 · 8 comments
Open

Feature: Notifications #73

famfop opened this issue Jul 13, 2018 · 8 comments

Comments

@famfop
Copy link

famfop commented Jul 13, 2018

Hi,
I believe I once asked but maybe I am mistaking. So I was wondering if there is a way to get (custom?) notifications on mount / unmount? I am using the systemd service. If it is possible, I'd like to see a / some simple examples on how to configure it and I guess this would make people start using it easier.

@LemonBoy
Copy link
Owner

Please check out the manual, the -c option allows you to specify a custom script that ldm invokes every time a device is mounted/unmounted. The LDM_ACTION, LDM_FS, LDM_NODE and LDM_MOUNTPOINT environment variables are defined and should be enough to generate the notification blurb.

The only problem I see is that you might need to export the DISPLAY variable for notify-send to work from within the script.

@famfop
Copy link
Author

famfop commented Jul 13, 2018

Thanks, so do I need to export it inside the script or how would you do that?

@LemonBoy
Copy link
Owner

I guess something like

DISPLAY=:1 notify-send "Hello"

is enough, just make sure to export the correct display.

@famfop
Copy link
Author

famfop commented Jul 15, 2018

I have been trying different things and cannot get it going. I tried it the way you said, also setting DISPLAY=:0.0, DISPLAY=:0 and some other things but it didn't work. Do you have any idea?

@LemonBoy
Copy link
Owner

Not really, make sure the script is executable and is actually executed first.

@famfop
Copy link
Author

famfop commented Aug 1, 2018

I was on holiday and am back now. Let me summarize what I tried (unsuccesfully):
I made a scriptfile and made it executable. My $DISPLAY variable said :0.0 so I was not sure and tried out DISPLAY=:0 notify-send "test", DISPLAY=:0.0 notify-send "test", for I don't know what reason DISPLAY=:1 notify-send "test" and also "plain" notify-send "test".
I edited my systemd file (the ExecStart variable) such that it is ExecStart=/usr/bin/ldm -u ${MOUNT_OWNER} -p ${BASE_MOUNTPOINT} -c /path/to/executable/scriptfile.sh

I am still not able to get the output "test" from my notification daemon... Do you see any mistakes / are you able to get notifications?

EDIT: for the record, the mounting/unmounting works just as expected!

EDIT 2: I also just tried simply putting a echo 'hello' to my scriptfile and running the execstart-command in my terminal. I don't see the output so I am wondering if the -c flag works at all. Can you use it succesfully?

@LemonBoy
Copy link
Owner

LemonBoy commented Aug 6, 2018

There's no output at all, the file descriptors for stdin, stdout and stderr are closed before sh is invoked. Please check your syslog (journalctl or whatever) for ldm-related errors and try something like this to see if the commands are executed.

echo "Hello" > /tmp/check

@famfop
Copy link
Author

famfop commented Aug 6, 2018

Ok this worked, no error and the file was produced. But the notify-send just does not work. I went on reading and stumbled upon some posts seemingly having the same issue with udev rules. The problem seems to be the at startup missing DBUS_SESSION_BUS_ADDRESS. I read a bit and tried but I don't have too much time right know, so I just leave the - in my opinion - most helpful link here. The interesting part are the linked articles in Resources, mainly: notify-send bug and notify-send workaround.

bugabinga added a commit to bugabinga/ldm that referenced this issue Feb 25, 2019
This commit makes it a little bit more comfortable to add a custom script for use cases such as in LemonBoy#73.
When the variable is empty/undefined `ldm` simply prints `The callback script isn't executable!` but works fine.
I am unsure about the exact quoting rules in systemd service files.
Maybe the `COMMAND_PATH` should be wrapped in **"** in case of whitespace in path?

Tested this with following config:

/etc/ldm.conf
```sh
MOUNT_OWNER=oli
BASE_MOUNTPOINT=/home/oli/Mounts
FMASK_DMASK=0177,0077
COMMAND_PATH=/etc/ldm_notify.sh
```
/etc/ldm_notify.sh
```sh
#!/bin/sh
env DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus /usr/bin/toastify send --icon mount --app-name ldm "$LDM_ACTION" "Mounted $LDM_NODE($LDM_FS) in $LDM_MOUNTPOINT."
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants