Detecting if XBMC is playing, from shellscript? - linux

I have an XBMC setup that I absolutely love at home. Now, I've been doing a bunch of automation to make everything run smoothly and without manual maintenance (Like updating my library automatically on new arrivals etc.), however one thing I'm missing:
I want to write a shellscript, which takes care of suspending the machine at night, and waking it at a predefined time the next day. There's two things to it:
1) It should start up automatically at predefined intervals. I have this covered through RTC + wakealarm in Ubuntu.
2) It should, at a specific time at night, check if XBMC is currently playing anything (In case I'm up at night). If XBMC is NOT playing, it should suspend the machine. I'm unaware if this is possible ?

I actually found the answer to this one myself, after digging quite a lot into the new JSON RPC webservice in newer XBMC's.
The webservice now allows you to poll to see if any players are currently active (When playing a video for instance). I'm going to use those in the aforementioned script to check if I'm currently watching anything, before shutting the mediacenter down for the night :)
It's described on http://wiki.xbmc.org/index.php?title=JSON_RPC#JSONRPC.GetAnnouncementFlags

Related

Monitor cron jobs in real-time

I have an issue currently where I've got a cron job set to run at midnight each day to reset daily API requests for a service that I run. The job failed recently which caused me a whole bunch of headaches and I've been trying to find a solution to monitor all of my cron jobs so I don't have a situation like this happen again.
I haven't been able to find a sufficient solution however, and in response I am considering creating a platform that allows you to monitor cron jobs, see logs (and past logs), last run date, failure/success of the last run, etc... in real-time and would notify you if your job hasn't completed within a specified window of time or the job failed.
I believe this might be a pain point and a good solution for others as well.
What are you thoughts? Do you think that this would be useful, have any suggestions, or just think this would be a waste of time?
Did you hear about Rundeck? (https://www.rundeck.com/open-source)
It looks like it's exactly what you're looking for.
You install it on a server, and it's like a Web UI for a crontab.
You define jobs you want to run using the Web UI, how often you want them to run and you can see some history of the past executions, their status and their output. You can also see when the next execution will happen.
I think there are also some alerting features to notify you if a job is on failure. I'm not sure if it can notify you based on the job execution time though.
This might be a good fit for what you're looking for.
2 years later, I am asking myself exactly the same questions ) Definitely you should have created such service already, haven't you? Every backend coder needs this time from time, in theory. I'm surprised this question hasn't received enough activity/voting. I got an answer leading to this though: https://uptimerobot.com/cron-job-monitoring/ that might be a good solution. Need to test it out. It does not seem to be promoted enough, as it's not easy to find. Also there is https://cronitor.io/docs/cron-job-monitoring that has ability to transmit (somewhat limited) telemetry data, +a lot of SDKs to be used from within programming languages.

Flutter: Schedule audio events for background execution

I am implementing an app in Flutter, for which I need to schedule (audio) events in advance. Only after one event is completed I can schedule the next, since the duration of the event might not be known before. Each audio event is a notification sound for the user, thus scheduling and audio playback should both work while the app has no focus or the phone is locked.
I currently fail to implement these specifications and I guess I'm just not thinking the right way about it for the moment. Since I started to learn Flutter recently, there could also be just some simple misunderstandings from my part. Let me summarize what I know about background execution & native code in Flutter, please correct anything wrong with these statements:
When the App looses focus (or the phone gets locked) code execution stops.
However, inside the "primary" Dart-code, I can spawn an isolate which will run even with the phone locked or without focus on the app.
Different isolates share no memory whatsoever; they communicate via ports.
There a spawned isolate does not know anything about the flutter ecosystem, therefore it is not possible to use flutter plugins.
For the same reasons I cannot use MethodChannels as well to communicate with platform code from an isolate.
From this I conclude:
The event should be scheduled from a seperate Dart-isolate, so that locking the phone won't halt scheduling.
This isolate won't be able to play any audio file by itself, and won't be able to communicate with platform code.
Thus, it needs to communicate with the primary isolate, which can play audio. However, without the app open, the code won't respond.
Consequently, this approach cannot work?
Right now, I am stuck at this point and don't know how to continue. I guess one option could be to directly call java/swift code for the respective native platforms and handle scheduling and audio there. Yet, I hope that I just don't see a simpler option right now.

