Merge known and wordpress in one unit file

This commit is contained in:
pierreozoux 2015-01-12 10:18:35 +01:00
parent aff928c2a9
commit 322f75319b
8 changed files with 75 additions and 110 deletions

View file

@ -0,0 +1 @@
/uploads

View file

@ -0,0 +1 @@
/app/wp-content

View file

@ -5,13 +5,10 @@ Description=%p for %i etcd registration
Requires=etcd.service
[Service]
# Start
## Test whether service is accessible and then register useful information
ExecStart=/bin/bash -c ' \
sleep 30; \
while true; do \
app=`echo %i | cut -d"-" -f1`; \
ip=`docker inspect --format \'{{.NetworkSettings.IPAddress}}\' $app-%i`; \
ip=`docker inspect --format \'{{.NetworkSettings.IPAddress}}\' %i`; \
curl -f $ip; \
if [ $? -eq 0 ]; then \
etcdctl set /services/web/%i \'{"ip":"\'$ip\'", "port":"80"}\' --ttl 60; \
@ -21,7 +18,5 @@ ExecStart=/bin/bash -c ' \
sleep 50; \
done'
# Stop
ExecStop=-/bin/bash -euxc ' \
app=`echo %p | cut -d"-" -f1`; \
/usr/bin/etcdctl rm /services/web/%i
ExecStop=-/usr/bin/etcdctl rm /services/web/%i

View file

@ -1,45 +0,0 @@
[Unit]
Description=%p-%i
# Requirements
Requires=docker.service
Requires=init@%i.service
Requires=mysql@%i.service
Requires=discovery@%p-%i.service
Requires=backup@%i.timer
# Dependency ordering
After=docker.service
After=init@%i.service
After=mysql@%i.service
Before=discovery@%p-%i.service
Before=backup@%i.timer
# Dependency binding
BindsTo=mysql@%i.service
BindsTo=discovery@%p-%i.service
[Service]
Restart=always
ExecStartPre=-/usr/bin/docker kill %p-%i
ExecStartPre=-/usr/bin/docker rm %p-%i
ExecStartPre=/bin/bash -euxc ' \
application_folder=/data/domains/%i/%p; \
if [ ! -d $application_folder ]; then \
mkdir -p $application_folder; \
touch $application_folder/.htaccess; \
fi; \
cat /data/domains/%i/mysql/.env | sed s/MYSQL_PASS/DB_PASS/ > $application_folder/.env'
ExecStart=/usr/bin/docker run \
--name %p-%i \
--link mysql-%i:db \
-v /data/domains/%i/%p/wp-content:/app/wp-content \
-v /data/domains/%i/%p/.htaccess:/app/.htaccess \
--env-file /data/domains/%i/%p/.env \
pierreozoux/%p
ExecReload=/usr/bin/docker restart %p-%i
ExecStop=/usr/bin/docker stop %p-%i
[Install]
WantedBy=multi-user.target

50
unit-files/lamp@.service Normal file
View file

@ -0,0 +1,50 @@
[Unit]
Description=%p-%i
# Requirements
Requires=docker.service
Requires=init@%i.service
Requires=mysql@%i.service
Requires=discovery@%i.service
Requires=backup@%i.timer
# Dependency ordering
After=docker.service
After=init@%i.service
After=mysql@%i.service
Before=discovery@%i.service
Before=backup@%i.timer
[Service]
Restart=always
EnvironmentFile=/data/domains/%i/.env
ExecStartPre=-/usr/bin/docker kill %i
ExecStartPre=-/usr/bin/docker rm %i
ExecStartPre=/bin/bash -euxc ' \
application_folder=/data/domains/%i/${APPLICATION}; \
if [ ! -d $application_folder ]; then \
mkdir -p $application_folder; \
touch $application_folder/.htaccess; \
fi; \
cat /data/domains/%i/mysql/.env | sed s/MYSQL_PASS/DB_PASS/ > $application_folder/.env'
ExecStart=/usr/bin/docker run \
--name %i \
--link mysql-%i:db \
-v /data/domains/%i/${APPLICATION}/data:$(cat /data/indiehosters/dockerfiles/services/${APPLICATION}/VOLUME) \
-v /data/domains/%i/${APPLICATION}/.htaccess:/app/.htaccess \
--env-file /data/domains/%i/${APPLICATION}/.env \
pierreozoux/${APPLICATION}
ExecReload=/bin/bash -euxc ' \
/usr/bin/docker restart %i; \
systemctl restart discovery@%i.service; \
systemctl restart backup@%i.timer;'
ExecStop=/bin/bash -euxc ' \
systemctl stop init@%i.service; \
systemctl stop discovery@%i.service; \
systemctl stop backup@%i.timer; \
/usr/bin/docker stop %i;'
[Install]
WantedBy=multi-user.target

