Not able to start Kafka-Connect as a service on CentOS 7 - apache-kafka

I have a Kafka environment (Zookeeper + Kafka Server + Kafka-Connect) which runs perfectly when I use command line to start each individual components on CentOS 7.
Now I am setting up these Kafka components to run as a service. For this I have created .service files and placed it in /etc/systemd/system folder. Following are the files
zookeeper.service
#!/bin/bash
# vi /etc/systemd/system/zookeeper.service
[Unit]
Description=This service will start Zookeeper server which will be used by Kafka Server.
Requires=network.target remote-fs.target
After=network.target remote-fs.target
[Service]
Type=simple
ExecStart=/opt/interactcrm/kafka_2.11-1.0.1/bin/zookeeper-server-start.sh /opt/interactcrm/kafka_2.11-1.0.1/config/zookeeper.properties
ExecStop=/opt/interactcrm/kafka_2.11-1.0.1/bin/zookeeper-server-stop.sh
TimeoutStartSec=0
Restart=on-abnormal
[Install]
WantedBy=multi-user.target
kafka.service
#!/bin/bash
# vi /etc/systemd/system/kafka.service
[Unit]
Description=This service will start Kafka server.
Requires=zookeeper.service
After=zookeeper.service
[Service]
Type=simple
ExecStart=/opt/interactcrm/kafka_2.11-1.0.1/bin/kafka-server-start.sh /opt/interactcrm/kafka_2.11-1.0.1/config/server.properties
ExecStop=/opt/interactcrm/kafka_2.11-1.0.1/bin/kafka-server-stop.sh
TimeoutStartSec=0
Restart=on-abnormal
[Install]
WantedBy=multi-user.target
Kafka-connect.service
#!/bin/bash
# vi /etc/systemd/system/kafkaconnect.service
[Unit]
Description=This service will start Kafka Connect Service.
Requires=network.target remote-fs.target nss-lookup.target kafka.service kafka.service
After=network.target remote-fs.target nss-lookup.target kafka.service
[Service]
Type=forking
Environment="KAFKA_JMX_OPTS=-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10040 -Dcom.sun.management.jmxremote.local.only=true -Dcom.sun.management.jmxremote.authenticate=false"
Environment="LOG_DIR=/var/log/kafka-logs"
ExecStart=/opt/interactcrm/kafka_2.11-1.0.1/bin/connect-distributed.sh /opt/interactcrm/kafka_2.11-1.0.1/config/connect-distributed.properties
TimeoutStartSec=1000
#Restart=on-abnormal
#SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
Zookeeper and Kafka services starts without any issue. I can create topics and then do operations on the topic. The issue is with Kafka connect service.
When I try to start the service using systemctl command, the service does not start. It gets stuck no following log ::
Oct 19 18:29:20 localhost.localdomain connect-distributed.sh[1071]: [2018-10-19 18:29:20,713] INFO Added plugin 'io.debezium.connector.mysql.MySqlConnector...er:136)
Oct 19 18:29:20 localhost.localdomain connect-distributed.sh[1071]: [2018-10-19 18:29:20,713] INFO Added plugin 'io.debezium.transforms.ByLogicalTableRoute...er:136)
Oct 19 18:29:20 localhost.localdomain connect-distributed.sh[1071]: [2018-10-19 18:29:20,713] INFO Added plugin 'io.debezium.transforms.UnwrapFromEnvelope'...er:136)
Oct 19 18:29:20 localhost.localdomain connect-distributed.sh[1071]: [2018-10-19 18:29:20,761] INFO Loading plugin from: /opt/interactcrm/debezium/debezium ...er:184)
Oct 19 18:29:28 localhost.localdomain connect-distributed.sh[1071]: [2018-10-19 18:29:28,725] INFO Registered loader: PluginClassLoader{pluginLocation=file...er:207)
I cannot find any log for this process in message logs after this line and there is no error in any other logs. The process gets stuck on this line ::
INFO Registered loader: PluginClassLoader{pluginLocation=file...er:207)
No matter how much I increase the timeout this process never starts. But when I run the same command from command line, the service starts properly.
I have tried to remove all connectors from Plugin path to see if the service start but it gets stuck on the same line.
Following is my reference point ::
Kafka-Connect Service

