I want to deploy a program on a VPS with Ubuntu 16.04.

If you run go run main.go , then go to http: // ip: 8000 and see the output of the running program.

When I launch through the service file, I need to specify the direct path to the binary, something like /usr/bin/go run /path/to/program/src/main.go , but then I see 404 by http: // ip: 8000 , and if you do this with systemd , the output of the systemctl status myproject.service command systemctl status myproject.service as follows, although I exported GOPATH :

 Jul 12 09:00:26 localhost systemd[1]: Started Simple implementation of WebSockets Chat on GoLang. Jul 12 09:00:26 localhost go[4826]: src/main.go:7:9: cannot find package "github.com/gorilla/websocket" in any of: Jul 12 09:00:26 localhost go[4826]: /usr/lib/go-1.6/src/github.com/gorilla/websocket (from $GOROOT) Jul 12 09:00:26 localhost go[4826]: ($GOPATH not set) 

The output of the whereis go command is as follows:

 go: /usr/bin/go /usr/lib/go /usr/share/go /usr/share/man/man1/go.1.gz 

And yes, indeed, in /usr/lib/go-1.6/src/ there is no github.com folder

At the same time, it turned out to be at the root:

 root@localhost:~# ls etc go gocode root@localhost:~/go/src# ls github.com 

Why does it work when I run just the go run , without specifying the path to the binary? How to start using the full path to work?

ADDITION

Running go run /path/to/program/src/main.go at http://ip:8000 see 404.

What's happening? With what it can be connected?

ADDITION

 [Unit] Description=Simple implementation of WebSockets Chat on GoLang After=network.target [Service] User=root WorkingDirectory=/var/www/SGWC ExecStart=/usr/bin/go run /var/www/SGWC/src/main.go [Install] WantedBy=multi-user.target 

1 answer 1

Thanks to the comment @ Ainar-G, we managed to solve it like this:

Compile the program:

 $ go build main.go 

And then change the unit file settings:

 [Unit] Description=Simple implementation of WebSockets Chat on GoLang After=network.target [Service] User=root WorkingDirectory=/var/www/SGWC ExecStart=/var/www/SGWC/src/main [Install] WantedBy=multi-user.target 

And that's all :)

It was not worth raising a panic.

@Ainar-g, again. thank you