Failed to restart redis-server.service: Unit redis-server.service not found - node.js

Tried to start redis-server but got:
26195:C 27 Aug 17:05:11.684 # Warning: no config file specified, using
the default config. In order to specify a config file use redis-server
/path/to/redis.conf
26195:M 27 Aug 17:05:11.684 * Increased maximum number of open files
to 10032 (it was originally set to 1024).
26195:M 27 Aug 17:05:11.685 # Creating Server TCP listening socket
*:6379: bind: Address already in use
Ran lsof -wni tcp:3000 and killed the local host and tried restarting redis-server again and got the same above error.
Tried: ps -aux | grep redis (output below), then sudo kill -9 6379
nick4896 12238 0.0 0.1 41432 9048 ? Sl Aug26 0:14
redis-server *:6379
nick4896 26304 0.0 0.0 21300 984 pts/21 S+ 17:08 0:00 grep
--color=auto redis
And ran sudo service redis-server restart, and got:
Failed to restart redis-server.service: Unit redis-server.service not
found.
Any ideas?

The problem is that symlink redis-server.service to redis.service was deleted.
Command
sudo systemctl enable redis-server
creates the symlink:
Created symlink /etc/systemd/system/redis.service → /lib/systemd/system/redis-server.service.

Came across this, I would suggest systemctl daemon-reload

Not an answer, but to complete Igor Kavzov's answer, this is the code to enter at the terminal:
sudo ln /lib/systemd/system/redis.service /etc/systemd/system/redis-server.service

Related

How to stop a redis server that was started with --daemonize yes

I'm trying to kill a redis server that was started with --daemonize yes
I feel like this should be easy, but I am unable to successfully kill it based on standard methods. I'm using Redis 3.2 installed via these instructions: https://www.hugeserver.com/kb/install-redis-debian-ubuntu/
$ redis-server --daemonize yes
1550:C 13 Mar 05:54:55.436 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1550:C 13 Mar 05:54:55.437 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=1550, just started
1550:C 13 Mar 05:54:55.437 # Configuration loaded
$ kill 1550
-bash: kill: (1550) - No such process
$ kill -9 1550
-bash: kill: (1550) - No such process
$ killall redis-server
redis-server(1181): Operation not permitted
redis-server: no process found
$ /etc/init.d/redis-server stop
[....] Stopping redis-server (via systemctl): redis-server.service==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to stop 'redis-server.service'.
Authenticating as: Ubuntu (ubuntu)
Password:
Why should I need to enter a password to stop it? I never set a password when i started it. And why doesn't kill work? Even if I sudo it, it just restarts again after.
-------------------EDIT-------------------
Additional information. Using the kill command on the process ID doesn't work. I have to use sudo kill but then it comes back with another processid as if something restarts it. I just killed it 3 times and it's back again with a 4th processid –
---------- Solution thanks to #Kevin Law ----------
I needed to kill the daemonized service and then kill the process. Not just one or the other...
ubuntu#ip-MyIPAddress:~/Relayer$ ps -ef | grep redis-server
ubuntu 2381 1 0 18:39 ? 00:00:00 redis-server *:6379
ubuntu 2386 1358 0 18:39 pts/0 00:00:00 grep --color=auto redis-server
ubuntu#ip-MyIPAddress:~/Relayer$ sudo service redis-server stop
ubuntu#ip-MyIPAddress:~/Relayer$ ps -ef | grep redis-server
ubuntu 2381 1 0 18:39 ? 00:00:00 redis-server *:6379
ubuntu 2418 1358 0 18:39 pts/0 00:00:00 grep --color=auto redis-server
ubuntu#ip-MyIPAddress:~/Relayer$ kill 2381
ubuntu#ip-MyIPAddress:~/Relayer$ ps -ef | grep redis-server
ubuntu 2420 1358 0 18:39 pts/0 00:00:00 grep --color=auto redis-server
ubuntu#ip-MyIPAddress:~/Relayer$
There are three options for your question from my test.
Stop redis by stoping redis service. This is the recommend way in most cases.
sudo systemctl stop redis-server
or
sudo service redis-server stop
connect to this redis-server and shutdown it by redis-cli.
redis-cli
after connected to redis, issue shutdown to turn off redis-server
shutdown
Kill the redis-server process directly:
ps -ef | grep redis-server
kill -9 (pid)
Try following command to find the redis-server instances that are running and then try killing the exact instance with kill command.
ps -aef | grep redis

Apache2: "Address already in use" when trying to start it ('httpd.pid' issue?)

