Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Systemd, ENV, latest stable Moodle #6

Merged
merged 17 commits into from
Aug 28, 2018
Merged

Systemd, ENV, latest stable Moodle #6

merged 17 commits into from
Aug 28, 2018

Conversation

hrpatel
Copy link
Contributor

@hrpatel hrpatel commented Aug 22, 2018

No description provided.

@hrpatel hrpatel self-assigned this Aug 22, 2018
@hrpatel hrpatel requested review from adamgilbert and mroote August 24, 2018 04:46

[Service]
WorkingDirectory=/etc/moodle-docker
Type=oneshot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a oneshot service? generally that's used for scripts that exit, but this will remain running as a service.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker-compose doesn't stay running, the actual containers are managed by docker

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove the --detach it will stay running, that way the logs show up properly with journalctl.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--detach is safer in prod because it saves on resources.. plus we should have a proper logging solution vs docker -> docker-compose -> journalctl

Some more notes here:
docker/compose#4266 (comment)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, I would much rather we use the 'syslog' docker logging driver and leave compose detached. This is what I'm doing for SDE, and instead of dumping logs into the compose stdout, it will send them to syslog with an appropriate container tag. Let me know if you have questions about this.

Copy link
Contributor

@mroote mroote Aug 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What resources would it be using exactly? The example posted before that comment is the correct way to do this IMO. The proper logging solution is to use this as a simple service and not oneshot. If we send the logs to journald it's easy to then move them elsewhere to a centralized location.

What's the behaviour with stopping a container in a oneshot service? once docker-compose exits the oneshot service will report it's exited successfully. This could leave you in a weird state where the container is running/crashed but systemd is not aware of this.

Also what happens when docker-compose exits but the container stops right after due to an error or some other reason? In this case systemd wont print any errors and the oneshot service will report success even though the container is not running.

Another reason to make this a simple service would be then we can use the Restart and related config fields to ensure the container is brought back up if it exits for some reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed further with @hrpatel, I think we are good to go with the oneshot approach.

RemainAfterExit=yes

ExecStartPre=-/usr/local/bin/docker-compose --file /etc/moodle-docker/docker-compose.yml pull --quiet
ExecStart=/usr/local/bin/docker-compose --file /etc/moodle-docker/docker-compose.yml --file /etc/moodle-docker/dc.prod.yml up --detach
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the container is managed with systemd we don't want to detach from the container here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its cleaner to detach and let docker handle logs/output/etc.. and only use systemd to manage starting and stopping

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep it attached and let systemd handling the logging also? Then systemd can detect if the container crashes or stops for some reason. You will also be able to access the logs through docker but it's easier to use journalctl and get all logs at once.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The syslog logging driver should dump everything to a log file, but we could also try the journald logging driver instead: https://docs.docker.com/config/containers/logging/journald/#options

systemctl --system daemon-reload >/dev/null || true
systemctl enable moodle-docker >/dev/null || true
# Skip starting since we need to configure `.env`
#systemctl start moodle-docker >/dev/null || true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should remove this line if it's not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to uncomment once I automate a couple more things:

  • populate hostname dynamically (if possible) or fail back to IP
    • still need to figure out a lets encrypt solution here
  • auto-generate random passwords for each field in .env

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah alright let's leave this part in for now then.

@hrpatel hrpatel merged commit 4afa81a into master Aug 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants