Starting Sync Gateway

502 views
Skip to first unread message

s.ande...@gmail.com

unread,
Jul 29, 2014, 10:12:11 PM7/29/14
to mobile-c...@googlegroups.com
I have installed Couchbase Server and Sync Gateway locally on my Mac. What I am trying to do is push the data in a Couchbase Lite database in an app to a Couchbase Server using Sync Gateway.

First baby step: attempt to get the Sync Gateway configured and running.

Using Couchbase Server's admin console I created a new bucket (e.g. mybucket). Confused about databases and buckets...I would have thought I would create a database, but there seems to be no option to do this so I created a bucket instead.

Created a config file for the Sync Gateway:

{
  "interface":"4984",
  "adminInterface":"4985",
  "databases":{
    "mybucket":{
      "server":"http://localhost:8091",
      "sync":`function(doc) { channel(doc.channels);}`
    }
  }
}

macbook:bin me$ ./sync_gateway /some/path/sync_gateway_config.json
09:54:23.344462 ==== Couchbase Sync Gateway/1.00 (1.0.0-23; commit 46d2fdaf) ====
09:54:23.344560 Configured Go to use all 4 CPUs; setenv GOMAXPROCS to override this
09:54:23.344567 Configured MaxFileDescriptors (RLIMIT_NOFILE) to 5000
09:54:23.344579 Opening db /mybucket as bucket "mybucket", pool "default", server <http://localhost:8091>
09:54:23.344611 Opening Couchbase database mybucket on <http://localhost:8091>
09:54:23.389506 Recomputing document channels...
09:54:23.410012 Starting admin server on 4985
09:54:23.411217 Starting server on 4984 ...
09:54:23.411334 FATAL: Failed to start HTTP server on 4985: listen tcp: missing port in address 4985 -- rest.(*ServerConfig).serve() at config.go:346

What am I doing wrong?

One additional complication: The account I am logged in as on my Mac is a "standard" account. To install Couchbase Server successfully I had to switch to an "Administrator" account. As such, I run Couchbase Server and Sync Gateway from the command line, first logging in as an administrator using su - <admin account>.

Rajagopal V

unread,
Jul 29, 2014, 11:46:51 PM7/29/14
to mobile-c...@googlegroups.com
Change the config file to have
"interface":":4984",
 "adminInterface":":4985",

(Note: Added a colon to indicate the port number), This is also explained in the help, if you try ./sync_gateway --help

Please note that these two are anyway not required as those are the default ports for the regular and admin interfaces.

Regards
Raja

Jens Alfke

unread,
Jul 30, 2014, 12:20:25 AM7/30/14
to mobile-c...@googlegroups.com

On Jul 29, 2014, at 7:12 PM, s.ande...@gmail.com wrote:

Using Couchbase Server's admin console I created a new bucket (e.g. mybucket). Confused about databases and buckets...I would have thought I would create a database, but there seems to be no option to do this so I created a bucket instead.

For historical reasons Couchbase Server calls them “buckets” instead of “databases”. Same thing — they’re a namespace for mapping keys to documents.

One additional complication: The account I am logged in as on my Mac is a "standard" account. To install Couchbase Server successfully I had to switch to an "Administrator" account. As such, I run Couchbase Server and Sync Gateway from the command line, first logging in as an administrator using su - <admin account>.

There isn’t really any ‘installation’ step for Couchbase Server on a Mac; it’s just an application that you can put anywhere. What was the problem with using it from a non-admin account?

And there’s no need to run Sync Gateway from an admin account (whether or not you run Couchbase Server that way.)

If it’s more convenient, you can use the built-in ‘Walrus’ storage engine while you’re experimenting; it doesn’t require having Couchbase Server at all. Just edit the config and change the server URL to ‘walrus:’ (for a non-persistent database) or ‘walrus:/path/to/storage/dir/‘.

—Jens

s.ande...@gmail.com

unread,
Jul 30, 2014, 7:43:32 AM7/30/14
to mobile-c...@googlegroups.com
On Wednesday, 30 July 2014 12:20:25 UTC+8, Jens Alfke wrote:

One additional complication: The account I am logged in as on my Mac is a "standard" account. To install Couchbase Server successfully I had to switch to an "Administrator" account. As such, I run Couchbase Server and Sync Gateway from the command line, first logging in as an administrator using su - <admin account>.

There isn’t really any ‘installation’ step for Couchbase Server on a Mac; it’s just an application that you can put anywhere. What was the problem with using it from a non-admin account?

It doesn't start from my non-admin account - message is displayed "You can't open the application "%@" because it may be damaged or incomplete." Yet Couchbase starts successfully from if I start it from the command line using an administrator account. In addition not all the menu options under the Couchbase icon work, e.g. Open Admin Console or About Couchbase Server.

