Skip to content
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

Doesn't work when used within proces runner such as PM2 or CRONtab? #226

Open
kunokdev opened this issue Mar 11, 2018 · 7 comments
Open

Comments

@kunokdev
Copy link

kunokdev commented Mar 11, 2018

I've added script to my crontab somewhat like this:

@reboot /path/to/script
* * * * * /path/to/script

code runs, however there is no notification.

return notifier.notify({
  title: 'foo',
  message: randomMessage(),
})

Same issue with PM2. So it appears that when it's being ran by some different process, not from user's shell, then it fails to send notification to desktop.

Same issue when using with gnome-session-properties. Linked SO question: https://stackoverflow.com/questions/49221716/when-using-notify-send-inside-some-process-runner-such-as-cron-or-pm2-notificat

Versions:
Ubuntu 16.04 Gnome3 (gubuntu distro).
notify-send 0.7.6
"node-notifier": "^5.2.1",

@kunokdev kunokdev changed the title Doesn't work when used as CRON task? Doesn't work when used within proces runner such as PM2 or CRONtab? Mar 11, 2018
@NicolasPerl
Copy link

@kunokdev did you end up figuring this out? It seems I'm having the same problem.

@kunokdev
Copy link
Author

kunokdev commented May 23, 2018

@NicolasPerl Unfortunately, I haven't. Spent whole night debugging linux notify-send (which is used as shell command within this lib for Linux) and I couldn't fix it. However, I think it's related to users, CRON is one user, Desktop environment is other user, and active shell user is third. So perhaps, desktop environment user has no access to crontab user's actions or vice versa. This needs deeper inspection tho. Also, in some edge cases this code worked, I don't know why and I couldn't debug it because I was doing presentation at that moment (and my bot's notification popped up that time, and never once again or before)

@joshhopkins
Copy link

Can confirm this is working: #148

@SPDUK
Copy link

SPDUK commented Apr 23, 2019

I'm trying to send notifications from cron, and the notifications don't display under ubuntu 19.04.
It does work under task scheduler on windows 10, though (using the exact same scripts).

Trying to run notify-send in general from cron does not work properly, but I found a this on SO which makes it work correctly from cron
* * * * * XDG_RUNTIME_DIR=/run/user/$(id -u) notify-send Hey "this is dog!

So in my .sh script I've added
export XDG_RUNTIME_DIR=/run/user/$(id -u) to the top of it, and that has made it work from cron for linux.

@nguiard
Copy link

nguiard commented May 7, 2019

My experience with this is, running via pm2, it works out of the box on my Mac, but not on a Win10 machine. (the script run by itself shows the notification on Win10, but not if run via pm2). Still trying to figure it out.

@nguiard
Copy link

nguiard commented May 7, 2019

Actually, upon further testing, it appears that my issue on Windows 10 was linked to the way I had pm2 starting up. I used nssm (Non-Sucking Service Manager) to make pm2 startup on Win10. At first I made it startup as a system user, which was the main problem. After I edited the pm2 service with nssm to start as a specific regular user, notifications worked for me. Hoping this can help someone.

@mikaelbr
Copy link
Owner

Related to #333

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

6 participants