compose-website/unit-files/mysql@.service
2015-01-12 14:41:00 +01:00

45 lines
1.2 KiB
Desktop File

[Unit]
Description=%p-%i
# Requirements
Requires=docker.service
# Dependency ordering
After=docker.service
After=init.service
Before=backup@%i.timer
# Dependency binding
BindsTo=lamp@%i.service
[Service]
Restart=always
Type=notify
NotifyAccess=all
ExecStartPre=/usr/bin/docker run --rm -v /opt/bin:/opt/bin ibuildthecloud/systemd-docker
ExecStartPre=-/usr/bin/docker kill %p-%i
ExecStartPre=-/usr/bin/docker rm %p-%i
ExecStartPre=/bin/bash -euxc ' \
mysql_folder=/data/domains/%i/mysql; \
if [ ! -d /data/runtime/domains/%i/mysql ]; then \
mkdir -p /data/runtime/domains/%i/mysql/db_files; \
if [ ! -d $mysql_folder ]; then \
mkdir -p $mysql_folder; \
pass=`echo $RANDOM ${date} | md5sum | base64 | cut -c-10`; \
echo MYSQL_PASS=$pass > $mysql_folder/.env; \
else \
cp $mysql_folder/dump.sql /data/runtime/domains/%i/mysql/db_files/; \
fi; \
fi'
ExecStart=/opt/bin/systemd-docker run \
--name %p-%i \
-v /data/runtime/domains/%i/%p/db_files:/var/lib/mysql \
-e STARTUP_SQL="/var/lib/mysql/dump.sql" \
--env-file /data/domains/%i/%p/.env \
pierreozoux/mysql
ExecReload=/usr/bin/docker restart %p-%i
ExecStop=/usr/bin/docker stop %p-%i
[Install]
WantedBy=multi-user.target