Using Apache2 on Linux, I get this error message when trying to start it.
$ sudo /usr/local/apache2/bin/apachectl start
httpd not running, trying to start
(98)Address already in use: make_sock: unable to listen for connections on address 127.0.0.1:80
no listening sockets available, shutting down
Unable to open logs
$ sudo /usr/local/apache2/bin/apachectl stop
httpd (no pid file) not running
Some facts:
This is one of the last lines in my Apache logs:
[Mon Jun 19 18:29:01 2017] [warn] pid file /usr/local/apache2/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
My '/usr/local/apache2/conf/httpd.conf' contains
Listen 127.0.0.1:80
I have "Listen 80" configured at '/etc/apache2/ports.conf'
Disk is not full
I've checked that I do not have two or more "Listen" at '/usr/local/apache2/conf/httpd.conf'
Some outputs:
$ sudo ps -ef | grep apache
root 1432 1 0 17:35 ? 00:00:00 /usr/sbin/apache2 -k start
www-data 1435 1432 0 17:35 ? 00:00:00 /usr/sbin/apache2 -k start
www-data 1436 1432 0 17:35 ? 00:00:00 /usr/sbin/apache2 -k start
myuserr 1775 1685 0 17:37 pts/1 00:00:00 grep --color=auto apache
$ sudo grep -ri listen /etc/apache2
/etc/apache2/apache2.conf:# supposed to determine listening ports for incoming connections which can be
/etc/apache2/apache2.conf:# Include list of ports to listen on
/etc/apache2/ports.conf:Listen 80
/etc/apache2/ports.conf: Listen 443
/etc/apache2/ports.conf: Listen 443
What can I do to restart Apache? Should I repair 'httpd.pid'?
This error means that something already uses 80 port.
If you really don't have 2 line of Listen 80 in apache configurations then execute this command to see what uses 80 port: netstat -antp | grep 80.
I fixed it by killing the three processes
root 1621 1 0 18:46 ? 00:00:00 /usr/sbin/apache2 -k start
www-data 1624 1621 0 18:46 ? 00:00:00 /usr/sbin/apache2 -k start
www-data 1625 1621 0 18:46 ? 00:00:00 /usr/sbin/apache2 -k start
However, each time I want to reboot my server, I must kill thee processes. What is starting them?

How can we check if our mongodb is running on EC2 linux server?

I have installed and started the MongoDB on EC2 Linux instance. How can I verify whether it is running or not?
1 way I got to know how to verify whether it is started or not is:
By checking the contents of the file at /var/log/mongodb/mongod.log for a line reading: [initandlisten] waiting for connections on port which I have not got.
What can be more ways to check?
You can check whether using a third party tool such as Mongoclient to check if you're able to connect your database. Or use one of the below methods:
Check processes that are working on:
ps -efl | grep mongo
ps -efl returns a list of processes that are being worked on your system right now, and you can use a pipe and grep to select only processes you wish, in this situation mongo.
This should return something like:
1 S sandsto+ 6997 6992 0 80 0 - 193376 - May22 ? 00:13:27 /bin/mongod --fork --bind_ip 127.0.0.1 --port 6081 --dbpath /var/mongo --logpath /var/log/mongo.log --pidfilepath /var/pid/mongo.pid --auth --nohttpinterface --noprealloc --nopreallocj --smallfiles --replSet ssrs --oplogSize 16
0 S sercan 8857 8827 0 80 0 - 85041 - May22 ? 00:20:58 mongod --storageEngine=wiredTiger
0 S sercan 29511 29471 2 80 0 - 67236 futex_ 13:41 pts/21 00:00:00 ./mongod --dbpath /home/sercan/mongo_data/
0 S sercan 29547 29529 0 80 0 - 3907 pipe_w 13:41 pts/22 00:00:00 grep --color=auto mongo
You can see there's a script ./mongod here that's working right now.
Either you can check ports that are being used by the system with command:
netstat -an | grep 27017
netstat -an returns all the allocated ports currently in the system and if you know your mongodb's port you can easily grep it from here. And this will return:
unix 2 [ ACC ] STREAM LISTENING 4184968 /tmp/mongodb-27017.sock
If you see LISTENING here, it means it's currently working.
But best way is adding mongodb to a system service manager such as supervisord, therefore you can simply check if your mongod is running with a single command:
sudo supervisorctl status
p.s. supervisor is just an example, there're a lot of process managers in linux that you can use, even mongodb documents have explanations about them.
You could check with this command
systemctl status mongod
and then you would see either of these results
1,
If it is inactive rung this command
systemctl start mongod
2,

Can't stop/restart Apache2 service

