Dear all, I am developing a web harvesting server which requires regularly website parsing. Since I use Mac 10.8 as my development environment, I try to use Launchd to routinely wake up my parser. My parser was a bash script which has only two lines: 1. cd $HOME/ProjectFolder 2. bundle exec rake dailyTask:dataParse When directly execute the script under Terminal, there is no problem. However, when this script is called by Launchctl, it produces errors, which looks like: /usr/local/Cellar/ruby/2.0.0-p195/bin/bundle exec rake dailyTask:dataParse --trace >> /tmp/cron-test.out /usr/local/Cellar/ruby/2.0.0-p195/lib/ruby/gems/2.0.0/gems/mysql2-0.3.13/lib/mysql2/mysql2.bundle: [BUG] Segmentation fault ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0] I look around for segmentation fault problem. Most posts suggests RVM or rbenv to swap Ruby version. None of the posts looks relevant to me since I can directly execute under terminal environment. OS: MAC OSX 10.8.4 Ruby version: 2.0.0p195 Bundler version: 1.3.5 Rake version: 10.0.4 The relevant part of my plist file is as following: <key>ProgramArguments</key> <array> <string>/bin/bash</string> <string>crontab-test.sh</string> </array> Hope someone can give me the right direction to continue. Many thanks! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e22178a3c94bbc3fee8af29169a8ea0f%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
On 29 August 2013 11:33, Shawn h. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Dear all, > I am developing a web harvesting server which requires regularly > website parsing. Since I use Mac 10.8 as my development environment, I > try to use Launchd to routinely wake up my parser. My parser was a bash > script which has only two lines: > 1. cd $HOME/ProjectFolderJust a thought, is $HOME valid when this is run? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLt4R3xEMS19zU6br52dnB_9n4XN8e2NjxVG0t6S9mPi1A%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Colin Law wrote in post #1119927:> On 29 August 2013 11:33, Shawn h. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Dear all, >> I am developing a web harvesting server which requires regularly >> website parsing. Since I use Mac 10.8 as my development environment, I >> try to use Launchd to routinely wake up my parser. My parser was a bash >> script which has only two lines: >> 1. cd $HOME/ProjectFolder > > Just a thought, is $HOME valid when this is run? > > ColinThanks for reply. I checked the path and it is ok. I test directly with no variable and the result is identical. I did some other experiments. In the batch script, I can successfully run bundle exec rake --version or bundle exec rake -h However, when I run bundle exec rake -T, it would produce exact segmentation error as follows: crontab-test.sh: line 6: 29245 Abort trap: 6 /usr/local/Cellar/ruby/2.0.0-p195/bin/bundle exec rake -T >> /tmp/cron-test.out /usr/local/Cellar/ruby/2.0.0-p195/lib/ruby/gems/2.0.0/gems/mysql2-0.3.13/lib/mysql2/mysql2.bundle: [BUG] Segmentation fault ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0] I don''t understand when bundle exec rake would encounter errors for mysql2 bundle, especially when it reports ruby 1.8.7 while I am sure I use 2.0.0p195. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3b76549a976a3780ce90fed4a71d5722%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
Colin Law wrote in post #1119927:> On 29 August 2013 11:33, Shawn h. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Dear all, >> I am developing a web harvesting server which requires regularly >> website parsing. Since I use Mac 10.8 as my development environment, I >> try to use Launchd to routinely wake up my parser. My parser was a bash >> script which has only two lines: >> 1. cd $HOME/ProjectFolder > > Just a thought, is $HOME valid when this is run? > > ColinThanks for reply. I checked the path and it is ok. I test directly with no variable and the result is identical. I did some other experiments. In the batch script, I can successfully run bundle exec rake --version or bundle exec rake -h However, when I run bundle exec rake -T, it would produce exact segmentation error as follows: crontab-test.sh: line 6: 29245 Abort trap: 6 /usr/local/Cellar/ruby/2.0.0-p195/bin/bundle exec rake -T >> /tmp/cron-test.out /usr/local/Cellar/ruby/2.0.0-p195/lib/ruby/gems/2.0.0/gems/mysql2-0.3.13/lib/mysql2/mysql2.bundle: [BUG] Segmentation fault ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0] I don''t understand why bundle exec rake would encounter errors for mysql2 bundle, especially when it reports ruby 1.8.7 while I am sure I use 2.0.0p195. Does it imply when launchd exec the bash script, it has its own environment which uses ruby 1.8.7? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3dd763af299118e12e8885aa789502f0%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
On Aug 29, 2013, at 5:33 AM, Shawn h. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Dear all, > I am developing a web harvesting server which requires regularly > website parsing. Since I use Mac 10.8 as my development environment, I > try to use Launchd to routinely wake up my parser. My parser was a bash > script which has only two lines: > 1. cd $HOME/ProjectFolder > 2. bundle exec rake dailyTask:dataParse > > When directly execute the script under Terminal, there is no > problem. However, when this script is called by Launchctl, it produces > errors, which looks like: > > /usr/local/Cellar/ruby/2.0.0-p195/bin/bundle exec rake > dailyTask:dataParse --trace >> /tmp/cron-test.out > /usr/local/Cellar/ruby/2.0.0-p195/lib/ruby/gems/2.0.0/gems/mysql2-0.3.13/lib/mysql2/mysql2.bundle: > [BUG] Segmentation fault > ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0] > > I look around for segmentation fault problem. Most posts suggests > RVM or rbenv to swap Ruby version. None of the posts looks relevant to > me since I can directly execute under terminal environment. > > OS: MAC OSX 10.8.4 > Ruby version: 2.0.0p195 > Bundler version: 1.3.5 > Rake version: 10.0.4 > > The relevant part of my plist file is as following: > <key>ProgramArguments</key> > <array> > <string>/bin/bash</string> > <string>crontab-test.sh</string> > </array> > > Hope someone can give me the right direction to continue. Many > thanks!Using launchd is much like using cron on linux: there is no (or barely any) predefined environment like you have in Terminal. Thus you have to provide all the information that will be needed to make sure your script runs correctly. This is includes running whatever is needed to set the right version and source of ruby for that launcher. Since OS/X ships with 1.8.7 as the system ruby, that is the one used by launchd. If you require a different version (and you do if you want to use any gems you''ve installed for that different version), you have to wrap your ruby script in something that will initialize the environment. I haven''t tried this, but it might just be enough to add —init-file /Users/youruser/.bash_profile to the argument list above, depending on how you have things configured. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4AAE71A9-EB88-4992-8512-FD0D98CD10E7%40gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
tamouse m. wrote in post #1119977:> On Aug 29, 2013, at 5:33 AM, Shawn h. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > Using launchd is much like using cron on linux: there is no (or barely > any) predefined environment like you have in Terminal. Thus you have to > provide all the information that will be needed to make sure your script > runs correctly. This is includes running whatever is needed to set the > right version and source of ruby for that launcher. > > Since OS/X ships with 1.8.7 as the system ruby, that is the one used by > launchd. If you require a different version (and you do if you want to > use any gems you''ve installed for that different version), you have to > wrap your ruby script in something that will initialize the environment. > I haven''t tried this, but it might just be enough to add init-file > /Users/youruser/.bash_profile to the argument list above, depending on > how you have things configured.Thanks! I think this is the right direction and I am gonna give it a try. I just test adding ruby path to both /etc/launchd.conf and /etc/paths. After rebooting, I thought it would work but not. Launchd still does not recognize the correct ruby version. I will report once it works. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4ff6d7e4a42cd98e7e9bcccb51f6d3e0%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.