This repository has been archived by the owner on Jan 22, 2022. It is now read-only.
forked from paperwork/paperwork
-
Notifications
You must be signed in to change notification settings - Fork 3
/
launcher.sh
executable file
·48 lines (42 loc) · 1.71 KB
/
launcher.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
# Create a bunch of folders under the clean /var that php, nginx, and mysql expect to exist
mkdir -p /var/lib/mysql
mkdir -p /var/lib/nginx
mkdir -p /var/log
mkdir -p /var/log/mysql
mkdir -p /var/log/nginx
# Wipe /var/run, since pidfiles and socket files from previous launches should go away
# TODO someday: I'd prefer a tmpfs for these.
rm -rf /var/run
mkdir -p /var/run
mkdir -p /var/run/mysqld
# move storage folders which must be writable to /var
rm -rf /var/storage
mkdir -p /var/storage
mkdir -p /var/storage/attachments
mkdir -p /var/storage/cache
mkdir -p /var/storage/logs
mkdir -p /var/storage/meta
mkdir -p /var/storage/sessions
mkdir -p /var/storage/views
cp /opt/app/services.json /var/storage/meta/services.json
# Ensure mysql tables created
HOME=/etc/mysql /usr/bin/mysql_install_db --force
# Spawn mysqld, php
HOME=/etc/mysql /usr/sbin/mysqld &
/usr/sbin/php5-fpm --nodaemonize --fpm-config /etc/php5/fpm/php-fpm.conf &
# Wait until mysql and php have bound their sockets, indicating readiness
while [ ! -e /var/run/mysqld/mysqld.sock ] ; do
echo "waiting for mysql to be available at /var/run/mysqld/mysqld.sock"
sleep .2
done
while [ ! -e /var/run/php5-fpm.sock ] ; do
echo "waiting for php5-fpm to be available at /var/run/php5-fpm.sock"
sleep .2
done
# Ensure the paperwork database exists.
echo "CREATE DATABASE IF NOT EXISTS paperwork DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; GRANT ALL PRIVILEGES ON paperwork.* TO 'paperwork'@'localhost' IDENTIFIED BY 'paperwork' WITH GRANT OPTION; FLUSH PRIVILEGES;" | mysql --user root --socket /var/run/mysqld/mysqld.sock
# Run database migrations.
time php /opt/app/frontend/artisan migrate --force
# Start nginx.
/usr/sbin/nginx -g "daemon off;"