redis-server auto restart - redis

i have a question here..
i already install redis-server on my CentOS vps for my wordpress frontend cache..
but i have a little problem here..
sometimes my redis-server was closed/disconnected suddenly, and i must have to restart it manually using command
/etc/init.d/redis-server start
my question is..
how to auto start the redis-server if my redis-server down or crashed suddenly..
i install redis using this tutorial
http://www.saltwebsites.com/2012/install-redis-245-service-centos-6
great thanks before

how to auto start the redis-server if my redis-server down or crashed
suddenly
Try to look at tools like upstart or monit which can be used to respawn redis if it dies unexpectedly.

If you use docker with docker-compose:
version: '3'
services:
redis:
container_name: "redis"
image: redis:5.0.3-alpine
command: ["redis-server", "--appendonly", "yes"]
hostname: redis
ports:
- "6339:6379"
volumes:
- /opt/docker/redis:/data
restart:
always
look at the last line:
restart: always

I Don't know exactly with centos with linux
sudo systemctl enable redis_6379
The above worked like charm ,The above will create a symlink in /etc/systemd/system/redis_6379.service.

Related

How to run a command when Docker container restarts

I'm new to using Docker and docker-compose so apologies if I have some of the terminology wrong.
I've been provided with a Dockerfile and docker-compose.yml and have successfully got the images built and container up and running (by running docker-compose up -d), but I would like to update things to make my process a bit easier as occasionally I need to restart Apache on the container (WordPress) by accessing it using:
docker exec -it 89a145b5ea3e /bin/bash
Then typing:
service apache2 restart
My first problem is that there are two other services that I need to run for my project to work correctly and these don't automatically restart when I run the above service apache2 restart command.
The two commands I need to run are:
service memcached start
service cron start
I would like to know how to always run these commands when apache2 is restart.
Secondly, I would like to configure my Dockerfile or docker-compose.yml (not sure where I'm supposed to be adding this) so that this behaviour is baked in to the container/image when it is built.
I've managed to install the services by adding them to my Dockerfile but can't figure out how to get these services to run when the container is restart.
Below are the contents for relevant files:
Dockerfile:
FROM wordpress:5.1-php7.3-apache
RUN yes | apt-get update -y \
&& apt-get install -y vim \
&& apt-get install -y net-tools \
&& apt-get install -y memcached \
&& apt-get install -y cron
docker-compse.yml
version: "3.3"
services:
db:
image: mysql:5.7
volumes:
- ./db_data:/var/lib/mysql:consistent
ports:
- "3303:3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: vagrant
MYSQL_DATABASE: wp_database
MYSQL_USER: root
MYSQL_PASSWORD: vagrant
wordpress:
container_name: my-site
build: .
depends_on:
- db
volumes:
- ./my-site-wp:/var/www/html/:consistent
ports:
- "8001:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: vagrant
WORDPRESS_DB_NAME: wp_database
volumes:
db_data:
my-site-wp:
...occasionally I need to restart Apache on the container (WordPress)...
Don't do that. It's a really, really bad habit. You're treating the container like a server where you go in and fix things that break. Think of it like it's a single application -- if it breaks, restart the whole dang thing.
docker-compose restart wordpress
Or restart the whole stack, even.
docker-compose restart
Treat your containers like cattle not pets:
Simply put, the “cattle not pets” mantra suggests that work shouldn’t grind to a halt when a piece of infrastructure breaks, nor should it take a full team of people (or one specialized owner) to nurse it back to health. Unlike a pet that requires love, attention and more money than you ever wanted to spend, your infrastructure should be made up of components you can treat like cattle – self-sufficient, easily replaced and manageable by the hundreds or thousands. Unlike VMs or physical servers that require special attention, containers can be spun up, replicated, destroyed and managed with much greater flexibility.)
Per each container in the compose file, you can add a run command flag in the yaml which will run a command AFTER your container has started. This will run during every start up. On the other hand, commands in the Dockerfile will only run when the image is being built. Ex:
db:
image: mysql:5.7
volumes:
- ./db_data:/var/lib/mysql:consistent
command: # bash command goes here
ports:
- "3303:3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: vagrant
MYSQL_DATABASE: wp_database
MYSQL_USER: root
MYSQL_PASSWORD: vagrant
However, this is not what you are after. Why would you mess with a container from another container? The depends_on flag should restart the downstream services. It seems your memcache instance isn't docked and hence, you are trying to fit it in the application level logic, which is the antithesis of Docker. This code should be in the infra level from the machine or the orchestrator (eg. Kubernetes).

Docker-compose can't start apache server

