Golang(15)Deployment

Golang(15)Deployment

1. Installtion
>git clone https://github.com/Supervisor/supervisor

Right now the version is 4.0-dev, so
>mv supervisor supervisor-4.0.0-dev

try to install that from command as follow
>python ./setup.py install
Traceback (most recent call last):  File "./setup.py", line 35, in <module>    from setuptools import setup, find_packages ImportError: No module named setuptools

Solution:
https://pypi.python.org/pypi/setuptools#files

>curl https://bootstrap.pypa.io/ez_setup.py -o - | python
>python ./setup.py install

2. Command Arguments in go main
https://gobyexample.com/command-line-arguments
http://golang.org/pkg/os/

First of all, we need to import the os package.
import (
     "encoding/json"
     "fmt"
     "github.com/gorilla/mux"
     "io/ioutil"
     "net/http"
     "os"
)

     argsWithProg := os.Args
     var port = "8088"
     if len(argsWithProg) > 1 {
          port = argsWithProg[1]
     }
     fmt.Println("Start the server on port " + port)
     http.ListenAndServe(":"+port, nil)

We get and parse the port number in command line, it both works in go run and bin
>go run src/com/sillycat/easygoapp/restjsonserver.go 8088
>bin/easygoapp 8089

3. Configure the CONF file
http://supervisord.org/configuration.html

My configuration file will be as follow /etc/supervisord.conf

[unix_http_server]

file = /var/run/supervisord.sock

chmod = 0777

#chown= root:root

[inet_http_server]

# Web管理界面设定

port=9001

username=admin

password=admin

[supervisorctl]

; 必须和'unix_http_server'里面的设定匹配 serverurl=unix:///var/run/supervisord.sock

;serverurl=http://127.0.0.1:9001

;username=admin

;password=admin

[supervisord]

logfile=/var/log/supervisord/supervisord.log ; (main log file;default $CWD/supervisord.log)

logfile_maxbytes=50MB       ; (max main logfile bytes b4 rotation;default 50MB)

logfile_backups=10          ; (num of main logfile rotation backups;default 10)

loglevel=info               ; (log level;default info; others: debug,warn,trace)

pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)

nodaemon=true              ; (start in foreground if true;default false)

minfds=1024                 ; (min. avail startup file descriptors;default 1024)

minprocs=200                ; (min. avail process descriptors;default 200)

user=root                 ; (default is current user, required if root)

childlogdir=/var/log/supervisord/            ; ('AUTO' child log dir, default $TEMP)

[rpcinterface:supervisor]

supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface ; 管理的单个进程的配置,可以添加多个program

[program:bugrest]

command=/Users/carl/work/easy/easygo/bin/easygoapp 8089

autostart = true

startsecs = 5

user = root

redirect_stderr = true

stdout_logfile = /var/log/supervisord/bugrest.log

Start the Server
>sudo supervisord
Error Message
ImportError: No module named mock

Solution:
>easy_install ipython
>sudo easy_install setuptools
>sudo easy_install mock

>sudo mkdir /var/log/supervisord

Check the Status of my app
>sudo supervisorctl status
bugrest                          RUNNING   pid 67103, uptime 0:03:08

Then I can use these commands
start bugrest, restart bugrest, stop all, reload, stop bugrest.

The most useful command is this.
>sudo supervisorctl help
default commands (type help <topic>): ===================================== add    clear  fg        open  quit    remove  restart   start   stop  update avail  exit   maintail  pid   reload  reread  shutdown  status  tail  version

>sudo supervisorctl version
4.0.0-dev

References:
https://github.com/astaxie/build-web-application-with-golang/blob/master/ebook/12.3.md

https://github.com/Supervisor/supervisor
http://supervisord.org/
http://ddbean.wordpress.com/2011/09/16/supervisor-python%E8%BF%9B%E7%A8%8B%E7%AE%A1%E7%90%86%E5%B7%A5%E5%85%B7/

https://pypi.python.org/pypi/setuptools#files

https://gobyexample.com/command-line-arguments

相关推荐