Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to stop nagios in container #51

Closed
dm2pg opened this issue Jan 30, 2018 · 10 comments
Closed

How to stop nagios in container #51

dm2pg opened this issue Jan 30, 2018 · 10 comments

Comments

@dm2pg
Copy link

dm2pg commented Jan 30, 2018

How can I stop nagios inside container without automatic stop of complete docker container. I want to replace /opt/nagios with an "old" one with backup data inside...

@tronyx
Copy link

tronyx commented Jan 31, 2018

I believe the process would be:

  1. Remove the Nagios service dir: docker exec nagios rm etc/service/nagios
  2. Do your work.
  3. Recreate the symbolic link to start it again: docker exec nagios ln -s /etc/sv/nagios /etc/service

My container name is nagios, but yours may not be so you would need to adapt the commands accordingly.

@tronyx
Copy link

tronyx commented Jan 31, 2018

This doesn't actually appear to work. Hopefully Jason can enlighten us as I hate having to restart the container every time I change something with the config.

@JasonRivers
Copy link
Owner

I don't really understand why you would do this? The point of this container is that it's running an up to date Nagios, if you're going to replace Nagios in the container, why not just create a fresh container for the older version?

Replacing files inside a running container is also a bad idea, if the container is updated you'd have to replace the files every time, a better way to do it would be to use a Docker file FROM jasonrivers/nagios - But I still don't understand the point, The image is created with Nagios, if you want an older version of Nagios, personally I would create a fresh container.

Which version of Nagios are you trying to run?

@dm2pg
Copy link
Author

dm2pg commented Jan 31, 2018 via email

@JasonRivers
Copy link
Owner

Use docker cp to copy the configs out of the container, you shouldn't store your configs in the container, you should use a volume to store configs in. (using -v when running the container).

If you wish to add extras to the image, you can create a Dockerfile with FROM jasonrivers/nagios and then add in any extra applications you want.
The point of Docker is that you can regenerate the image easily and re-create the container at any time, if you store you configuration inside the container then you lose that ability.

@dm2pg
Copy link
Author

dm2pg commented Jan 31, 2018 via email

@bpsizemore
Copy link

Since you didn't originally mount the container to a volume to write your data, try using the docker cp utility.

$: docker cp --help

Usage:	docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
	docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH

Copy files/folders between a container and the local filesystem

Options:
  -a, --archive       Archive mode (copy all uid/gid information)
  -L, --follow-link   Always follow symbol link in SRC_PATH

Docker containers aren't designed to be used in the same way a traditional server would use them. E.g. If you run nagios on the host machine, you might periodically update configs manually and copy out data. To do this same setup on docker, you would keep a copy of your nagios config and build a new container everytime you want to update the container. You could also use a docker volume to mount the directory in the container where data is stored, to somewhere on the localhost, so that could be reused in other containers and easily saved for other use.

As an example, here is what my nagios repo looks like...

/nagios-repo/
----etc/ *where config is stored*
----libexec/ *where plugins are stored*
----Dockerfile
----Readme
----nagios_key.pem *ssh-key*

Then my dockerfile looks like

From jasonrivers/nagios

# Put Config Files in place
COPY ./etc/ /opt/nagios/etc
RUN mkdir -p /home/nagios/.ssh/

COPY ./libexec/ /opt/nagios/libexec/

# Setup Nagios Key Communication
COPY nagios_key.pem /opt/nagios/.ssh/nagios_key.pem
RUN chown nagios:nagios /opt/nagios/.ssh/nagios_key.pem && chmod 700 /opt/nagios/.ssh/nagios_key.pem

CMD [ "/usr/local/bin/start_nagios" ]

Anytime I need to update or change my nagios config. I take the following steps:

  1. Update config in repo
  2. docker build . -t nagios
  3. docker run -d --name nagios_container -p 0.0.0.0:3000:80 nagios

The only difference is that you are wanting to save data so will need to add a volume that mounts from a dir on your host to somewhere in the container where the data is stored.

@byron6910
Copy link

How Can eject the commadn "service restart nagios in the docker" ? I do change in the configuration file to add a new host. Thanks

@davralin
Copy link

Restart the container.

@Kolossi
Copy link

Kolossi commented Apr 21, 2021

... or if the UI is running, just click the "Process Info" link near the bottom of the right hand menu (under "System" heading), then click "Restart the Nagios Process" link on the right under the "Process commands" heading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants