Maintain Golang processes from zero deployment supervisor

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Golang Supervisor

Go prep work

Create a <demo> project with MAIN.GO code inside
Code excerpt from <go WEB programming >

package mainimport (    "fmt"    "log"    "net/http"    "strings")func sayhelloName(w http.ResponseWriter, r *http.Request) {    r.ParseForm()       //解析参数,默认是不会解析的    fmt.Println(r.Form) //这些信息是输出到服务器端的打印信息    fmt.Println("path", r.URL.Path)    fmt.Println("scheme", r.URL.Scheme)    fmt.Println(r.Form["url_long"])    for k, v := range r.Form {        fmt.Println("key:", k)        fmt.Println("val:", strings.Join(v, ""))    }    fmt.Fprintf(w, "Hello astaxie!") //这个写入到w的是输出到客户端的}func main() {    http.HandleFunc("/", sayhelloName)       //设置访问的路由    err := http.ListenAndServe(":9090", nil) //设置监听的端口    if err != nil {        log.Fatal("ListenAndServe: ", err)    }}

Go Build
Go Install
The local test passes the running demo package to the server after

Installing Supervisor

Official address
Http://supervisord.org/index.html

sudo yum install python-setuptoolssudo easy_install supervisor

Build configuration file after successful installation

sudo echo_supervisord_conf > /etc/supervisord.conf

Here is very simple, if you encounter problems can be Google under

To add your own configuration file

I also learn online under the/etc/to create a special put. conf folder, feel good, than blindly modify supervisord.conf file to more convenient later management
I named it
"Supervisorconffile"
Create a new. conf file in Supervisorconffile
It's mine
Demo.conf

Description

command:表示运行的命令,我这是填写的我demo安装包的原则路径。autostart:表示是否跟随supervisor一起启动。autorestart:如果该程序挂了,是否重新启动。stdout_logfile:终端标准输出重定向文件。stderr_logfile:终端错误输出重定向文件。

Note the two log files above
/root/applications/logfile/log/demo.log
/root/applications/logfile/err/demo.log
To create the corresponding log under the corresponding directory

Modifying a configuration file

All right, start.
Edit/etc/supervisord.conf

At the bottom of the file
It's just opened.

;[include];files = relative/directory/*.ini

Change it.

[include]files = /etc/supervisorconffile/*.conf

Note the '; ' in front of [include] To get rid of it, I lost some time on this.

Start

sudo /usr/bin/supervisord -c /etc/supervisord.conf

An error.
Error:another program was already listening on a port the one of our HTTP servers are configured to use. Shut This program down first before starting Supervisord.

Check online to perform the following two commands to resolve

1.find / -name supervisor.sock2.unlink /***/supervisor.sock

Execute again
Sudo/usr/bin/supervisord-c/etc/supervisord.conf
Startup success
I have nothing to do with this success. Print output feedback, no feedback is successful no problem.

You can enter a command to see if the demo service you just started is a success

sudo supervisorctl status demo

Output

demo                             

View Status Entry Directory

supervisorctl

Output:

demo                             RUNNING   pid 4806, uptime 0:04:05

Supervisor> Help
Use Help to view assistance
Enter Exit exit

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.