Trying to stop Apache2 service, but get PID error:
#service apache2 stop
[FAIL] Stopping web server: apache2 failed!
[....] There are processes named 'apache2' running which do not match your pid file which are left untouched in the name of safety, Plea[warnview the situation by hand. ... (warning).
Trying to kill, those processes:
#kill -9 $(ps aux | grep apache2 | awk '{print $2}')
but they get re-spawned again:
#ps aux | grep apache2
root 19279 0.0 0.0 4080 348 ? Ss 05:10 0:00 runsv apache2
root 19280 0.0 0.0 4316 648 ? S 05:10 0:00 /bin/sh /usr/sbin/apache2ctl -D FOREGROUND
root 19282 0.0 0.0 91344 5424 ? S 05:10 0:00 /usr/sbin/apache2 -D FOREGROUND
www-data 19284 0.0 0.0 380500 2812 ? Sl 05:10 0:00 /usr/sbin/apache2 -D FOREGROUND
www-data 19285 0.0 0.0 380500 2812 ? Sl 05:10 0:00 /usr/sbin/apache2 -D FOREGROUND
And though the processes are running i can't connect to the server on port 80. /var/log/apache2/error.log.1 has no new messages when i do the kill -9.
Before I tried to restart everything worked perfectly.
Running on Debian: Linux adara 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux
UPD:
also tried apache2ctl:
#/usr/sbin/apache2ctl -k stop
AH00526: Syntax error on line 76 of /etc/apache2/apache2.conf:
PidFile takes one argument, A file for logging the server process ID
Action '-k stop' failed.
The Apache error log may have more information.
but there is no pid file in /var/run/apache2
I'm new to linux, looks like it has to do something with startup scripts, but can't figure out what exactly.
Below is the command to find out the process running on port 80
lsof -i tcp:80
Kill the process with PID.Restart the system once to check if their is any start up script executing and using the Port 80 which is preventing you to start your service.
For start up scripts you can check
/etc/init.d/ or /etc/rc.local or crontab - e
You can try Apache official documentation for stop/restart operations.
link

Apache 2.4 hits rlimit_nproc: hidden processes?

My webapp allows users to execute some arbitrary code in a sandbox. To prevent forkbombs, the application calls setrlimit and limits RLIMIT_NPROC to 50 before executing user code. This worked great in Ubuntu 12.04 up till Ubuntu 13.04. However, after upgrading to Ubuntu 13.10 (which ships with Apache 2.4 and Linux 3.11), we hit the limit of 50 www-data processes, even when Apache2 is idle!
The problem is most easily reproduced by running bash as user www-data with ulimit. First switch into user www-data and start bash:
jeroen#Ubuntu:/$ sudo su www-data
$ bash
www-data#Ubuntu:/$
Now gradually lower RLIMIT_NPROC until we hit problems:
#RLIMIT_NPROC=100: works fine
www-data#Ubuntu:/$ ulimit -u 100
www-data#Ubuntu:/$ ls
bin dev initrd.img lib64 mnt root srv usr vmlinuz.old
boot etc initrd.img.old lost+found opt run sys var
cdrom home lib media proc sbin tmp vmlinuz
#RLIMIT_NPROC=50: limit reached
www-data#Ubuntu:/$ ulimit -u 50
www-data#Ubuntu:/$ ls
bash: fork: retry: No child processes
bash: fork: retry: No child processes
bash: fork: Resource temporarily unavailable
Hence after setting RLIMIT_NPROC to 50, the process can no longer fork. This implies that there are already 50 or more processes running as user www-data. However, this does not seem to be the case, the server is just a blank idle Apache 2.4. According to ps, there are currently only 2 procs owned by www-data:
jeroen#Ubuntu:~$ ps aux | grep www-data
www-data 11473 0.0 0.5 631296 46164 ? Sl 14:28 0:01 /usr/sbin/apache2 -k start
www-data 11474 0.0 0.5 565656 45632 ? Sl 14:28 0:01 /usr/sbin/apache2 -k start
jeroen 12136 0.0 0.0 13644 956 pts/4 S+ 14:51 0:00 grep --color=auto www-data
So why is www-data is hitting the RLIMIT_NPROC limit of 50 in Apache 2.4, even when idle?
Found the problem thanks to the suggestion from #sarnold. My Application depends on mpm_prefork and up till Ubuntu 13.04, this module was automatically enabled when the apache2-mpm-prefork package is installed. I assumed this was still the case, but it turned out that it was running mpm_event.
It seems that in Apache 2.4 the packaging of MPM's has changed and mpm_prefork needs to be enabled manually after installation:
sudo a2dismod mpm_event
sudo a2enmod mpm_prefork
sudo service apache2 restart
Now the problems seem to have disappeared.

Resources