View file

@ -8,6 +8,9 @@ Requires=docker.service
After=docker.service
Before=backup@%i.timer
# Dependency binding
BindsTo=lamp@%i.service
[Service]
Restart=always
ExecStartPre=-/usr/bin/docker kill %p-%i

View file

@ -4,35 +4,40 @@ Description=%p-%i
# Requirements
Requires=docker.service
Requires=init@%i.service
Requires=discovery@%p-%i.service
Requires=discovery@%i.service
Requires=backup@%i.timer
# Dependency ordering
After=docker.service
After=init@%i.service
Before=discovery@%p-%i.service
Before=discovery@%i.service
Before=backup@%i.timer
# Dependency binding
BindsTo=discovery@%p-%i.service
[Service]
Restart=always
ExecStartPre=-/usr/bin/docker kill %p-%i
ExecStartPre=-/usr/bin/docker rm %p-%i
EnvironmentFile=/data/domains/%i/.env
ExecStartPre=-/usr/bin/docker kill %i
ExecStartPre=-/usr/bin/docker rm %i
ExecStartPre=/bin/bash -euxc ' \
application_folder=/data/domains/%i/static/www-content; \
application_folder=/data/domains/%i/%p/www-content; \
if [ ! -d $application_folder ]; then \
mkdir -p $application_folder; \
echo Hello %i > $application_folder/index.html; \
fi;'
fi'
ExecStart=/usr/bin/docker run \
--name %p-%i \
--name %i \
-v /data/domains/%i/%p/www-content:/app \
pierreozoux/nginx
ExecReload=/usr/bin/docker restart %p-%i
ExecStop=/usr/bin/docker stop %p-%i
ExecReload=/bin/bash -euxc ' \
/usr/bin/docker restart %i; \
systemctl restart discovery@%i.service; \
systemctl restart backup@%i.timer;'
ExecStop=/bin/bash -euxc ' \
systemctl stop init@%i.service; \
systemctl stop discovery@%i.service; \
systemctl stop backup@%i.timer; \
/usr/bin/docker stop %i;'
[Install]
WantedBy=multi-user.target

View file

@ -1,45 +0,0 @@
[Unit]
Description=%p-%i
# Requirements
Requires=docker.service
Requires=init@%i.service
Requires=mysql@%i.service
Requires=discovery@%p-%i.service
Requires=backup@%i.timer
# Dependency ordering
After=docker.service
After=init@%i.service
After=mysql@%i.service
Before=discovery@%p-%i.service
Before=backup@%i.timer
# Dependency binding
BindsTo=mysql@%i.service
BindsTo=discovery@%p-%i.service
[Service]
Restart=always
ExecStartPre=-/usr/bin/docker kill %p-%i
ExecStartPre=-/usr/bin/docker rm %p-%i
ExecStartPre=/bin/bash -euxc ' \
application_folder=/data/domains/%i/%p; \
if [ ! -d $application_folder ]; then \
mkdir -p $application_folder; \
touch $application_folder/.htaccess; \
fi; \
cat /data/domains/%i/mysql/.env | sed s/MYSQL_PASS/DB_PASS/ > $application_folder/.env'
ExecStart=/usr/bin/docker run \
--name %p-%i \
--link mysql-%i:db \
-v /data/domains/%i/%p/wp-content:/app/wp-content \
-v /data/domains/%i/%p/.htaccess:/app/.htaccess \
--env-file /data/domains/%i/%p/.env \
pierreozoux/%p
ExecReload=/usr/bin/docker restart %p-%i
ExecStop=/usr/bin/docker stop %p-%i
[Install]
WantedBy=multi-user.target