Using sync_gateway

hello,

I’m now trying to gather information about use of sync_gateway. I have 2 couchbase servers which are not on my local and I created sync_gateway bucket in both. I filled my default buckets on both servers with MVC.

I read that I need to create a config file in json and call it. But I don’t understand where am I gonna create it and how to call it because I can’t write anything on here :

I thought that would be some kind of platform to write code on, isn’t it?

Also when I try to open http://MYPORT:4984/sync_gateway/ on browser it says:

{
error: "not_found",
reason: "no such database "sync_gateway""
}

What am I gonna do? How am I gonna create a config file and where am gonna call it?

Thanks

@HandeBc

If you installed Sync gateway from an installer, it should have created a Windows service to start sync gateway automatically.

If this is the case there will be a configuration file here:

C:\Program Files (x86)\Couchbase\serviceconfig.json

with the following content:

{
	"log": ["HTTP+"],
	"adminInterface": "127.0.0.1:4985",
	"interface": "0.0.0.0:4984",
	"databases": {
		"db": {
			"server": "walrus:data",
			"users": {
				"GUEST": {"disabled": false, "admin_channels": ["*"] }
			}
		}
	}
}

If you try the following URL do you get a valid response:

http://MYHOST:4984/db/

You can edit the serviceconfig.json to point to your Couchbase Server Buckets, there are number of example here.

A simple example of how to connect to a Couchbase Server bucket is basic-couchbase-bucket.json.

hello @andy

thanks for the response. I tried to change that file but it said “access is denied”. Is that normal? So I deleted that file and created another and move it to that directory.when I start the .exe it still says

2016-04-14T16:49:12.770+03:00 ==== Couchbase Sync Gateway/1.2.0(83;41aa099) ====
2016-04-14T16:49:12.771+03:00 Opening db /sync_gateway as bucket “sync_gateway”, pool “default”, server walrus:
2016-04-14T16:49:12.771+03:00 Opening Walrus database sync_gateway on walrus:
2016-04-14T16:49:12.772+03:00 Using default sync function ‘channel(doc.channels)’ for database "sync_gateway"
2016-04-14T16:49:12.772+03:00 Reset guest user to config
2016-04-14T16:49:12.772+03:00 Starting profile server on
2016-04-14T16:49:12.772+03:00 Starting admin server on 127.0.0.1:4985
2016-04-14T16:49:12.779+03:00 Starting server on localhost:4984 …

I cant see the ports I entered here, still looks like the default.
thanks

@HandeBc

‘Access Denied’ is normal as the installer runs with Admin privileges.

You wil need to find the NotePad (or other editor) icon, right click on it and select ‘Run as administrator’, then you will be able to edit and save the file.

The best way to test changes to the config file is to restart the Sync Gateway Windows Service wrapper.

You can access the Services panel via:

Control Panel\System and Security\Administrative Tools

There should be a service called Couchbase Sync Gateway

Restart the service to pick up config changes.

If you want to run Sync Gateway directly you need to pass serviceconfig.json as a command line parameter e.g.

C:\Program Files (x86)\Couchbase\sync_gateway.exe C:\Program Files (x86)\Couchbase\serviceconfig.json

oh, there is nothing like Couchbase Sync Gateway on my administrative tools.I couldn’t restart it. I only installed couchbase-sync-gateway-enterprise_1.2.0-83b_x86_64.exe, isn’t it enough?

I just closed and reopened the sync_gateway.exe file after I edited serviceconfig.json but It did not work obviously. What am I doing wrong ?

@HandeBc Have you already reviewed the “Running Sync Gateway” guide for Sync Gateway here?
http://developer.couchbase.com/documentation/mobile/1.2/develop/guides/sync-gateway/running-sync-gateway/index.html

It covers a lot of the material you’re asking about.

@adamf Yeah, I actually did but it doesn’t explains why I can’t see the changes I’m doing on the config file. It always uses default.

It sounds like you’re not passing the config file as a command line parameter (as @andy described above).

@adamf I can’t write anything on the window that I sent picture of in my first post. Should I write it somewhere else?

That shell/command window is running Sync Gateway; it’s a server process, not interactive, so it’s not going to respond to keyboard input.

Open another shell/command window and do it there.

@jens @adamf @andy ok thank you so much . now it saw the changes. I did something and It said :

2016-04-15T15:26:52.564+03:00 FATAL: Failed to start HTTP server on http://syncGatewayIP:4984: listen tcp: too many colons in address http://syncGatewayIP:4984 -- rest.(*ServerConfig).serve() at config.go:591

It says that when I enter couchbaseServerIP instead of syncGatewayIP too.

I edited the post like million times, everytime I try something else,and there were 2 doc in my sync_gateway before I started work with it, now after I did something it became three, _sync:user: appeared but I dont get what it is :

