Apache Zookeeper: Unable to access data directory - apache-zookeeper

OS: RHEL 8.2
I am trying to create a systemctl service for zookeeper. It fails to access the datadir.
Here is my config for zookeeper,
dataDir=/opt/zookeeper
maxClientCnxns=20
tickTime=2000
dataDir=/var/zookeeper/
initLimit=20
syncLimit=10
server.0=master:2888:3888
clientPort=2181
admin.serverPort=8082
Permission of /opt/zookeeper is set to 777.
[user1#server1 opt]$ ls -lart
total 0
dr-xr-xr-x. 17 root root 244 Jul 3 10:56 ..
drwxr-xr-x 3 root root 27 Jul 10 10:29 rh
drw-r--r-- 2 user2 user2 6 Jul 17 08:48 hsluw_data
drw-r--r-- 2 user2 user2 6 Jul 17 08:58 hsluw_config
drwxr-xr-x. 6 root root 71 Jul 17 08:58 .
drwxrwxrwx 3 user2 user2 23 Jul 17 09:40 zookeeper
If I run the command,
./bin/zookeeper-server-start.sh config/zookeeper.properties
it gives me an error message: Unable to access datadir
[2020-07-30 10:25:50,767] ERROR Invalid configuration, only one server specified (ignoring) (org.apache.zookeeper.server.quorum.QuorumPeerConfig)
[2020-07-30 10:25:50,767] INFO Starting server (org.apache.zookeeper.server.ZooKeeperServerMain)
[2020-07-30 10:25:50,769] INFO zookeeper.snapshot.trust.empty : false (org.apache.zookeeper.server.persistence.FileTxnSnapLog)
[2020-07-30 10:25:50,769] ERROR Unable to access datadir, exiting abnormally (org.apache.zookeeper.server.ZooKeeperServerMain)
org.apache.zookeeper.server.persistence.FileTxnSnapLog$DatadirException: Cannot write to data directory /var/zookeeper/version-2
at org.apache.zookeeper.server.persistence.FileTxnSnapLog.<init>(FileTxnSnapLog.java:132)
at org.apache.zookeeper.server.ZooKeeperServerMain.runFromConfig(ZooKeeperServerMain.java:124)
at org.apache.zookeeper.server.ZooKeeperServerMain.initializeAndRun(ZooKeeperServerMain.java:106)
at org.apache.zookeeper.server.ZooKeeperServerMain.main(ZooKeeperServerMain.java:64)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:128)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:82)
Unable to access datadir, exiting abnormally
However, sudoing the above command works,
sudo ./bin/zookeeper-server-start.sh config/zookeeper.properties
Now I have created a service in /etc/systemd/system/zookeeper.service
I wrote the service in /etc/systemd/system/zookeeper.service in this way,
[Unit]
Requires=network.target remote-fs.target
After=network.target remote-fs.target
[Service]
Type=simple
User=user2
ExecStart=/home/user2/kafka/bin/zookeeper-server-start.sh /home/user2/kafka/config/zookeeper.properties
ExecStop=/home/user2/kafka/bin/zookeeper-server-stop.sh
Restart=on-abnormal
[Install]
WantedBy=multi-user.target
The SELinux status is disabled.
user2#server1$ sestatus
SELinux status: disabled
Now if I do the following
sudo systemctl daemon-reload
sudo systemctl start zookeeper
sudo systemctl enable zookeeper
I am getting the the same Unable to access the datadir error like the following,
[user2#server1 /]$ systemctl status zookeeper
\u25cf zookeeper.service
Loaded: loaded (/etc/systemd/system/zookeeper.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2020-07-30 10:13:19 CEST; 24s ago
Main PID: 12911 (code=exited, status=3)
Jul 30 10:13:19 server1.localdomain zookeeper-server-start.sh[12911]: org.apache.zookeeper.server.persistence.FileTxnSnapLog$Data>
Jul 30 10:13:19 server1.localdomain zookeeper-server-start.sh[12911]: at org.apache.zookeeper.server.persistence.FileTxnS>
Jul 30 10:13:19 server1.localdomain zookeeper-server-start.sh[12911]: at org.apache.zookeeper.server.ZooKeeperServerMain.>
Jul 30 10:13:19 server1.localdomain zookeeper-server-start.sh[12911]: at org.apache.zookeeper.server.ZooKeeperServerMain.>
Jul 30 10:13:19 server1.localdomain zookeeper-server-start.sh[12911]: at org.apache.zookeeper.server.ZooKeeperServerMain.>
Jul 30 10:13:19 server1.localdomain zookeeper-server-start.sh[12911]: at org.apache.zookeeper.server.quorum.QuorumPeerMai>
Jul 30 10:13:19 server1.localdomain zookeeper-server-start.sh[12911]: at org.apache.zookeeper.server.quorum.QuorumPeerMai>
Jul 30 10:13:19 server1.localdomain zookeeper-server-start.sh[12911]: Unable to access datadir, exiting abnormally
Jul 30 10:13:19 server1.localdomain systemd[1]: zookeeper.service: Main process exited, code=exited, status=3/NOTIMPLEMENTED
Jul 30 10:13:19 server1.localdomain systemd[1]: zookeeper.service: Failed with result 'exit-code'.
What am I missing here?

In the configuration file, this line
dataDir=/var/zookeeper/
appears twice. Removing that line solves the issue.

Related

Service starting gunicorn failing with "Start request repeated too quickly"

Trying to start a service to run gunicorn as backend server for Flask, not working. Running nginx as frontend server for React, working.
Server:
Virtualization: vmware
Operating System: Red Hat Enterprise Linux 8.4 (Ootpa)
CPE OS Name: cpe:/o:redhat:enterprise_linux:8.4:GA
Kernel: Linux 4.18.0-305.3.1.el8_4.x86_64
Architecture: x86-64
Service file in /etc/systemd/system/myservice.service:
[Unit]
Description="Description"
After=network.target
[Service]
User=root
Group=root
WorkingDirectory=/home/project/app/api
ExecStart=/home/project/app/api/venv/bin/gunicorn -b 127.0.0.1:5000 api:app
Restart=always
[Install]
WantedBy=multi-user.target
/app/api:
-rwxr-xr-x. 1 root root 2018 Jun 9 20:06 api.py
drwxrwxr-x+ 5 root root 100 Jun 7 10:11 venv
Error message:
● myservice.service - "Description"
Loaded: loaded (/etc/systemd/system/myservice.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2021-06-10 19:01:01 CEST; 5s ago
Process: 18307 ExecStart=/home/project/app/api/venv/bin/gunicorn -b 127.0.0.1:5000 api:app (code=exited, status=203/EXEC)
Main PID: 18307 (code=exited, status=203/EXEC)
Jun 10 19:01:01 xxxx systemd[1]: myservice.service: Service RestartSec=100ms expired, scheduling restart.
Jun 10 19:01:01 xxxx systemd[1]: myservice.service: Scheduled restart job, restart counter is at 5.
Jun 10 19:01:01 xxxx systemd[1]: Stopped "Description".
Jun 10 19:01:01 xxxx systemd[1]: myservice.service: Start request repeated too quickly.
Jun 10 19:01:01 xxxx systemd[1]: myservice.service: Failed with result 'exit-code'.
Jun 10 19:01:01 xxxx systemd[1]: Failed to start "Description".
Tried, not working:
Adding Environment="PATH=/home/project/app/api/venv/bin" under [Service]
$ systemctl reset-failed myservice.service
$ systemctl daemon-reload
Reboot, ofc.
Tried, working:
Running (as root) /home/project/app/api/venv/bin/gunicorn -b 127.0.0.1:5000 api:app while in /app/api directory
Does anyone know how to fix this problem?
Typically enough, I figured it out shortly after posting this issue.
SELinux is messing with permissions for files and directories, so for anyone experiencing the same issue, make sure to test with the following alterings (as root):
$ setsebool -P httpd_can_network_connect on
$ chcon -Rt httpd_sys_content_t /path/to/your/Flask/dir
In my case: $ chcon -Rt httpd_sys_content_t /home/project/app/api
While this is NOT a permanent fix, it's worth a try. Check out the SELinux docs for more permanent solutions.

Failed at step CHDIR spawning /opt/Informer5/informer5.sh: No such file or directory

I have an application called "Informer." I am trying to register it as a service and I'm not sure where I have gone wrong.
Here is informer.service:
[Unit]
Description=Informer Docker
After=docker.service
Requires=docker.service
[Service]
Type=oneshot
User=root
WorkingDirectory=/opt/Informer5 <===Modify for the appropriate directory
ExecStart=/opt/Informer5/informer5.sh start <===Modify for the appropriate directory
ExecStop=/opt/Informer5/informer5.sh stop <===Modify for the appropriate directory
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
This file is in my /etc/systemd/system folder. I have enabled the service via
sudo systemctl enable informer
when I execute
sudo systemctl start informer
The response I get is
Job for informer.service failed because the control process exited with error code. See "systemctl status informer.service" and "journalctl -xe" for details.
So, running, systemctl status informer.service, I see the following:
$sudo systemctl status informer.service
● informer.service - Informer Docker
Loaded: loaded (/etc/systemd/system/informer.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2018-09-18 08:49:07 EDT; 4min 2s ago
Process: 5780 ExecStart=/opt/Informer5/informer5.sh start <===Modify for the appropriate directory (code=exited, status=200/CHDIR)
Main PID: 5780 (code=exited, status=200/CHDIR)
Sep 18 08:49:07 informer5 systemd[1]: Starting Informer Docker...
Sep 18 08:49:07 informer5 systemd[1]: informer.service: Main process exited, code=exited, status=200/CHDIR
Sep 18 08:49:07 informer5 systemd[1]: Failed to start Informer Docker.
Sep 18 08:49:07 informer5 systemd[1]: informer.service: Unit entered failed state.
Sep 18 08:49:07 informer5 systemd[1]: informer.service: Failed with result 'exit-code'.
Running $ sudo journalctl -xe, I get:
$ sudo journalctl -xe
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit informer.service has failed.
--
-- The result is failed.
Sep 18 08:06:36 informer5 systemd[1]: informer.service: Unit entered failed state.
Sep 18 08:06:36 informer5 systemd[1]: informer.service: Failed with result 'exit-code'.
Sep 18 08:06:36 informer5 sudo[5690]: pam_unix(sudo:session): session closed for user root
Sep 18 08:12:40 informer5 sudo[5712]: n_connor : TTY=pts/0 ; PWD=/opt/Informer5 ; USER=root ; COMMAND=/bin/cat /etc/systemd/system/informer.service
Sep 18 08:12:40 informer5 sudo[5712]: pam_unix(sudo:session): session opened for user root by n_connor(uid=0)
Sep 18 08:12:40 informer5 sudo[5712]: pam_unix(sudo:session): session closed for user root
Sep 18 08:15:01 informer5 CRON[5716]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 18 08:15:01 informer5 CRON[5717]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Sep 18 08:15:01 informer5 CRON[5716]: pam_unix(cron:session): session closed for user root
Sep 18 08:17:01 informer5 CRON[5721]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 18 08:17:01 informer5 CRON[5722]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Sep 18 08:17:01 informer5 CRON[5721]: pam_unix(cron:session): session closed for user root
Sep 18 08:25:01 informer5 CRON[5732]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 18 08:25:01 informer5 CRON[5733]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Sep 18 08:25:01 informer5 CRON[5732]: pam_unix(cron:session): session closed for user root
Sep 18 08:35:01 informer5 CRON[5745]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 18 08:35:01 informer5 CRON[5746]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Sep 18 08:35:01 informer5 CRON[5745]: pam_unix(cron:session): session closed for user root
Sep 18 08:45:01 informer5 CRON[5758]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 18 08:45:01 informer5 CRON[5759]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Sep 18 08:45:01 informer5 CRON[5758]: pam_unix(cron:session): session closed for user root
Sep 18 08:47:43 informer5 sudo[5774]: n_connor : TTY=pts/0 ; PWD=/opt/Informer5 ; USER=root ; COMMAND=/bin/cat /etc/systemd/system/informer.service
Sep 18 08:47:43 informer5 sudo[5774]: pam_unix(sudo:session): session opened for user root by n_connor(uid=0)
Sep 18 08:47:43 informer5 sudo[5774]: pam_unix(sudo:session): session closed for user root
Sep 18 08:49:07 informer5 sudo[5777]: n_connor : TTY=pts/0 ; PWD=/opt/Informer5 ; USER=root ; COMMAND=/bin/systemctl start informer
Sep 18 08:49:07 informer5 sudo[5777]: pam_unix(sudo:session): session opened for user root by n_connor(uid=0)
Sep 18 08:49:07 informer5 systemd[5780]: informer.service: Failed at step CHDIR spawning /opt/Informer5/informer5.sh: No such file or directory
-- Subject: Process /opt/Informer5/informer5.sh could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The process /opt/Informer5/informer5.sh could not be executed and failed.
--
-- The error number returned by this process is 2.
Sep 18 08:49:07 informer5 systemd[1]: Starting Informer Docker...
-- Subject: Unit informer.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit informer.service has begun starting up.
Sep 18 08:49:07 informer5 systemd[1]: informer.service: Main process exited, code=exited, status=200/CHDIR
Sep 18 08:49:07 informer5 systemd[1]: Failed to start Informer Docker.
-- Subject: Unit informer.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit informer.service has failed.
--
-- The result is failed.
Sep 18 08:49:07 informer5 systemd[1]: informer.service: Unit entered failed state.
Sep 18 08:49:07 informer5 systemd[1]: informer.service: Failed with result 'exit-code'.
Sep 18 08:49:07 informer5 sudo[5777]: pam_unix(sudo:session): session closed for user root
Sep 18 08:53:09 informer5 sudo[5787]: n_connor : TTY=pts/0 ; PWD=/opt/Informer5 ; USER=root ; COMMAND=/bin/systemctl status informer.service
Sep 18 08:53:09 informer5 sudo[5787]: pam_unix(sudo:session): session opened for user root by n_connor(uid=0)
Sep 18 08:53:09 informer5 systemd[1]: Configuration file /etc/systemd/system/informer.service is marked executable. Please remove executable permission bits. Proceeding anyway.
Sep 18 08:53:09 informer5 sudo[5787]: pam_unix(sudo:session): session closed for user root
Sep 18 08:54:01 informer5 sudo[5791]: n_connor : TTY=pts/0 ; PWD=/opt/Informer5 ; USER=root ; COMMAND=/bin/journalctl -xe
Sep 18 08:54:01 informer5 sudo[5791]: pam_unix(sudo:session): session opened for user root by n_connor(uid=0)
I think that the salient error here is informer.service: Failed at step CHDIR spawning /opt/Informer5/informer5.sh: No such file or directory
I have checked that the file does exist and I can manually start the service using that file as root. I have a home directory set in the service file. I have no idea where this error is coming from. I am using ubuntu 16.04 and I have enabled root login with ssh. Any ideas?
I added #!/bin/bash in the bash file at the top and it worked
e.g.
nano server.sh
#!/bin/bash
echo "Serving Web App!"
serve -s build -p 4004
chmod +x server.sh
nano /etc/systemd/system/web.service
[Unit]
Description=Web App
After=network.target
[Service]
WorkingDirectory=/var/www/html/web
User=root
ExecStart=/var/www/html/web/server.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
Things to note
Verify the WorkingDirectory e.g cd /var/www/html/web if it does not exist create it e.g. cd /var/www/html/web

varnish 4.1 default.vcl permissions denied

When I'm trying to add magento 2 varnish.vcl file by creating a symbolic link, varnish service stop working with error permission denied, while if I use default varnish configuration file varnish works smooth.
My Stack is ubuntu 16.04, varnish 4.1
ls -al
drwxr-xr-x 2 root root 4096 Mar 21 13:14 .
drwxr-xr-x 96 root root 4096 Mar 21 12:56 ..
lrwxrwxrwx 1 root root 44 Mar 21 13:14 default.vcl -> /var/www/bazaar/varnish.vcl
-rw-r--r-- 1 root root 1225 Aug 22 2017 default.vcl_bak
-rw-r--r-- 1 root root 37 Mar 21 12:56 secret
here is the status for varnish service
● varnish.service - Varnish HTTP accelerator
Loaded: loaded (/lib/systemd/system/varnish.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/varnish.service.d
└─customexec.conf
Active: failed (Result: exit-code) since Wed 2018-03-21 13:59:08 UTC; 2s ago
Docs: https://www.varnish-cache.org/docs/4.1/
man:varnishd
Process: 3093 ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m (code=exited, status=2)
Main PID: 3093 (code=exited, status=2)
Mar 21 13:59:08 bazaar systemd[1]: Stopped Varnish HTTP accelerator.
Mar 21 13:59:08 bazaar systemd[1]: Started Varnish HTTP accelerator.
Mar 21 13:59:08 bazaar varnishd[3093]: Error: Cannot read -f file (/etc/varnish/default.vcl): Permission denied
Mar 21 13:59:08 bazaar systemd[1]: varnish.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Mar 21 13:59:08 bazaar systemd[1]: varnish.service: Unit entered failed state.
Mar 21 13:59:08 bazaar systemd[1]: varnish.service: Failed with result 'exit-code'.
my current user for nginx is bazaar
and permissions for varnish.vcl is as follow
-rw-r--r-- 1 bazaar bazaar 7226 Mar 21 13:24 varnish.vcl
Any hint or help will be highly appreciated.
Thanks.
It is likely that the user (vcache) does not have access to read in the parent directory(s) /var/www/bazaar.

Filebeat Service will not start on RHEL 7

I have a trouble/problem with my Filebeat installation.
When I try it to start with "service filebeat start", it says "Starting Filebeat". After "service filebeat status" I get 4 PIDs (until here everything looks "normal"):
[root#(Server) run]# service filebeat status
Filebeat is running with pid: 30650 30657 30658 30659
But after checking the PID, we see that it is not running:
[root#(Server) run]# ps -ef | grep 30650
root 30665 31360 0 16:27 pts/0 00:00:00 grep --color=auto 30650
Trying to start it with systemctl doesn't help:
[root#(Server) run]# systemctl start filebeat
Job for filebeat.service failed because a configured resource limit was exceeded. See "systemctl status filebeat.service" and "journalctl -xe" for details.
Status says:
[root#Server run]# systemctl status filebeat
● filebeat.service - LSB: start and stop filebeat
Loaded: loaded (/etc/rc.d/init.d/filebeat; bad; vendor preset: disabled)
Active: failed (Result: resources) since Tue 2017-09-26 16:30:33 CEST; 1min 41s ago
Docs: man:systemd-sysv-generator(8)
Process: 32118 ExecStart=/etc/rc.d/init.d/filebeat start (code=exited, status=0/SUCCESS)
Sep 26 16:30:33 Server... systemd[1]: Starting LSB: start and stop filebeat...
Sep 26 16:30:33 Server... filebeat[32118]: Starting Filebeat
Sep 26 16:30:33 Server... su[32119]: (to user) root on none
Sep 26 16:30:33 Server... systemd[1]: PID file /var/run/filebeat.pid not readable (yet?) after start.
Sep 26 16:30:33 Server... systemd[1]: Failed to start LSB: start and stop filebeat.
Sep 26 16:30:33 Server... systemd[1]: Unit filebeat.service entered failed state.
Sep 26 16:30:33 Server... systemd[1]: filebeat.service failed.
Does somebody has any idea?
Regards
Problem was "chown permissions". I installed filebeat not as root and the "data" directory had root user & group ownership. After changing that, it runs and starts automatically after boot.
Regards

systemd: recover from systemctl hang

I have a custom systemd ".service" file, like this one:
[Unit]
Description=MyStuff
After=syslog.target
After=network.target
After=local-fs.target
After=remote-fs.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/MyStuff/start
ExecReload=/bin/kill $MAINPID && /usr/bin/cat /var/run/MyStuff.pid | /usr/bin/xargs --no-run-if-empty /bin/kill
ExecStop=/bin/kill $MAINPID && /usr/bin/cat /var/run/MyStuff.pid | /usr/bin/xargs --no-run-if-empty /bin/kill
ExecStartPost=/usr/local/MyStuff/after_start.sh
PIDFile=/var/run/MyStuff.pid
#RemainAfterExit=yes
TimeoutSec=300
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
It worked fine until minutes ago. A systemctl stop MyStuff hung this way:
[root#Live-1 ffmpeg]# systemctl status WowzaStreamingEngine
● MyStuff.service - MyStuff
Loaded: loaded (/usr/lib/systemd/system/MyStuff.service; enabled; vendor preset: disabled)
Active: deactivating (final-sigkill) (Result: timeout) since vie 2017-07-28 11:12:23 -03; 23min ago
Main PID: 25149
CGroup: /system.slice/MyStuff.service
jul 28 11:12:23 Live-1 kill[10382]: kill: cannot find process "/usr/bin/cat"
jul 28 11:12:23 Live-1 kill[10382]: kill: cannot find process "/var/run/MyStuff.pid"
jul 28 11:12:23 Live-1 kill[10382]: kill: cannot find process "|"
jul 28 11:12:23 Live-1 kill[10382]: kill: cannot find process "/usr/bin/xargs"
jul 28 11:12:23 Live-1 kill[10382]: kill: cannot find process "--no-run-if-empty"
jul 28 11:12:23 Live-1 kill[10382]: kill: cannot find process "/bin/kill"
jul 28 11:12:23 Live-1 systemd[1]: MyStuff.service: control process exited, code=exited status=1
jul 28 11:17:24 Live-1 systemd[1]: MyStuff.service stop-sigterm timed out. Killing.
jul 28 11:22:24 Live-1 systemd[1]: MyStuff.service still around after SIGKILL. Ignoring.
jul 28 11:31:22 Live-1 systemd[1]: MyStuff.service stop-final-sigterm timed out. Killing.
I know there are errors reported there. That is not the problem; I'm not asking about those errors. The problem is: systemd/systemctl hangs in that state, and i'm unable to do start/stop/restart actions because all of them stays waiting forever.
What i need to know is a way around that state. This time I just rebooted the server, because it was development environment. But i can't just deal this way on production.
So: when systemd/systemctl hangs this way, what can I do in order to recover my service from this state without rebooting the server?
Thanks in advance.