Mosquitto not running always i do reboot throught sudo reboot

Heys guys i have this issue when i restarted my pi throught sudo reboot

17-02-19 11:11:57 ERROR (Thread-7) [homeassistant.components.mqtt] Can't connect to the broker. Please check your settings and the broker itself
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/mqtt/__init__.py", line 291, in setup
    birth_message)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/mqtt/__init__.py", line 383, in __init__
    self._mqttc.connect(broker, port, keepalive)
  File "/home/homeassistant/.homeassistant/deps/paho/mqtt/client.py", line 686, in connect
    return self.reconnect()
  File "/home/homeassistant/.homeassistant/deps/paho/mqtt/client.py", line 808, in reconnect
    sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
  File "/usr/lib/python3.4/socket.py", line 509, in create_connection
    raise err
  File "/usr/lib/python3.4/socket.py", line 500, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
17-02-19 11:11:57 ERROR (MainThread) [homeassistant.bootstrap] component mqtt failed to initialize

@balloob @rpitera @fabaff

Is your config right? Your broker running?

i think yes. my broker running good if now i put the command: mosquitto
show me:
1487503461: mosquitto version 1.4.10 (build date Thu, 25 Aug 2016 10:12:09 +0100) starting
1487503461: Using default config.
1487503461: Opening ipv4 listen socket on port 1883.
1487503461: Opening ipv6 listen socket on port 1883.

my config is:
mqtt:
broker: 127.0.0.1
port: 1883
username: xxx edit
password: xxx edit
keepalive: 60

and i can say one more thing now if i restarted HA throught front the error not show, but if i restart sudo reboot shows.

If i understand your right then you need to make sure that mosquitto is up before starting Home Assistant. Check the systemd documentation for details.

i need help to do that. i am new, and dont have much knowledge. but on the others version of HA this not happens. i am running the last.

See https://www.freedesktop.org/software/systemd/man/systemd.unit.html

thank you.
sudo apt-get install git

First disable the init.d script:

sudo update-rc.d mosquitto remove

Then

sudo git clone https://github.com/Dan-in-CA/mosquitto_unit_file.git

copy the mosquitto.service file

sudo cp mosquitto_unit_file/mosquitto.service /etc/systemd/system/mosquitto.service

Enable the service

sudo systemctl enable mosquitto.service

Thank you Rodolfo for showing how to do that, this is very helpfull, a sharp contrast to fabaff’s answer, which although valid, is far from beeing helpfull… let me explain: I’m interested in setting up a home automation system right now, learning the new systemd’s peculiarities is not in my priorities yet, there are much funnier things to learn. The best way to show newbies how to persist in learning Linux is sometimes to go easy on the valid answer.