You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Paul Davis <pa...@gmail.com> on 2014/02/03 07:21:48 UTC
Re: Cannot get os_daemon api to function
I reckon your stdout is buffered. Try adding an fflush call after the
second fputs.
On Sat, Feb 1, 2014 at 11:40 PM, Scott Weber <sc...@sbcglobal.net> wrote:
> I am using version 1.5. I can get the daemon to start, but there does not appear to be any communication on stdin/stdout.
>
> Below are my settings, and a simple C example. I would expect this simple code to log a message, then give me a reply of the config settings. However nothing happens.
>
> Couch does restart the daemon if I change a config setting under [os_daemons]. And the settings do appear in the config page of Futon.
>
> The example program does also exit when Couch closes the stdin connection, as expected.
>
>
> Any advice is appreciated.
>
> -Scott
>
>
> CONFIG SETTINGS:
> [log]
> level = info
>
> [os_daemons]
>
> my_test = c:/path/nativeDaemon/debug/NativeDaemon.exe
>
> [my_test]
> Value = 10,002
> OtherValue = The other value
>
>
>
> Actual C code (uses Windows Sleep, otherwise is agnostic) :
>
>
> int main() {
> char buffer[257];
>
> LogMessage("\nSTART:", "Daemon Startup"); // My own log file to disk
> Sleep(3000);
>
> fputs("[\"log\",{\"log\" : \"The process started\"}]\n",stdout);
> fputs("[\"get\", \"os_daemons\"]\n",stdout);
>
> do {
> fgets(buffer,256,stdin);
> if (feof(stdin)) {
> LogMessage("\nCLOSE:","Closed STDIN"); // This does exit when expected
> break;
> }
>
>
> // etc... into loop.
Re: Cannot get os_daemon api to function
Posted by Alexander Shorin <kx...@gmail.com>.
Well, it doesn't says that $MESG should be only JSON object:
> Where $MESG is any arbitrary JSON.
but this statement also includes it like JSON string, number, and
other types. I'll fix it to make it more concrete.
--
,,,^..^,,,
On Mon, Feb 3, 2014 at 6:17 PM, Scott Weber <sc...@sbcglobal.net> wrote:
> Yup. That worked.
>
> I am trying to pass a JSON object because that is what the doc says.
> "The process started" is not a valid JSON object, although the doc says that $MESG is any JSON object. It does not say that $MESG is only a non-JSON string.
>
> Anyway, live and learn.
>
>
>
>
> ________________________________
> From: Alexander Shorin <kx...@gmail.com>
> To: "user@couchdb.apache.org" <us...@couchdb.apache.org>
> Sent: Monday, February 3, 2014 8:06 AM
> Subject: Re: Cannot get os_daemon api to function
>
>
> On Mon, Feb 3, 2014 at 5:52 PM, Scott Weber <sc...@sbcglobal.net> wrote:
>>
>> Now I get an 'Invalid Log Message' when I try to log. My log message is exactly:
>> ["log",{"log" : "The process started"}]
>
> Have you tried to pass just "The process started" string without
> object wrapper? I wonder why you trying to do this, since there is no
> much reasons for it.
>
>> There’s also an API for adding messages to CouchDB’s logs. Its simply:
>> ["log", $MESG]\n
>> Where $MESG is any arbitrary JSON. There is no response from this command. As
>> with the config API, the trailing \n represents a newline byte
>
> Probably "any arbitrary JSON" is too greedy definition since the only
> acceptable JSON try is a string one.
>
> --
> ,,,^..^,,,
Re: Cannot get os_daemon api to function
Posted by Scott Weber <sc...@sbcglobal.net>.
Yup. That worked.
I am trying to pass a JSON object because that is what the doc says.
"The process started" is not a valid JSON object, although the doc says that $MESG is any JSON object. It does not say that $MESG is only a non-JSON string.
Anyway, live and learn.
________________________________
From: Alexander Shorin <kx...@gmail.com>
To: "user@couchdb.apache.org" <us...@couchdb.apache.org>
Sent: Monday, February 3, 2014 8:06 AM
Subject: Re: Cannot get os_daemon api to function
On Mon, Feb 3, 2014 at 5:52 PM, Scott Weber <sc...@sbcglobal.net> wrote:
>
> Now I get an 'Invalid Log Message' when I try to log. My log message is exactly:
> ["log",{"log" : "The process started"}]
Have you tried to pass just "The process started" string without
object wrapper? I wonder why you trying to do this, since there is no
much reasons for it.
> There’s also an API for adding messages to CouchDB’s logs. Its simply:
> ["log", $MESG]\n
> Where $MESG is any arbitrary JSON. There is no response from this command. As
> with the config API, the trailing \n represents a newline byte
Probably "any arbitrary JSON" is too greedy definition since the only
acceptable JSON try is a string one.
--
,,,^..^,,,
Re: Cannot get os_daemon api to function
Posted by Alexander Shorin <kx...@gmail.com>.
On Mon, Feb 3, 2014 at 5:52 PM, Scott Weber <sc...@sbcglobal.net> wrote:
>
> Now I get an 'Invalid Log Message' when I try to log. My log message is exactly:
> ["log",{"log" : "The process started"}]
Have you tried to pass just "The process started" string without
object wrapper? I wonder why you trying to do this, since there is no
much reasons for it.
> There’s also an API for adding messages to CouchDB’s logs. Its simply:
> ["log", $MESG]\n
> Where $MESG is any arbitrary JSON. There is no response from this command. As
> with the config API, the trailing \n represents a newline byte
Probably "any arbitrary JSON" is too greedy definition since the only
acceptable JSON try is a string one.
--
,,,^..^,,,
Re: Cannot get os_daemon api to function
Posted by Scott Weber <sc...@sbcglobal.net>.
Yes, it was buffering. That got me closer. Thanks.
Now I get an 'Invalid Log Message' when I try to log. My log message is exactly:
["log",{"log" : "The process started"}]
( which I coded as strcpy(buffer,"[\"log\",{\"log\" : \"The process started\"}]\n"); )
Because the doc says the message must be a JSON. As shown below:
----------------------------------------------------------------
7.3.2. Logging API
There’s also an API for adding messages to CouchDB’s logs. Its simply:
["log", $MESG]\n
Where $MESG is any arbitrary JSON. There is no response from this command. As
with the config API, the trailing \n represents a newline byte.-----------------------------------------------------------------
The error that is reported is:
-------------------------------------------------------------
[info] [<0.36.0>] Apache CouchDB has started on http://0.0.0.0:5984/
[error] [<0.139.0>] Invalid log message from daemon "my_test": {[{<<"log">>,
<<"The process started">>}]}
-------------------------------------------------------------
Any idea what it is really expecting?
-Scott
________________________________
From: Paul Davis <pa...@gmail.com>
To: "user@couchdb.apache.org" <us...@couchdb.apache.org>; Scott Weber <sc...@sbcglobal.net>
Sent: Monday, February 3, 2014 12:21 AM
Subject: Re: Cannot get os_daemon api to function
I reckon your stdout is buffered. Try adding an fflush call after the
second fputs.
On Sat, Feb 1, 2014 at 11:40 PM, Scott Weber <sc...@sbcglobal.net> wrote:
> I am using version 1.5. I can get the daemon to start, but there does not appear to be any communication on stdin/stdout.
>
> Below are my settings, and a simple C example. I would expect this simple code to log a message, then give me a reply of the config settings. However nothing happens.
>
> Couch does restart the daemon if I change a config setting under [os_daemons]. And the settings do appear in the config page of Futon.
>
> The example program does also exit when Couch closes the stdin connection, as expected.
>
>
> Any advice is appreciated.
>
> -Scott
>
>
> CONFIG SETTINGS:
> [log]
> level = info
>
> [os_daemons]
>
> my_test = c:/path/nativeDaemon/debug/NativeDaemon.exe
>
> [my_test]
> Value = 10,002
> OtherValue = The other value
>
>
>
> Actual C code (uses Windows Sleep, otherwise is agnostic) :
>
>
> int main() {
> char buffer[257];
>
> LogMessage("\nSTART:", "Daemon Startup"); // My own log file to disk
> Sleep(3000);
>
> fputs("[\"log\",{\"log\" : \"The process started\"}]\n",stdout);
> fputs("[\"get\", \"os_daemons\"]\n",stdout);
>
> do {
> fgets(buffer,256,stdin);
> if (feof(stdin)) {
> LogMessage("\nCLOSE:","Closed STDIN"); // This does exit when expected
> break;
> }
>
>
> // etc... into loop.