LoginSignup
0
0

More than 5 years have passed since last update.

HiveMQ で WebSocket を port 80 で起動しようとしてエラーですぐに停止してしまう時の対処

Last updated at Posted at 2014-12-27

現象

port 80 を使っているプロセスはいないはずなのに以下のエラーになる。
"ERROR - Could not bind to all interfaces and port 80, because it is already in use. Stopping HiveMQ."

結論

少しお行儀が悪いのかもしれませんが root で起動できました

経緯

cofiguration.properties で

configuration.properties
websockets.enabled=true

と設定すると Websocket を有効になります。デフォルトでは port=8000 なのですが、これを以下のように port=80 に変更すると掲題のエラーで起動直後にとまってしまいました

configuration.properties
websockets.port=80

hivemq.log ファイルを見るとこんな感じです

hivemq.log
2014-12-26 18:43:50,337 INFO  - Starting on all interfaces and port 1883
2014-12-26 18:43:50,377 INFO  - Starting with Websockets support on all interfaces and port 80
2014-12-26 18:43:50,383 INFO  - Shutting down HiveMQ
2014-12-26 18:43:50,383 INFO  - Closing all connections
2014-12-26 18:43:50,393 ERROR - Could not bind to all interfaces and port 80, because it is already in use. Stopping HiveMQ.
2014-12-26 18:43:50,402 INFO  - All connections closed in 19 ms

なにか起動してたっけ?と lsof コマンドで確認

lsof -iTCP:80

80で Listen しているプロセスが何もない。なんで???
forum で教えてもらったこちらをもう一度みて見て納得。単にエラーメッセージが適切でなくテキトーなだけ(よくあることですね)で、本当の原因は 80 番ポートだから root 権限が必要だったんですね。で、その手順で authbind の設定をするのですが現象がかわらない。???

そこで、hivemq の初期化スクリプトを確認してみると、上の手順の sed で書き換えてる行がないというか、run.sh なんか呼んでない...

/etc/init.d/hivemq
do_start()
{
    # Return
    #   0 if daemon has been started
    #   1 if daemon was already running
    #   2 if daemon could not be started
    start-stop-daemon --start --quiet --chuid $DAEMON_USER:$DAEMON_GROUP --pidfile $PID_FILE --make-pidfile \
        --background --oknodo --exec $DAEMON -- $DAEMON_ARGS
    return $?
}

とりあえず --exec の前に authbind をつけたり試行錯誤したりするもうまくいかないので、諦めて root で起動するように変更して無事にport=80で起動しました

/etc/init.d/hivemq
#DAEMON_USER=hivemq
#DAEMON_GROUP=hivemq
DAEMON_USER=root
DAEMON_GROUP=root

感想

これで動くのでしばらくこれで運用することにします。
本当はどうするのが行儀がよかったのでしょうかね?

0
0
0

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
0
0