I faced the same problem on Debain 9. Figure it out it was because the service need a WorkingDirectory otherwise kafka-connect never fully charges.
So your service should look like this:
#!/bin/bash
# vi /etc/systemd/system/kafkaconnect.service
[Unit]
Description=This service will start Kafka Connect Service.
Requires=network.target remote-fs.target nss-lookup.target kafka.service kafka.service
After=network.target remote-fs.target nss-lookup.target kafka.service
[Service]
Type=forking
Environment="KAFKA_JMX_OPTS=-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10040 -Dcom.sun.management.jmxremote.local.only=true -Dcom.sun.management.jmxremote.authenticate=false"
Environment="LOG_DIR=/var/log/kafka-logs"
WorkingDirectory="/opt/interactcrm/kafka_2.11-1.0.1" <--- or whatever directory you to use
ExecStart=/opt/interactcrm/kafka_2.11-1.0.1/bin/connect-distributed.sh /opt/interactcrm/kafka_2.11-1.0.1/config/connect-distributed.properties
TimeoutStartSec=1000
#Restart=on-abnormal
#SuccessExitStatus=143
[Install]
WantedBy=multi-user.target

** Below configuration worked for me in Ubuntu **
[Unit]
Requires=kafka.service
After=kafka.service
[Service]
Type=simple
User=kafka
ExecStart=/bin/sh -c '/home/kafka/kafka/bin/connect-distributed.sh /home/kafka/kafka/config/connect-distributed.properties > /home/kafka/kafka/kafka_connect.log 2>&1'
Restart=on-abnormal
[Install]
WantedBy=multi-user.target

Related

CentOS 8 systemctl not finding service

systemctl start adstichr Failed to start adstichr.service: Unit adstichr.service not found.
So i have made the following code inside
/etc/systemd/system
adstichr.service
[Unit]
Description=AdStichr Player
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
WorkingDirectory=/home/adstichrplayer
ExecStart=/usr/bin/node app.js
ExecStop=/bin/kill -INT $MAINPID
[Install]
WantedBy=multi-user.target
However when I run it am getting it can't be found. Wondering how do I get this to work as it is working on my ubuntu server.

How to enable JMX port for Zookeeper server

I am using Zookeeper version 3.4.6. I am trying to enable JMX for the same. Following below Url. Below are the changes I did in my zkServer.sh file
How do i enable remote jmx with port in zookeeper zkServer.cmd
ZOOMAIN="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=2989 -Djava.rmi.server.hostname=HDP.trinityiot.local org.apache.zookeeper.server.quorum.QuorumPeerMain"
Zookeeper is starting but JMX port is not enabled.
We have to add the below line in zkEnv.sh file
ZOOMAIN="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=2989 -Djava.rmi.server.hostname=xxxxx org.apache.zookeeper.server.quorum.QuorumPeerMain"
If you have a systemd service you can do it like this with Environment parameter:
[Unit]
Requires=network.target remote-fs.target
After=network.target remote-fs.target
[Service]
Type=simple
User=kafka
ExecStart=/bin/sh -c 'zookeeper-server-start zookeeper.properties > /var/log/zookeeper.log 2>&1'
ExecStop=zookeeper-server-stop
Restart=on-abnormal
Environment="JMX_PORT=9998"
[Install]
WantedBy=multi-user.target

How to enable services in beaglebone black?

[Unit]
Description=Splash screen
DefaultDependencies=no
[Service]
Type=oneshot
ExecStart=/usr/local/bin/psplash
[Install]
WantedBy=basic.target
job for .service failed because the control process exited with an error code
Here is shell script to make service of python code.
It will start the execution at startup,
[Unit]
Description= Python First Service
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/python /home/debian/serv_demo.py
Restart=on-abort
[Install]
WantedBy=multi-user.target
I followed this example and it worked well for my BBB:
https://gist.github.com/tstellanova/7323116

how to manage kafka broker by systemd?

