補上篇,Go Web 應用程式需要在 Command Line 下啟動,在 Production 環境中我們可以在 Ubuntu 中使用 Upstart 設定為開機時自動啟動,設定如下:
file: /etc/init/go-http.conf
# Upstart Configuration
description "Golang Web App"
author "xxxxx xxx"
start on (net-device-up
and local-filesystems
and runlevel [2345])
stop on runlevel [016]
respawn
exec /path/to/http
然後就可以使用這個指令來啟動:
$ sudo service go-http start go-http start/running, process 12537
Upstart 在 Ubuntu like 系統上是預設安裝的應用程式,在其他的 Linux 下可能需要另外安裝。設定好了之後重新開機時就會像一般的 Daemon 一樣自動啟動應用程式。這個設定會在網路已經啟用的狀況下才啟動你指定的程式,對於 Upstart 有興趣深入了解的朋友可以參考這篇:http://upstart.ubuntu.com/cookbook/
2014/2/15 [補充] Debian 與 Ubuntu 都將支持使用 systemd 而不再用 Upstart, 因此稍晚這篇要改成 systemd 的設定方式。