Add service, update, and README files

This commit is contained in:
Wojciech Kozlowski 2018-01-24 22:46:39 +00:00
parent a65286dccf
commit 520eb68dcf
4 changed files with 138 additions and 0 deletions

View File

@ -1,3 +1,17 @@
# -----------------------------------------------------------------------------
# Install the service file.
# -----------------------------------------------------------------------------
install:
cp loki-server.service /lib/systemd/system/
systemctl daemon-reload
systemctl enable loki-server
uninstall:
systemctl disable loki-server
rm /lib/systemd/system/loki-server.service
systemctl daemon-reload
# -----------------------------------------------------------------------------
# The container registry to use.
# -----------------------------------------------------------------------------

55
README.rst Normal file
View File

@ -0,0 +1,55 @@
Loki
====
Docker files for my server, Loki.
Installation
------------
The following command will install the service file, reload systemd, and enable
the service
::
make install
Uninstall with
::
make uninstall
Usage
-----
To start the service run
::
service loki-server start
To stop run
::
service loki-server stop
To restart
::
service loki-server restart
Note that ``docker-compose`` might have issues with HTTP timeout so you may
have to increase the ``COMPOSE_HTTP_TIMEOUT`` environment variable. ``300``
should be enough.
Updating
--------
To update the images and restart run (``WARNING: THIS WILL REMOVE ALL UNUSED
DOCKER IMAGES``)
::
./update.sh

14
loki-server.service Normal file
View File

@ -0,0 +1,14 @@
[Unit]
Description=Dockerised web server
Require=docker.service
After=docker.service
[Service]
WorkingDirectory=/root/Dockerfiles
ExecStart=/usr/bin/docker-compose up
ExecStop=/usr/bin/docker-compose down
Restart=always
TimeoutStopSec=10min
[Install]
WantedBy=multi-user.target

55
update.sh Executable file
View File

@ -0,0 +1,55 @@
#!/bin/bash
set -e
CYAN='\033[01;36m'
RED='\033[01;31m'
NC='\033[00m'
SCRIPT=$(readlink -f $0)
DIRNAME=$(dirname $SCRIPT)
SLEEP_TIME=600
# -----------------------------------------------------------------------------
# Pull updated images.
# -----------------------------------------------------------------------------
echo -e "${CYAN}[${SCRIPT}] Pull updated images${NC}"
make -C $DIRNAME pull-all
# -----------------------------------------------------------------------------
# Restart the containers.
# -----------------------------------------------------------------------------
echo -e "${CYAN}[${SCRIPT}] Restart the containers${NC}"
COMPOSE_HTTP_TIMEOUT=300 service loki-server restart
# -----------------------------------------------------------------------------
# Wait for containers to start.
# -----------------------------------------------------------------------------
echo -e "${CYAN}[${SCRIPT}] Wait ${SLEEP_TIME}s for containers to start${NC}"
sleep $SLEEP_TIME
# -----------------------------------------------------------------------------
# Remove unused images.
# -----------------------------------------------------------------------------
ACTIVE=$(systemctl status loki-server.service | grep "active (running)" -c)
if [[ $ACTIVE == 1 ]]
then
echo -e "${CYAN}[${SCRIPT}] Remove unused images${NC}"
yes | docker image prune -a
else
echo -e "${RED}[${SCRIPT}] Problem with service activation${NC}"
fi