Can't start Redis server properly on Ubuntu 20.04 - linux

So I installed Redis and try to start it using systemctl. It stuck at activating service, But however Redis server is already up and running. After that it got SIGTERM scheduling shutdown and restart again and again, forever.
This is my service file.
[Unit]
Description=Advanced key-value store
After=network.target
Documentation=http://redis.io/documentation, man:redis-server(1)
[Service]
Type=forking
ExecStart=/usr/bin/redis-server /etc/redis/redis.conf
PIDFile=/var/run/redis/redis-server.pid
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=2755
UMask=007
PrivateTmp=yes
LimitNOFILE=65535
PrivateDevices=yes
ProtectHome=no
##ReadOnlyDirectories=/
ReadWritePaths=-/var/lib/redis
ReadWritePaths=-/var/log/redis
ReadWritePaths=-/var/run/redis
NoNewPrivileges=true
CapabilityBoundingSet=CAP_SETGID CAP_SETUID CAP_SYS_RESOURCE
MemoryDenyWriteExecute=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectControlGroups=true
RestrictRealtime=true
RestrictNamespaces=true
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
# redis-server can write to its own config file when in cluster mode so we
# permit writing there by default. If you are not using this feature, it is
# recommended that you replace the following lines with "ProtectSystem=full".
ProtectSystem=true
ReadWriteDirectories=-/etc/redis
[Install]
WantedBy=multi-user.target
Alias=redis.service

Related

Do you know how to make the system automatically restart daemon service?

I have made a daemon service in linux server. It is running well. The service file is
stargate.service (in /etc/systemd/system).
[Unit]
Description=stargate
[Service]
Type=simple
PIDFile=/app/stargate/stargate.pid
ExecStart=/app/stargate/stargate.sh start
ExecReload=/app/stargate/stargate.sh restart
ExecStop=/app/stargate/stargate.sh stop
[Install]
Alias=stargate
WantedBy=default.target
If by some reasons, the daemon service is die and stop. Do you know how to make the system automatically restart the daemon service ?
How to make the daemon service starts if server get rebooted?
To respawn your service when it fails, add the following to the [Service] block:
[Service]
Restart=on-failure
RestartSec=3
If you wish to always restart when your service is killed use Restart=always
The RestartSec value is the delay between restart attempts.
See more info here: https://www.freedesktop.org/software/systemd/man/systemd.service.html

Variable is not used in my zookeeper systemd service

I wanted to use Prometheus JMX exporter for Apache Zookeeper which was installed from Kafka package installation. I did according https://alex.dzyoba.com/blog/jmx-exporter/ so I use variable EXTRA_ARGS (+ I also set variable to /etc/enviroment):
export EXTRA_ARGS="-javaagent:/opt/jmx-exporter/jmx_prometheus_javaagent-0.16.1.jar=7070:/opt/jmx-exporter/zookeeper.yaml"
If I start zookeeper by command bellow I can see server listen on port 7070:
/opt/kafka/bin/zookeeper-server-start.sh /opt/kafka/config/zookeeper.properties
But when I tried to start zookeeper by systemd service server does not listen on port 7070. ExecStart is same as command which I started manually from command line.
[Unit]
Requires=network.target remote-fs.target
After=network.target remote-fs.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/opt/kafka/bin/zookeeper-server-start.sh /opt/kafka/config/zookeeper.properties
ExecStop=/opt/kafka/bin/zookeeper-server-stop.sh
Restart=on-abnormal
[Install]
WantedBy=multi-user.target
Does anybody know what I do wrong and how to set properly?
Thanks, Roman
Try
Environment="SERVER_JVMFLAGS=-javaagent:/opt/jmx-exporter/jmx_prometheus_javaagent-0.16.1.jar=7070:/opt/jmx-exporter/zookeeper.yaml"

Auto-starting Twonky Server on Ubuntu 18.04 using systemd