I am trying to manager kafka broker by systemd. here is a unit-file:
[Unit]
Description=Kafka with broker id (%i)
After=network.target
After=zk.service
[Service]
Type=simple
SyslogIdentifier=kafka (%i)
WorkingDirectory=/opt/service/kafka_2.11-0.9.0.1
LimitNOFILE=16384:163840
ExecStart=/usr/bin/bash -c 'bin/kafka-server-start.sh /opt/service/units/kafka/%i.properties'
ExecStop=/usr/bin/bash -c 'bin/kafka-server-stop.sh /opt/service/units/kafka/%i.properties'
[Install]
WantedBy=multi-user.target
with that file, I can start kafka by command systemctl --user start kafka#0.service and systemctl --user start kafka#1.service.
But when I try to kill those daemons by systemctl --user stop kafka#0.service, all two daemons are stoped! so, why could not I kill just only one broker?
Something like this:
[Unit]
Description=Kafka with broker id (%i)
After=network.target
After=zk.service
[Service]
Type=forking
SyslogIdentifier=kafka (%i)
Restart=on-failure
LimitNOFILE=16384:163840
ExecStart=/opt/service/kafka_2.11-0.9.0.1/bin/kafka-server-start.sh -daemon /opt/service/units/kafka/%i.properties
[Install]
WantedBy=multi-user.target

systemd: Pass start/stop to service

I am trying to create an systemd init script for starting and stopping the softether VPN server.
A tutorial I found suggests following init.d script.
#!/bin/sh
# chkconfig: 2345 99 01
# description: SoftEther VPN Server
DAEMON=/usr/local/vpnserver/vpnserver
LOCK=/var/lock/subsys/vpnserver
test -x $DAEMON || exit 0
case "$1" in
start)
$DAEMON start
touch $LOCK
;;
stop)
$DAEMON stop
rm $LOCK
;;
restart)
$DAEMON stop
sleep 3
$DAEMON start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0
But I'd like to use systemd, so I wrote following service file.
[Unit]
Description=Softether VPN server
After=syslog.target
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/vpnserver/vpnserver start
ExecStop=/usr/local/vpnserver/vpnserver stop
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300
[Install]
WantedBy=multi-user.target
But this script does not keep the VPN server running. sudo systemctl status softethervpn gives me following status.
● softethervpn.service - Softether VPN server
Loaded: loaded (/lib/systemd/system/softethervpn.service; disabled)
Active: deactivating (stop) since Mon 2016-04-18 19:11:41 CEST; 1s ago
Process: 1463 ExecStart=/usr/local/vpnserver/vpnserver start (code=exited, status=0/SUCCESS)
Main PID: 1463 (code=exited, status=0/SUCCESS); : 1474 (vpnserver)
CGroup: /system.slice/softethervpn.service
├─1471 /usr/local/vpnserver/vpnserver execsvc
└─control
└─1474 /usr/local/vpnserver/vpnserver stop
Apr 18 19:11:40 raspberrypi systemd[1]: Started Softether VPN server.
Apr 18 19:11:41 raspberrypi vpnserver[1463]: The SoftEther VPN Server service has been started.
Apr 18 19:11:42 raspberrypi vpnserver[1474]: Stopping the SoftEther VPN Server service ...
Apr 18 19:11:42 raspberrypi vpnserver[1474]: SoftEther VPN Server service has been stopped.
How do I need to correct my service file to work correctly?
It seems that the Type needs to be forking. Following script works for me (found at SoftEther Configurationfile for Systemd).
[Unit]
Description=SoftEther VPN Server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/vpnserver/vpnserver start
ExecStop=/usr/local/vpnserver/vpnserver stop
[Install]
WantedBy=multi-user.target
for SoftEther this works
[Unit]
Description=SoftEther VPN Server
After=network.target auditd.service
[Service]
Type=forking
TasksMax=infinity
EnvironmentFile=-/usr/local/vpnserver
ExecStart=/usr/local/vpnserver/vpnserver start
ExecStop=/usr/local/vpnserver/vpnserver stop
KillMode=process
Restart=on-failure
# Hardening
PrivateTmp=yes
ProtectHome=yes
ProtectSystem=full
ReadOnlyDirectories=/
ReadWriteDirectories=-/usr/local/vpnserver
[Install]
WantedBy=multi-user.target
It is the official service for SoftEther, expect this line has been removed
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW CAP_SYS_NICE CAP_SYSLOG CAP_SETUID
which caused some error for me, Ex,
-- Alert: SoftEther VPN Kernel --
Unable to create /usr/local/vpnserver/.VPN-49BDCFFA14.
-- Alert: SoftEther VPN Kernel --
Unable to create /usr/local/vpnserver/.VPN-49BDCFFA14.