Kafka and Zookeeper as service

# Modify systemd script

modify _kafka.service_ by applying [this template](./kafka.service) to /etc/systemd/system/kafka.service

followed by executing:

```

sudo systemctl daemon-reload

```

FOR KAFKA

If Zookeeper is added as service, then add the 'Requires' parameter to the unit section. So when kafka is started it will start zookeeper service automatically.

[Unit]

Description=Apache Kafka server (broker)

Documentation=http://kafka.apache.org/documentation.html

Requires=zookeeper.service

[Service]

Type=simple

Environment="KAFKA_OPTS=-Djava.security.auth.login.config=/home/kafka/config/kafka_server_jaas.conf"

ExecStart=/home/kafka/bin/kafka-server-start.sh /home//kafka/config/server.properties

ExecStop=/home/kafka/bin/kafka-server-stop.sh

[Install]

WantedBy=multi-user.target

FOR ZOOKEEPER

[Unit]

Description=Apache Zookeeper server

Documentation=http://zookeeper.apache.org

Requires=network.target remote-fs.target

After=network.target remote-fs.target

[Service]

Type=simple

ExecStart=/home/kafka/bin/zookeeper-server-start.sh /home/ubuntu/config/zookeeper.properties

ExecStop=/home/kafka/bin/zookeeper-server-stop.sh

[Install]

WantedBy=multi-user.target

### Activating systemd scripts

```

sudo systemctl enable zookeeper

sudo systemctl enable kafka

```

### service management via systemd

```

sudo systemctl start zookeeper

sudo systemctl start kafka