I was trying to set up a Twonky Server on Ubuntu. The server works fine, but I could not get systemd to autostart the server (using a service file I created at /etc/systemd/system/twonkyserver.service). Sometimes I got the cryptic error message that some PID-file (/var/run/mediaserver.pid) is not accessible, the exit code of the service is 13, which apparently is a EACCES Permission denied error . The service runs as root.
I finally managed to fix the problem by setting PIDFile in the twonkyserver.service file to /var/run/mediaserver.pid. For reference, find the service file below:
[Unit]
Description=Twonky Server Service
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/twonky/twonky.sh start
ExecStop=/usr/local/twonky/twonky.sh stop
ExecReload=/usr/local/twonky/twonky.sh reload
ExecRestart=/usr/local/twonky/twonky.sh restart
PIDFile=/var/run/mediaserver.pid
Restart=on-failure
[Install]
WantedBy=multi-user.target
As described above, the below service file auto-starts the Twonky Server on boot. Simply create it using vim /etc/systemd/system/twonkyserver.service. This assumses that you have installed the Twonky Server to usr/local/twonky. The shell-file twonky.sh already provides a nice interface to the service file (twonky.sh start|stop|reload|restart, also see twonky.sh -h).
[Unit]
Description=Twonky Server Service
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/twonky/twonky.sh start
ExecStop=/usr/local/twonky/twonky.sh stop
ExecReload=/usr/local/twonky/twonky.sh reload
ExecRestart=/usr/local/twonky/twonky.sh restart
PIDFile=/var/run/mediaserver.pid
Restart=on-failure
[Install]
WantedBy=multi-user.target
I would slightly amend the start and stop commands from twonky.sh and put them directly into the twonky.service file for systemd:
[Unit]
Description=Twonky Server Service
After=network.target
[Service]
Type=simple
#Systemd will ensure RuntimeDirectory for the PID file is created under /var/run
RuntimeDirectory=twonky
PIDFile=/var/run/twonky/mediaserver.pid
# use the -mspid argument for twonkystarter to put the pid file in the right place
ExecStart=/usr/local/twonky/twonkystarter -mspid /var/run/twonky/mediaserver.pid -inifile /usr/local/twonky/twonkyserver.ini -logfile /usr/local/twonky/twonky.log -appdata /usr/local/twonky
ExecStop=kill -s TERM $MAINPID
ExecStopPost=-killall -s TERM twonkystarter
ExecStopPost=-killall -s TERM twonky
# Twonky 8.5.1 doesn't reload, it stops instead (on arm at least)
# ExecReload=kill -s HUP $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
You need to be sure the paths in the ExecStart command match where you unpacked twonky, and also where you want the .pid file, configuration, logfile and runtime appdataunless you are happy with their default locations.
After putting that all into/etc/systemd/system/twonky.server, run
sudo systemctl daemon-reload
sudo systemctl start twonky
sudo systemctl enable twonky

Node.js on Plesk not starting

I have installed the Node.js Extension and I can't get my app running. I have a Symfony 4 application and I am using socket.io for socket communication. Now I need to startup socket.js to startup my server. This file is located in the resources/js folder.
So I have setup Node.js as below:
Document Root: /application.domain.com/public
Application Mode: production
Application URL: This site is under development
Application Root: /application.domain.com
Application Startup File: resources/js/socket.js
Custom environment variables:
But when I start the application, it is not working. When I run the socket.js file from CLI (SSH connection) like this
/opt/plesk/node/8/bin/node socket.js
It is working fine. But now I need to keep my SSH connection alive and there is no check if socket.js is still running. I suppose the Node.js extension also takes care for that.
How can I use this Node.js extension to startup up my socket.js? Or how could I do this in another way?
OK, I fixed this another way with Systemd.
Found this on https://www.axllent.org/docs/view/nodejs-service-with-systemd/, so credits to Ralph Slooten.
Create the service file
/etc/systemd/system/nodeserver.service
Content
[Unit]
Description=Node.js Example Server
#Requires=After=mysql.service # Requires the mysql service to run first
[Service]
ExecStart=/usr/local/bin/node /opt/nodeserver/server.js
# Required on some systems
#WorkingDirectory=/opt/nodeserver
Restart=always
# Restart service after 10 seconds if node service crashes
RestartSec=10
# Output to syslog
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=nodejs-example
#User=<alternate user>
#Group=<alternate group>
Environment=NODE_ENV=production PORT=1337
[Install]
WantedBy=multi-user.target
Enable the service
systemctl enable nodeserver.service
Start the service
systemctl start nodeserver.service

My server run by systemd service but can't generate log file

I used systemd (ubuntu 16.0.4 LTS) to start MyServer at service (if reboot or crash ocurred, restart automatically by systemd).
It's work fine but it's never generate logs any more!
My server generate logs at file "MyServerLogs" and if this file not exist, create new one (in same running directory).
Also MyServer watch a directory (that create by itself in same running directory) for file creation. This does not work either!
When MyServer run by systemd service, It can not create file, write to file and watch directory for file creation any more. But why?.
I develop MyServer with c++ and beginner of systemd and unit files.
I put MyServer at:
/usr/bin/MyServer
and my unit file
[Unit]
Description=Virtual Distributed Ethernet
After=syslog.target
After=network-online.target
After=network.target
[Service]
ExecStart=/usr/bin/MyServer
Restart=always
StandardOutput=syslog
[Install]
WantedBy=multi-user.target
Thanks for any help.

Resources