Node.js require becomes extremely slow after OS X has been running for a while

When I reboot my Mac, starting up Node.js apps is nice and fast. Later, after the Mac has been on for a few hours, it gets REALLY slow.
I've used process.hrtime() to time various things, and it seems that it's all the require calls that take time, ie loading dependencies. Once everything is loaded, my apps run reasonably fast.
The difference is extreme: just after I've rebooted, an app may take 300ms to get through the require calls, then it takes something like 30 seconds once it's been on for a few hours.
What could be causing this?
Since how fast executing require is perfectly related to a disk loading performance.
So I suppose It's highly possible that HDD/SSD or whatever your project belongs causing that.
it's working fine right after you rebooted so maybe some background software(such as virus scan or auto downloader) is making IO blocking
You'd better start by checking your CPU/RAM/HDD status while the issue is occurring and see what happens if you move your project into USB flash drive or external HDD

Connect to a child process after navigating away from the page

I am using SailsJS for a web application which basically lets the user download and process any video from the internet(say youtube). The user enters a link to the video and my sails app downloads the video if available and then starts processing the downloaded video using a shell script(Come OpenCV processing to find different frames).
This process takes a very long time to complete, and the user can navigate away from the page and do whatever he wants. Now, to check on the progress by visiting this page later I need to be able to connect with the child process that was created earlier for this video file.
I have come up with two possible solutions:
1) Using gearman to implement a job server and connect to it every time the user navigates to the page and start getting the callback events and show the progress based on them. This is the first time I'll be using gearman.
2) Somehow storing the processID of the child process in the session/db and then using it to find the process using ps-node.
Which of these is the better approach(if you think they'll work fine)? Or is there any other solution I don't know about? Any pointers in the right direction will be appreciated.
Let's start with the second option. Don't use it. Simply because this way your site users will have sort of more control over the number of processes running on your server then you will.
Number one is way better, but using a separate job server seems like a bit of overkill to me (I have to admit though that I'm not fully informed the scale of your plans).
Bottom line, I would use a message/job queue (kue seems like a perfect fit to me) and store the progress in DB or (preferably) Redis (or whatever cache you are using).

"General permanent error" during libspotify search

I've recently started programming in C on my Raspberry Pi. I have downloaded libspotify (I have the correct version), and have managed it pretty well.
Just recently (~2 hours ago (around 18:00 30/12/2013)), libspotify started to return SP_ERROR_OTHER_PERMANENT when checking for a search error in the search_complete_cb callback.
Before the error started occuring, I have built and started the program quite a few times (and thus, logging in many times, during only a short period of time), and to test my 'Search' feature, I have used the same query every time. Then, without making any changes to my program, suddenly there were no results returned after calling sp_search_create.
I am worried that the developer account has been somehow suspended for either repeatedly logging in, or because it seemed weird to the spotify crew that I would search for the same query all the time. I don't really know what the problem is caused by. There are no emails or warnings sent to the address connected to the account. The problem has lasted for a while now, so it seems like it's not going away at first.
Additional details
log_message tells me there is a ChannelError(4, 0, search). I have also seen ChannelError(5, 0, search), but only once.
I can still play music from the official Spotify desktop client for Windows.
I have an earlier version of the program, before I rewrote it to get a bit more structure, that works. The same API key and same credentials are used in both programs, so that excludes a ban. The rewrite does log in, but no results are returned from searching. In the old version, I get a lot of results. All working. I have rebooted the Raspberry Pi several times, but that doesn't seem to help.
If you need any code or other information, I'll be happy to share. Just point out what's needed, because the code is split over a lot of files.
Well, if your old one is working then the problem will be in your rewrite. Don't pay too much notice to the error messages, they're pretty much par for the course, and can be triggered by something as benign as a cache miss. Unless you're actually getting an error callback somewhere, the log messages are meaningless.
As for your problem, I can't really make any guesses without seeing your code. One thing to check and is the most common course of a permanent error is to make sure you're actually logged in. The login process is asynchronous, and any functionality that requires you to be logged in (searching is one of them) will fail before login is completed.

Resources