A
A
amalygin2016-01-16 20:57:27
go
amalygin, 2016-01-16 20:57:27

How to start a Go application via start-stop-deamon?

I wrote an application in Go that makes an http request every 20 seconds. In the source folder I do go build. Then I run the executable file and everything works while the terminal is running. The essence of the application is that it makes a request every 20 seconds and if it receives apns tokens in response, it sends a push notification of the specified format to all devices. The main problem is how to launch an application through deamon so that it does not depend on the terminal?
When launched via start-stop-deamon, an error is thrown: Could not create clientopen resources/pushcert.pem: no such file or directory. This is the apns certificate, which is located in the resources folder, the folder itself is located next to the executable file.
The command I run in the terminal:
start-stop-daemon -Sbvx /root/go/src/myapp/myapp
Tell me how to properly write paths to resource files in Go and how to run an application that does not depend on the terminal.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
abcyu, 2016-01-16
@amalygin

To start a daemon, you can use external tools that can run regular programs like a daemon.
Specifically for Go, there are packages, there are at least 3 of them different and 6 more of their clones. For example: https://github.com/takama/daemon (specifically, I didn’t like this one, I use another one, simpler, but also more stable https://github.com/VividCortex/godaemon )
But in your case, it’s just not rights to the directory (under the daemon, the program with what rights is launched, what do you think?) or the path cannot be found.
First, try to write the full path, not from the current directory of the program, but from the root - and check.

P
Pavel, 2016-01-20
@milast

Perhaps you should not make a demon from the application?
And that's it, no longer dependent on the terminal.
Killing a process is just as easy:
Or first we find out the pid of the process and terminate it by it:
we will see something like this:
then complete the process
And no demons are needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question