My serviceconfig file is :
{
“log”: [“HTTP+”],
“adminInterface”: “http://couchbaseServerIP:4985”,
“interface”: “http://syncGatewayIP:4984”,
“databases”: {
“sync_gateway”: {
“server”: “http://couchbaseServerIP:8091”,
“users”: {
“GUEST”: {“disabled”: false, “admin_channels”: ["*"] }
}
}
}
}
I want all my docs in default bucket to be synced here. am I doing something wrong with the part I wrote in bold?? My boss said sync_gateway’s IP is different from couchbase server’s IP, shouldnt I use it there also? When I replace them with 127.0.0.1:4984 and127.0.0.1:4985 it just stays lke that:

2016-04-15T13:21:13.741+03:00 Starting server on 127.0.0.1:4984 …

when i use

{
  "log": ["*"],
  "databases": {
    "sync_gateway": {
      "server": "http://couchbaseServerIP:8091",
      "bucket": "default",
      "users": { "GUEST": { "disabled": false, "admin_channels": ["*"] } }
    }
  }
}

it says for evey single doc I got:

WARNING: changeCache: Error unmarshaling doc "mainForums_698": <nil> -- db.(*changeCache).DocChanged.func1() at change_cache.go:327

I’m so stucked.Thanks.

@HandeBc

The appearance of the _sync docs means that Sync Gateway has successfully connected to the Couchbase server bucket.

The error regarding colons is caused by the aminInterface and interface values, these should not include the http:// protocol, also to be clear these must point to the IP address of the local server Sync Gateway is running on, not the IP that Couchbase Sever is running on.

From your post try a serviceconfig.json like this:

{
    "log": ["HTTP+"],
    "adminInterface": "syncGatewayIP:4985",
    "interface": "syncGatewayIP:4984",
    "databases": {
        "sync_gateway": {
            "server": "http://couchbaseServerIP:8091",
            "bucket":"sync_gateway",
            "users": {
                "GUEST": {"disabled": false, "admin_channels": ["*"] }
            }
        }
    }
}

@andy I tried exactly what you wrote, It said :

FATAL: Failed to start HTTP server on syncGatewayIP:4985: listen tcp syncGatewayIP:4985: bind: The requested address is not valid in its context. – rest.(*ServerConfig).serve() at config.go:591

@HandBc

Are you replacing syncGatewayIP with an actual IP bind address.

e.g.

0.0.0.0 (bind to all local interfaces, completely public access to REST API’s)
127.0.0.1 (bind to local loopback interface, only access REST API’s )

{
    "log": ["HTTP+"],
    "adminInterface": "127.0.0.1:4985",
    "interface": "127.0.0.1:4984",
    "databases": {
        "sync_gateway": {
            "server": "http://couchbaseServerIP:8091",
            "bucket":"sync_gateway",
            "users": {
                "GUEST": {"disabled": false, "admin_channels": ["*"] }
            }
        }
    }
}

@andy SORRY for asking too much but gotta say that : mobile side will be handled by some other guys here, my only duty now is to carry my docs from default bucket to sync_gateway bucket and keep these two synchronized… I guess I am struggling with more than I should??
Because my boss just came in and said I shouldn’t be using sync_gateway.exe and all other stuff, it’s already connected and the rest is mobile guys’ thing. Should I write my problem with .net tags or am I in the right place? Because nothing I’ve been doing in this 2 days worked for me, about carrying my docs!

Have you read the docs? The documentation of the config file, linked from the main setup page @adamf pointed you to earlier, shows the format of the file including the "interface" and "adminInterface". This could have saved you a lot of trouble.

1 Like

@jens One more thing, should I be using sync_gateway’s config file to create users? Because I need to create channels and roles so I can’t do that without creating users. But when I look at the documentation it shows codes starting with “curl” and I don’t know what that is. I only use .net SDK and couchbase console, ios and android entegration will be done by someone else. So, could you help me about creating users with the config file? Like, with a sample code or something else?

Thanks

I added 2 users by httpie, like : http PUT :4985/db/_user/ios name=ios password=1234

now I need to create channels and give users authorization. problem is, I really couldn’t get the idea of channels. In my sync_gateway bucket, my docs have this property:

"channels": [
               null,
               null,
               null,
               null
           ]

How should I create channels? Should I go to views tab and create multiple channels, is that the way? Because there is a “channels” view in my sync_gateway’s production views and there are so many mapping codes in it but I didn’t create it. This is also what I should do? Or what? Also, when I create channels, will I change these "null"s by hand? Thanks!

@HandeBc

I would recommend reading all the documentation on Sync Gateway to get a good overview.

There are docs specifically covering channels and the [Sync Function API](http://developer.couchbase.com/documentation/mobile/1.2/develop/guides/sync-gateway/sync-function-api-guide/index.html()

There are example Sync Gateway Configuration files

You can also look at one of the ToDoLite mobile applications

iOS
Android
ToDo-Lite-ionic

To see how it interacts with the ToDoLite example config for channels and user access

@andy I read all the docs! Also, mobile applications parts mean nothing to me because I have no idea about ios or android programming. I won’t do that parts at all, someone else will. So all I’m saying is, these docs don’t give any information about “creating” channels, they just show how to use and do things on “created” channels. Hence I’m stuck at the very beginning. My above questions are all about the fundamentals of creating channels and how to shape them in my head. Should I think of them as regular views, or something etc… Thanks again!