Supervisor creating daemons for Golang background

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.