And there’s no need to run Sync Gateway from an admin account (whether or not you run Couchbase Server that way.)

If it’s more convenient, you can use the built-in ‘Walrus’ storage engine while you’re experimenting; it doesn’t require having Couchbase Server at all. Just edit the config and change the server URL to ‘walrus:’ (for a non-persistent database) or ‘walrus:/path/to/storage/dir/‘.

Thanks for the walrus info. I installed Couchbase Server and Sync Gateway locally as I expect I will use both in production/when my app is released.

Steve

s.ande...@gmail.com

unread,
Jul 30, 2014, 10:22:35 AM7/30/14
to mobile-c...@googlegroups.com
Excellent, thanks Raja.

s.ande...@gmail.com

unread,
Aug 5, 2014, 10:10:22 PM8/5/14
to mobile-c...@googlegroups.com
Further to my original post...

I now have Couchbase Server and Sync Gateway running. Using the demo app GrocerySync I am attempting to sync it with an empty grocery-sync database/bucket I created on Couchbase Server.

However, the URL http://mycomputer.local:4984/grocery-sync/ does not work, the app displays the error message "Error syncing 404 not_found." The Sync Gateway reports the same, "404 no such database grocery-sync".

NB: mycomputer was replaced with the actual name of my computer.

My Sync Gateway config file looks as follows:


{
  "interface":":4984",
  "adminInterface":":4985",
  "databases":{
    "sync_gateway":{
      "server":"http://stevesmacbook.local:8091",
      "bucket":"grocery-sync",
      "sync":`function(doc) {channel(doc.channels);}`
    }
  }
}

Any ideas?

Raja

unread,
Aug 5, 2014, 11:25:04 PM8/5/14
to mobile-c...@googlegroups.com
On Wed, Aug 6, 2014 at 7:40 AM, <s.ande...@gmail.com> wrote:
{
  "interface":":4984",
  "adminInterface":":4985",
  "databases":{
    "sync_gateway":{
      "server":"http://stevesmacbook.local:8091",
      "bucket":"grocery-sync",
      "sync":`function(doc) {channel(doc.channels);}`
    }
  }
}


The name of the database as per your configuration above is "sync_gateway", not "grocery-sync", which is probably why its erroring with a 404. You need to provide 2 buckets, one for sync_gateway and one for grocery-sync, something like this:

{
   "databases":{
        "sync_gateway":{
                "server":"http://localhost:8091",
                "bucket":"sync_gateway"
        },
        "grocery-sync": {
                "server":"http://localhost:8091",
                "bucket":"grocery-sync",
                "sync": `function(doc, oldDoc) { channel ("public");}`,
        }
  }

The sync_gateway bucket is for some internal metadata that the sync gateway stores and then your actual bucket is for custom data.

Note: I have left off some details from your original configuration since they were the defaults anyway(for interface and admininterface)

Regards
Raja

--
Raja
rajasaur at gmail.com

Jens Alfke

unread,
Aug 7, 2014, 7:09:29 PM8/7/14
to mobile-c...@googlegroups.com

On Aug 5, 2014, at 8:25 PM, Raja <raja...@gmail.com> wrote:

You need to provide 2 buckets, one for sync_gateway and one for grocery-sync, something like this:

No you don't! You only need the grocery-sync bucket.

—Jens

s.ande...@gmail.com

unread,
Aug 9, 2014, 2:15:10 AM8/9/14
to mobile-c...@googlegroups.com

Correct. The following config file seems to work:

{
    "databases":{
        "grocery-sync":{

            "server":"http://stevesmacbook.local:8091",
            "bucket":"grocery-sync",
            "users":{
                "GUEST":{
                    "disabled":false,
                    "admin_channels":["*"]
                }
            }
        }
    }
}

Remote Couchbase URL: http://stevesmacbook.local:4984/grocery-sync/

Output from Sync Gateway startup:

18:00:18.266755 ==== Couchbase Sync Gateway/1.00 (1.0.0-23; commit 46d2fdaf) ====
18:00:18.266824 Configured Go to use all 4 CPUs; setenv GOMAXPROCS to override this
18:00:18.266830 Configured MaxFileDescriptors (RLIMIT_NOFILE) to 5000
18:00:18.266841 Opening db /grocery-sync as bucket "grocery-sync", pool "default", server <http://stevesmacbook.local:8091>
18:00:18.266871 Opening Couchbase database grocery-sync on <http://stevesmacbook.local:8091>
18:00:18.590817 Using default sync function 'channel(doc.channels)' for database "grocery-sync"
18:00:18.614809     Reset guest user to config
18:00:18.614824 Starting admin server on 127.0.0.1:4985
18:00:18.616134 Starting server on :4984 ...

Reply all
Reply to author
Forward
0 new messages