LoginSignup
3

More than 5 years have passed since last update.

godocのhttpサーバーをTerminalを閉じても起動させ続ける

Posted at

local環境にgodocのhttpサーバー立ち上げても、Terminalのウィンドウを閉じると一緒にプロセスも落ちちゃいますよね?

でも、再起動させるのがめんどうなので、godocを起動させ続けられないか調べました。

やり方

nohupコマンド経由で、godocをバックグラウンドに流します。

nohup godoc -http=:6060 &

以上!

これで、Terminal落としてても、ログアウトしてから戻って来ても、godocのhttpサーバーが立ち上がりっぱなしになります。

で、落とす時はこんな感じ。

kill -9 `pgrep godoc`

おまけ

bashrcやzshrcに、こんなかんじで書いておくとちょっとだけ幸せになれるかもしれないです。

.zshrc
if [ -z "`pgrep godoc`" ]; then
  (nohup godoc -http=:6060 &) &> /dev/null
fi

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3