There is a custom dockerfile with a supervisor for postgresql, a supervisor for ssh and postgres services. I need to throw pg_data on the host, but when I write volume /pg_data:/var/lib/postgresql/11/main postgres in the compose, it cannot start. Can you tell me what is the problem?The error is INFO exited: postgresql (exit status 1; not expected)
Related
I've been following this link to update Postgresql on my Ubuntu-18.04 (VM running on Windows 10)
https://computingforgeeks.com/install-postgresql-12-on-ubuntu/
However, Im getting the below error, so I cannot proceed.
.../desktop/my_app$ systemctl status postgresql.service
System has not been booted with systemd as init system (PID 1). Can't operate.
What can I do?
service postgresql status
or
systemctl status postgresql
Must work.
Can someone give a detailed explanation of how the postgresql service(s) works on Ubuntu [16.04]? The behavior that leads me to ask is the following. I use the command sudo systemctl start postgresql to start my postgresql service. When I run systemctl list-units | grep post I see
UNIT LOAD ACTIVE SUB DESCRIPTION
postgresql.service loaded active exited PostgreSQL RDBMS
postgresql#9.6-main.service loaded active running PostgreSQL Cluster 9.6-main
system-postgresql.slice loaded active active system-postgresql.slice
and when I run sudo systemctl stop postgresql both postgresql.service and postgresql#9.6-main.service disappear. What is each of these three services doing?
I assume postgresql#9.6-main.service is registered service for PostgreSQL Cluster 9.6-main cluster. This is the one that actually controls postgres on your system.
I assume postgresql.service is the effect desribed here
I assume system-postgresql.slice is a postgres slice unit
none of above are critical for running postgres. You can start/stop the cluser with just pg_ctl, without registering it with your services. But if you wonder which service runs it in your case - then it is postgresql#9.6-main.service
One of the annoying things about running Mongodb with docker-compose is if you stop your docker-machine without first stopping the compose containers (eg if you're running a local dev copy and reboot your laptop...) then Mongo gets in a bad state.
When you try and start mongodb again it fails:
$ docker-compose logs mongodb
Attaching to dockerenvironment_mongodb_1
mongodb_1 | about to fork child process, waiting until server is ready for connections.
mongodb_1 | forked process: 12
mongodb_1 | ERROR: child process failed, exited with error number 100
The general advice for this seems to be 'delete the lock file'
However I can't do that because the container has stopped already, I can't exec into it.
If I do (i.e. start a fresh container)
$ docker-compose run mongodb
root#a65901f9fc3d:/# ls /data/db
root#a65901f9fc3d:/#
...there's no lock file to delete.
I have tried also
$ docker rm -v dockerenvironment_mongodb_1
but when I start it fails again with Exit 100
I don't know what else to try, can anyone help?
On Red Hat EL7, I installed Postgres from the standard repository and initialized the database in the usual way:
# postgresql-setup initdb
But when I try to start the service with:
# systemctl start postgresql.service
I get an error:
Job for postgresql.service failed. See 'systemctl status postgresql.service' and 'journalctl -xn' for details.
journalctl -xn gives me:
Oct 06 14:52:55 myserver systemd[1]: Starting PostgreSQL database server...
-- Subject: Unit postgresql.service has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit postgresql.service has begun starting up.
Oct 06 14:52:55 myserver systemd[29267]: Failed at step USER spawning /usr/bin/postgresql-check-db-dir: No such process
-- Subject: Process /usr/bin/postgresql-check-db-dir could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The process /usr/bin/postgresql-check-db-dir could not be executed and failed.
--
-- The error number returned while executing this process is 3.
Anyone have any ideas?
I don't consider this a complete and proper fix, but it's what I'd call a "strong workaround". The problem seems to start with the fact that this Linux system can authenticate locally as well as through a directory server. The PostgreSQL package tries to create a user:group combo called postgres:postgres. The user "postgres" wasn't created because it already exists in the directory server. The group "postgres" was created locally.
When systemd starts Postgres, it changes into the postgres user before trying to call postgresql-check-db-dir which is a script that checks whether the database directory has been intialized with postgresql-setup initdb. It seems that systemd can't change to this directory-supplied postgres user.
My work-around was to create a new local user ("pgsql") and change the ownership of /var/lib/pgsql and /var/run/postgresql to this new user, then create a custom systemd service file called /etc/systemd/system/postgresql.service to override the default one. The contents of this file are:
.include /usr/lib/systemd/system/postgresql.service
[Service]
User=pgsql
Group=postgres
That allows Postgres to be started and stopped by systemd.
For me the logs are telling you that the db path does not exist. Are you sure psql is configured correctly, the db path exists and you have permission to access it ?
I have installed mongodb on a docker container together with openssh on ubuntu 14.04. The container is running with ssh but when I ssh into the container I get the following error when trying to start mongod.
root#430f9502ba2d:~# service mongod start
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mongod start
Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start mongod
Also start mongod does not affect anything.
Tried looking at this also Mongo daemon doesn't run by service mongod start without it helping.
mongod --config /your/path/to/mongod.conf doesn't seem to work also, just locks up.
The error below is standard as of course there is no mongod server running.
root#430f9502ba2d:/# mongo
MongoDB shell version: 2.6.9
connecting to: test
2015-05-07T20:49:56.213+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-05-07T20:49:56.214+0000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
The problem here is your approach. Docker does not have an init system like you are used to on traditional systems. What docker does is replace PID 1 with the process you specify in the CMD or ENTRYPOINT Dockerfile commands. For now, ignore ENTRYPOINT, because it replaces what your CMD is run with (normally, it's /bin/sh -c). You need to instruct docker to start your mongod service in your Dockerfile with the CMD command, like:
CMD usr/bin/mongod
And when you run your container, mongod will be your PID 1. Now, you're probably wondering at this point "But what about my SSH server?" and the answer is: Don't run an SSH server on your docker containers. There are some use cases where running an SSH server is okay, but almost all of the "normal" reasons (debug, C&C, etc) are nullified with the "best practice" for getting a shell on your container:
docker exec -it myContainer /bin/bash
This will drop you into a shell on your running container. The recommendation here for managing configuration and changes in your docker container is to use something like Ansible. However, remember that docker containers are ephemeral, and you shouldn't be restarting services and changing configuration state on them. If you need a config change, change the Dockerfile or config data, and then start a new container. Good luck! Here is a little more information on Dockerizing MongoDB, but keep in mind that the method described there alters the ENTRYPOINT in the Dockerfile, which is a little more involved and requires a better understanding of what's going on in Dockerfiles.
This is really helpful. I was trying to make old Ansible playbooks work with Docker by creating several blank containers and let Ansible do the rest.
It works through command
mongod --dbpath /var/lib/mongodb --smallfiles