Supervisor is a UNIX system process management software that can be used to manage Apache, Nginx and other services, if the service hangs can let them automatically restart. The following is based on the CentOS 6.6, which describes the following specific implementation:
sudo yum install Python-setuptoolssudo easy_install Supervisor
If you do not see any error, then the installation is successful, you can use echo_supervisord_conf to view configuration details, and then generate the configuration file.
sudo echo_supervisord_conf >/etc/supervisord.conf
Suppose the following is a simple Golang code:
package
main
import
(
"fmt"
"log"
"net/http"
)
func
main() {
http.HandleFunc(
"/"
,
func
(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w,
"Hello world"
)
})
err := http.ListenAndServe(
":9090"
, nil)
if
err != nil {
log.Fatal(
"ListenAndServe: "
, err)
}
}
Go build compiles the executable file test in/usr/local/ponpon/gowork/src/test/.
Edit/etc/supervisord.conf, add run program settings at the end
[program:go-http-server]command=/usr/local/ponpon/gowork/src/test/testdirectory=/usr/local/ponpon/gowork/src/ testautostart=trueautorestart=truestartsecs=10stdout_logfile=/var/log/stdout.logstdout_logfile_maxbytes= 1mbstdout_logfile_backups=10stdout_capture_maxbytes=1mbstderr_logfile=/var/log/stderr.logstderr_logfile_ Maxbytes=1mbstderr_logfile_backups=10stderr_capture_maxbytes=1mb
Several configuration instructions:
Command: Indicates the running commands, fill in the full path.
Directory: Represents the CD to the app's catalog
Autostart: Indicates whether to start with supervisor.
AutoRestart: If the program is hung, restart it.
Stdout_logfile: Terminal standard output redirection file.
Stderr_logfile: Terminal error output redirect file.
Finally start supervisor
Sudo/usr/bin/supervisord-c/etc/supervisord.conf
If prompted/tmp/supervisord.sock error, delete /tmp/supervisord.sock restart supervisor can
This article is from the "Programming in XMU" blog, be sure to keep this source http://liuxp0827.blog.51cto.com/5013343/1643620
Supervisor creating daemons for Golang background