Friday, February 28, 2014

GNU Cash (Perl Finance::Quote) Failed to Retrieve Stock Price Quotes

I have been GNU Cash for a couple of years. I set up Perl Finance::Quote to automatically update stock price quotes. GNU Cash suddenly reports that it cannot retrieve stock price quotes.

Using this opportunity, I updated GNU Cash to 2.6.1 and reinstalled Finance::Quote module. However, the problem remains.

I am running GNU Cash on both a Windows XP box and a Windows 8.1 box. On both machines I observe the same problem. The detailed problem description is as follows,

(1) Version of Perl

C:\>perl --version
This is perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x86-multi-
thread (with 1 registered patch, see perl -V for more detail)

Copyright 1987-2012, Larry Wall

Binary build 1603 [296746] provided by ActiveState http://www.ActiveState.com
Built Mar 13 2013 11:29:21


(2) Perl Finance::Quote with GNU Cash

C:\Program Files\gnucash\bin>perl gnc-fq-check
("1.18" "vwd" "yahoo_nz" "australia" "amfiindia" "usfedbonds" "canada" "yahoo" "
adig" "bux" "aiahk" "bsero" "yahoo_australia" "unionfunds" "lerevenu" "asia" "ts
x" "sixfunds" "indiamutual" "bse" "hungary" "known_currencies" "fidelity_direct"
 "goldmoney" "tdwaterhouse" "trustnet" "ftportfolios_direct" "cominvest" "mornin
gstar" "ftportfolios" "tdefunds" "hu" "za" "fundlibrary" "stockhousecanada_fund"
 "yahoo_europe" "platinum" "maninv" "tsp" "financecanada" "usa" "france" "trowep
rice" "nasdaq" "bmonesbittburns" "yahoo_asia" "tiaacref" "troweprice_direct" "se
b_funds" "yahoo_brasil" "greece" "fidelity" "fetch_live_currencies" "romania" "d
wsfunds" "finland" "hex" "brasil" "asegr" "deka" "nyse" "canadamutual" "asx" "fi
nanzpartner" "fool" "dutch" "uk_unit_trusts" "sixshares" "nzx" "aex" "nz" "vangu
ard" "europe" "bourso") 
 

(3) Problem: when Finance::Quote in GNU Cash is being installed, the installation script actually reports an error despite that it states the process was successful. See below,

C:\Program Files\gnucash\bin>install-fq-mods.cmd
GNU Cash
......
* Run gnc-fq-helper

Use of uninitialized value within %info in string eq at C:/Perl/site/lib/Finance
/Quote/Yahoo/Base.pm line 222, <> line 1.
Use of uninitialized value $info{"Missing Symbols List.\34p_change"} in substitu
tion (s///) at C:/Perl/site/lib/Finance/Quote/Yahoo/Base.pm line 238, <> line 1.

Use of uninitialized value within %info in pattern match (m//) at C:/Perl/site/l
ib/Finance/Quote/Yahoo/Base.pm line 243, <> line 1.
(#f)

* Installation succeeded

(4) gnc-fq-dump and gnc-fq-helper fails. Now I try GNU Cash's gnc-fq-dump, it actually fails. It is perhaps the result of some issue with Active Perl. For instance,

C:\Program Files\gnucash\bin>echo (yahoo "TGT") | perl gnc-fq-helper
Use of uninitialized value within %info in string eq at C:/Perl/site/lib/Finance
/Quote/Yahoo/Base.pm line 222, <> line 1.
Use of uninitialized value $info{"Missing Symbols List.\34p_change"} in substitu
tion (s///) at C:/Perl/site/lib/Finance/Quote/Yahoo/Base.pm line 238, <> line 1.

Use of uninitialized value within %info in pattern match (m//) at C:/Perl/site/l
ib/Finance/Quote/Yahoo/Base.pm line 243, <> line 1.
(#f)

which is the same error I saw during the installation of the Finance::Quote module.

I attempted a few methods neither of which works. The methods I attempted were.
(1) Completely remove GNU Cash and Active Perl and reinstall GNU Cash and Active Perl
(2) Update Perl modules using "cpan -r".

What actually works is to replace Active Perl by Strawberry Perl. I obtain this solution by reading " install-fq-mods.cmd that actually attempts to install Strawberry Perl if perl cannot be found.

Here is the steps that leads to a success.
(1). Completely remove Active Perl. There is no need to reinstall GNU Cash. So leave GNU Cash alone
(2). Download and install Strawberry Perl
(3). Install Perl Finance::Quote module


C:\Program Files\gnucash\bin>install-fq-mods.cmd

(4). Test the functionality using gnc-fq-helper

C:\Program Files\gnucash\bin>echo (yahoo "JPM") | perl gnc-fq-helper
(("JPM" (symbol . "JPM") (gnc:time-no-zone . "2014-02-27 16:01:00") (last . 56.6
9) (currency . "USD")))

(5). Test the functionality using gnc-fq-dump

C:\Program Files\gnucash\bin>perl gnc-fq-dump nyse JPM TGT
Finance::Quote fields Gnucash uses:
    symbol: JPM                  <=== required
      date: 02/27/2014           <=== required
  currency: USD                  <=== required
      last: 56.69                <=\
       nav:                      <=== one of these
     price: 56.69                <=/
  timezone:                      <=== optional
=====

Finance::Quote fields Gnucash uses:
    symbol: TGT                  <=== required
      date: 02/27/2014           <=== required
  currency: USD                  <=== required
      last: 60.66                <=\
       nav:                      <=== one of these
     price: 60.66                <=/
  timezone:                      <=== optional

It works.
By the way, the information about version of the Perl and Finance::Quote are as follows,

C:\Program Files\gnucash\bin>perl --version

This is perl 5, version 18, subversion 2 (v5.18.2) built for MSWin32-x86-multi-t
hread-64int

Copyright 1987-2013, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.


C:\Program Files\gnucash\bin>perl gnc-fq-check
("1.20" "bitcoin_gbp" "known_currencies" "bsero" "bitcoin_sek" "fetch_live_curre
ncies" "hu" "hex" "bitcoin_nok" "australia" "bitcoin_cad" "tdefunds" "mtgox_jpy"
 "fool" "bitcoin_hkd" "yahoo_europe" "mtgox_chf" "finanzpartner" "europe" "bitco
in_cny" "ftportfolios_direct" "unionfunds" "bitcoin_thb" "ftportfolios" "yahoo_b
rasil" "uk_unit_trusts" "lerevenu" "aiahk" "bmonesbittburns" "mtgox_hkd" "sixsha
res" "yahoo_nz" "mtgox_nok" "deka" "za" "maninv" "nasdaq" "bourso" "tsx" "bitcoi
n_jpy" "financecanada" "mtgox_dkk" "dwsfunds" "cominvest" "sixfunds" "bitcoin_sg
d" "mtgox_eur" "asegr" "mtgox_usd" "bitcoin_usd" "fidelity" "stockhousecanada_fu
nd" "bitcoin_chf" "asx" "fundlibrary" "bitcoin_pln" "mtgox_aud" "nzx" "amfiindia
" "nz" "romania" "bitcoin_rub" "yahoo" "nyse" "tiaacref" "canada" "asia" "usa" "
greece" "france" "hungary" "mtgox_pln" "fidelity_direct" "bse" "yahoo_asia" "bux
" "troweprice_direct" "mtgox_sgd" "morningstarjp" "platinum" "aex" "mtgox_cny" "
mtgox_sek" "yahoo_australia" "mtgox_rub" "usfedbonds" "mtgox_nzd" "bitcoin_dkk"
"brasil" "trustnet" "vanguard" "adig" "vwd" "mtgox_cad" "bitcoin_eur" "canadamut
ual" "finland" "bitcoin_nzd" "troweprice" "dutch" "indiamutual" "tdwaterhouse" "
tsp" "seb_funds" "goldmoney" "morningstar" "mtgox_thb" "bitcoin_aud" "mtgox_gbp"
)

which means that it is probably that Finance::Quote 1.20 works while 1.18 has some problem.

Tuesday, February 18, 2014

Redmine Error: Phusion Passenger Watchdog Failed to Start

Having upgraded a few package including Redmine and Ruby on Rail, my redmine host failed to start. I am running a Apache web server for the Redmine. When I browse the Redmine host, the error message returned in the web browser is


Application error
Rails application failed to start properly

The Redmine's production log at the redmine/log directory indicates nothing is generated in the log, which means Redmine does not even run. To verify that Redmine itself is actually OK, run it from the command line,

ruby script/rails server webrick -e production

Then point the browser to http://localhost:3000/. The Redmine server runs OK. Checking Apache's error log (the error_log file) a little bit closely, the error message looks the following,

[pid=9135 thr=140212503205888 file=ext/common/LoggingAgent/Main.cpp:287 
time=2014-02-01 03:29:02.699 ]: *** ERROR: Cannot stat 
'/var/log/passenger-analytics': Permission denied (13)
     (empty)
[Sun Feb 01 03:29:02 2014] [error] *** Passenger could not be initialized 
because of this error: Unable to start the Phusion Passenger watchdog 
because it encountered the following error during startup: Unable to start 
the Phusion Passenger logging agent: it seems to have crashed during startup 
for an unknown reason, with exit code 1
At the same time, the redmine_error.log that belongs to the virtual host in which the Redmine runs shows something similar to,

[Mon Feb 01 22:55:15 2014] [warn] [client 10.0.0.1] (104)Connection reset by peer: mod_fcgid: 
 error reading data from FastCGI server
[Mon Feb 01 22:55:15 2014] [error] [client 10.0.0.1] Premature end of script headers: 
 dispatch.fcgi

Now it becomes clearer that the problem may be that Phusion Passenger cannot access the directory /var/log/passenger-analytics. After I give sufficient permission to the directory as follows, the Phusion Passenger starts OK and the Redmine runs normally.

chown -R apache:apache passenger-analytics
chmod -R 750 apache:apache passenger-analytics
chcon system_u:object_r:httpd_sys_content_t:s0  passenger-analytics

The last step is necessary since SeLinux is enabled in my case. A second, perhaps a better approach is to route any analytics logs to Redmine's log directory, for which, I added the following line to the Redmine's Apache configuration file, in my case /etc/httpd/conf.d/redmine.conf,


<VirtualHost *:80>
   ......
   PassengerAnalyticsLogDir REDMINE_ROOT/log
   ......
</VirtualHost> 

In the above, replacing REDMINE_ROOT by the root directory of the Redmine installation, such as /home/usr/redmine etc. In this case, there is not need to change the directory permission and ownership since the Redmine directory should already have had correct permission and SeLinux context. In addition, you can consolidate the log files in a place that you like.