When I use the nginx/unit project as my LoadBalancer component, I want use golang programming language to make a plugin tool. According to the official document, I config/make unit source code and go build my program, then use http put command to update the config:
{
"listeners": {
"*:8500": {
"application": "go_chat_app"
}
},
"applications": {
"go_chat_app": {
"type": "go",
"working_directory": "/tmp",
"executable": "/tmp/unit-go"
}
}
}
```bash
After start unit service, I can't see the unit-go child process in `ps` commond, but I see the 8500 port is listing by unit router process:
```bash
#netstat -anpt | grep 8500
tcp 0 0 0.0.0.0:8500 0.0.0.0:* LISTEN 12798/unit: router
```bash
root 12795 0.0 0.0 16224 952 ? Ss 5ๆ25 0:00 unit: main [/usr/sbin/unitd --log /var/log/unitd.log --pid /run/unitd.pid]
nobody 12797 0.0 0.0 26468 976 ? S 5ๆ25 0:00 _ unit: controller
nobody 12798 0.0 0.0 174076 932 ? Sl 5ๆ25 0:00 _ unit: router
and my golang code:
```golang
package main
import (
"fmt"
"net/http"
"nginx/unit"
)
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "text/plain");
fmt.Fprintf(w, "Method : %s\n", r.Method)
fmt.Fprintf(w, "URL : %s\n", r.URL.Path)
fmt.Fprintf(w, "Host : %s\n", r.Host)
}
func main() {
http.HandleFunc("/", handler)
unit.ListenAndServe("8000", nil)
}
go.json:
{
"listeners": {
"*:8500": {
"application": "go_chat_app"
}
},
"applications": {
"go_chat_app": {
"type": "go",
"working_directory": "/tmp",
"executable": "/tmp/unit-go"
}
}
}
Anybody has same problem?
When I curl localhost:8500, it returns "Read header timeout" error.
Please provide more information about your environment: OS version, golang version, configure command line options to reproduce the issue.
Thank you very much~
Here is my environment Info:
OS version: CentOS 7
Kernel version: 3.10.0-693.2.2.el7.x86_64
Golang version: go1.9.5 linux/amd64
Configure commands:
Firstly: ./config
Then: ./config go
Then: make all
Finally: make go-install
My directory:
~/unit
โโโ full.json
โโโ get.sh
โโโ go.json
โโโ put.sh
โโโ src
โย ย โโโ nginx
โย ย โย ย โโโ unit
โย ย โโโ unit
โย ย โโโ auto
โย ย โโโ build
โย ย โโโ CHANGES
โย ย โโโ configure
โย ย โโโ docs
โย ย โโโ LICENSE
โย ย โโโ Makefile
โย ย โโโ NOTICE
โย ย โโโ pkg
โย ย โโโ README
โย ย โโโ sbin
โย ย โโโ src
โย ย โโโ test
โโโ unit
โโโ unit.go
GOPATH: ~/unit
This problem is also posted on stackoverflow-Can not find unit-go child process in nginx unit, curl request timeout, welcoming everyone to join the discussion~
I've tried to reproduce your issue and failed with it. Sorry.
Let's ensure we using same version, same commands etc. This is my sequence of commands:
$ cd $HOME
$ script $HOME/unit-i126.log
$ rm -rf $HOME/unit-i126 && mkdir -p $HOME/unit-i126/src
$ cd $HOME/unit-i126/src
$ git clone https://github.com/nginx/unit.git
$ cp unit/pkg/rpm/rpmbuild/SOURCES/unit.example-go-app ../go-app.go
$ cp unit/pkg/rpm/rpmbuild/SOURCES/unit.example-go-config ../go-app.json
$ cd unit
$ export GOPATH=$HOME/unit-i126
$ ./configure
$ ./configure go
$ make -s all
$ make go-install
$ ./build/unitd
$ cd $HOME/unit-i126
$ go build go-app.go
$ cp go-app /tmp/
$ curl -X PUT -d @go-app.json --unix-socket src/unit/control.unit.sock http://localhost/
$ curl http://localhost:8500/
$ kill `cat src/unit/unit.pid`
$ exit
Please stop any running version of unit and carefully execute this commands line by line. In case of any issues, let me know and attach $HOME/unit-i126.log and $HOME/unit-i126/src/unit/unit.log files.
@lth2015 What Unit version are you trying to run? Please, note that currently supported version is 1.1 and all the instructions are valid for it.
@mar0x thank you very much! It's works! may be I use a different version of unit by yum install unit and service unitd start.
@VBart thank you~
I will write a document to show how to can run unit-go step-by-step, thank you all guys~
Most helpful comment
I've tried to reproduce your issue and failed with it. Sorry.
Let's ensure we using same version, same commands etc. This is my sequence of commands:
Please stop any running version of unit and carefully execute this commands line by line. In case of any issues, let me know and attach $HOME/unit-i126.log and $HOME/unit-i126/src/unit/unit.log files.