When i'm running sudo docker-compose up inside my dir, i get this error. I'm trying to make a container, that host a php website, where you can do whoami on it.
Thanks
(13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:80
| no listening sockets available, shutting down
| AH00015: Unable to open logs
Dockerfile:
FROM ubuntu:16.04
RUN apt update
RUN apt install -y apache2 php libapache2-mod-php
RUN useradd -d /home/cp/ -m -s /bin/nologin cp
WORKDIR /home/cp
COPY source .
USER cp
ENTRYPOINT service apache2 start && /bin/bash
docker-compose.yml
version: '2'
services:
filebrowser:
build: .
ports:
- '8000:80'
stdin_open: true
tty: true
volumes:
- ./source:/var/www/html
- ./logs:/var/log/apache2
There's a long-standing general rule in Unix-like operating systems that only the root user can open "low" ports 0-1023. Since you're trying to run Apache on the default HTTP port 80, but you're running it as a non-root user, you're getting the "permission denied" error you see.
The absolute easiest answer here is to use a prebuilt image that has PHP and Apache preinstalled. The Docker Hub php image includes a variant of this. You can use a simpler Dockerfile:
FROM php:7.4-apache
# Has Apache, mod-php preinstalled and a correct CMD already,
# so the only thing you need to do is
COPY source /var/www/html
# If you want to run as a non-root user, you can specify
RUN useradd -r -U cp
ENV APACHE_RUN_USER cp
ENV APACHE_RUN_GROUP cp
With the matching docker-compose.yml
version: '3' # version 2 vs 3 doesn't really matter
services:
filebrowser:
build: .
ports:
- '8000:80'
volumes:
- ./logs:/var/log/apache2
If you want to build things up from scratch, the next easiest option would be the Apache User directive: have your container start as root (so it can bind to port 80) but then instruct Apache to switch to the unprivileged user once it's started up. The standard php:...-apache image has an option to do this on its own which I've shown above.

Docker stack: Apache service will not start

Apache service in docker stack never starts (or, to be more accurate, keeps restarting). Any idea what's going on?
The containers are the ones in: https://github.com/adrianharabula/lampstack.git
My docker-compose.yml is:
version: '3'
services:
db:
image: mysql:5.7
volumes:
- ../db_files:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: toor
#MYSQL_DATABASE: testdb
#MYSQL_USER: docky
#MYSQL_PASSWORD: docky
ports:
- 3306:3306
p71:
# depends_on:
# - db
image: php:7.1
build:
context: .
dockerfile: Dockerfile71
links:
- db
volumes:
- ../www:/var/www/html
- ./php.ini:/usr/local/etc/php/conf.d/php.ini
- ./virtualhost-php71.conf:/etc/apache2/sites-available/001-virtualhost-php71.conf
- ../logs/71_error.log:/var/www/71_error.log
- ../logs/71_access.log:/var/www/71_access.log
environment:
DB_HOST: db:3306
DB_PASSWORD: toor
ports:
- "81:80"
pma:
depends_on:
- db
image: phpmyadmin/phpmyadmin
And I start it with:
docker stack deploy -c docker-compose.yml webstack
db and pma services start correctly, but p71 service keeps restarting
docker service inspect webstack_p71
indicates:
"UpdateStatus": {
"State": "paused",
"StartedAt": "2018-01-19T16:28:17.090936496Z",
"CompletedAt": "1970-01-01T00:00:00Z",
"Message": "update paused due to failure or early termination of task 45ek431ssghuq2tnfpduk1jzp"
}
As you can see by the docker-composer.yml I already commented out the service dependency to avoid failures if dependencies are not met at first run.
$ docker service logs -f webstack_p71
$ docker service ps --no-trunc webstack_p71
What should I do to get that Apache/PHP (p71) service running?
All the containers work when run independently:
$ docker build -f Dockerfile71 -t php71 .
$ docker run -d -p 81:80 php71:latest
First of all, depends_on option doesn't work in swarm mode of version 3.(refer this issue)
In short...
depends_on is a no-op when used with docker stack deploy. Swarm mode
services are restarted when they fail, so there's no reason to delay
their startup. Even if they fail a few times, they will eventually
recover.
Of course, even though depends_on doesn't work, p71 should work properly since it would restart after the failure.
Thus, I think there is some error while running p71 service. that would be why the service keeps restarting. however, I am not sure what is happening inside the service only with the information you offer.
You could check the trace by checking log.
$ docker service logs -f webstack_p71
and error message
$ docker service ps --no-trunc webstack_p71 # check ERROR column

How do I stop the RabbitMQ server on localhost

I installed RabbitMQ server on OS X, and started it on command line. Now, it is not obvious that how I should stop it from running? After I did:
sudo rabbitmq-server -detached
I get:
Activating RabbitMQ plugins ...
0 plugins activated:
That was it. How should I properly shut it down? In the document, it mentions using rabbitmqctl(1), but it's not clear to me what that means. Thanks.
Edit: As per comment below, this is what I get for running sudo rabbitmqctl stop:
(project_env)mlstr-1:Package mlstr$ sudo rabbitmqctl stop
Password:
Stopping and halting node rabbit#h002 ...
Error: unable to connect to node rabbit#h002: nodedown
DIAGNOSTICS
===========
nodes in question: [rabbit#h002]
hosts, their running nodes and ports:
- h002: [{rabbit,62428},{rabbitmqctl7069,64735}]
current node details:
- node name: rabbitmqctl7069#h002
- home dir: /opt/local/var/lib/rabbitmq
- cookie hash: q7VU0JjCd0VG7jOEF9Hf/g==
Why is there still a 'current node'? I have not run any client program but only the RabbitMQ server, does that mean a server is still running?
It turns out that it is related to permissions. Somehow my rabbitmq server was started with user 'rabbitmq' (which is strange), so that I had to do
sudo -u rabbitmq rabbitmqctl stop
In my dev environment where I keep it running all the time, I use:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.rabbitmq.plist
and to start it
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.rabbitmq.plist
Even easier....
brew services stop rabbitmq
brew services start rabbitmq
Use rabbitmqctl stop to stop any node. If you need to specify the node giving you trouble, add the -n rabbit#[hostname] option.
You can also use the shortcut RabbitMQ Service - stop if you don't like the commands
stop
sudo systemctl stop rabbitmq-server
start
sudo systemctl start rabbitmq-server
For Windows, use PowerShell as Admin, then run
.\rabbitmq-service.bat stop
stop Stop the service. The service must be running for this command to have any effect.
https://www.rabbitmq.com/man/rabbitmq-service.8.html
For OP's answer above,
It turns out that it is related to permissions.
I have no knowledge on this.
For mac users
To Stop
brew services stop rabbitmq
To Start
brew services start rabbitmq
To Restart
brew services restart rabbitmq
To Know the status of the server
brew services info rabbitmq

"node with name "rabbit" already running", but also "unable to connect to node 'rabbit'"

Rabbitmq server does not start, saying it's already running:
$: rabbitmq-server
Activating RabbitMQ plugins ...
0 plugins activated:
node with name "rabbit" already running on "android-d1af002161676bee"
diagnostics:
- nodes and their ports on android-d1af002161676bee: [{rabbit,52176},
{rabbitmqprelaunch2254,
59205}]
- current node: 'rabbitmqprelaunch2254#android-d1af002161676bee'
- current node home dir: /Users/Jordan
- current node cookie hash: ZSx3slRJURGK/nHXDTBRqQ==
But, rabbitmqctl seems to think otherwise:
rabbitmqctl -n rabbit status
Status of node 'rabbit#android-d1af002161676bee' ...
Error: unable to connect to node 'rabbit#android-d1af002161676bee': nodedown
diagnostics:
- nodes and their ports on android-d1af002161676bee: [{rabbit,52176},
{rabbitmqctl2462,59256}]
- current node: 'rabbitmqctl2462#android-d1af002161676bee'
- current node home dir: /Users/Jordan
- current node cookie hash: ZSx3slRJURGK/nHXDTBRqQ==
Any takers?
The rabbitmq server was running somewhere but it just couldn't be connected to.
One of the following will mention something about rabbits:
$: ps aux | grep epmd
$: ps aux | grep erl
Kill the process with kill -9 {pid of rabbitmq process}
i was having the same problem then I realized I was not issuing the right command.
./rabbitmqctl stop
this works everytime, although it does take down erlang runtime too. also mind where your config file.
I used rabbitmqctl stop and then restarted using rabbitmq-server as root.
This issue can be caused by two issues:
Rabbit is already running on the server. If that is the case, use the answer you found of killing the currently running process (ps aux | grep rabbit | grep -v grep)
You have changed the IP address of your machine but not changed the /etc/hosts file to reflect the new IP address of the machine.
The more common of the issues is the first, but the harder to find is the second (especially if you have rabbit running on the other machine. If rabbit is installed on the other machine it will look at the old IP address and would see another machine already running rabbitmq and give you the same error. This has caused me grief in the past.
I was having this same error # Win 7, but the solutions above did not worked for me, what did solved was to remove and reinstall the service. Using a console with admin rights:
rabbitmq-service remove
rabbitmq-service install
I hope this might help someone else too
$CD RabbitMQ Server\rabbitmq_server-3.7.8\sbin
rabbitmq-service remove
rabbitmq-service install
Go : windows Services
Find : RabbitMQ and Start it
after this Enable plugin :
rabbitmq-plugins enable rabbitmq_management
In my case under Ubuntu 11.10 it helped to
#rabbitmqctl cluster MASTER SLAVE
#rabbitmqctl start_app
before I always got this error message...
Using admin console, in Win 2012R2 ver 3.5.5 rabbit, got it to work using the remove and install then rabbitmq-server restart
then ctr-c to terminate the job, then I was able to use the windows service console and start the rabbitMq service.
In my case(windows),
1. I just ran the stop service.
2. The started the service.