Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Launchd with Mavericks and Ruby

Upgraded to Mavericks and now launchd / Lingon is unable to launch Ruby scripts. I have the files set to be executable (using chmod +x), and have the first lines set to

#!/usr/bin/ruby

However, I keep getting the following error in Console:

com.apple.launchd.peruser.501[169] (craig.logging[754]): Exited with code: 1

That is a permissions error, but I have no idea what permissions to fix or change. The script runs fine in terminal with ruby.

This is driving me nuts.

Update: the Ruby scripts that are causing the problem write their output to another file, for example, in my Dropbox. But I'm running the launchd files as myself who has admin privileges to write to those files. No idea what's going wrong...]

Update 2: Have started using Applescript to launch the Terminal and run my scripts, but this is pretty clumsy and inelegant. Anyone else have any insight to why launchd won't run scripts that write their output to files? Or is anyone having success with scripts that do?

Update 3: The failures were being triggered because of encoding issues. I had to specifically set file.open(path/to/file, encoding: 'UTF-8') for the scripts to work.

Thanks everyone.

like image 917
craigeley Avatar asked Oct 25 '13 21:10

craigeley


2 Answers

I had this same problem on a Mavericks box with several Ruby scripts I have set to run at various intervals. I found that while this machine that had the OS upgraded was failing, my new MacBook Pro that shipped with Mavericks could schedule the same scripts off launchd just fine. I ended up erasing the machine and reinstalling Mavericks (and everything else) from scratch, and then scheduling the scripts began to work.

Not the most delicate answer, I know, but Worked For Me™.

like image 168
MacPrince Avatar answered Oct 22 '22 05:10

MacPrince


I'm still not entirely sure why, but the permissions errors were being triggered because of encoding issues. I had to specifically do this:

File.open(path/to/file, encoding: 'UTF-8')     

for the scripts to work.

Thanks everyone for your help.

like image 29
craigeley Avatar answered Oct 22 '22 03:10

craigeley