-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathstart-container
182 lines (156 loc) · 4.78 KB
/
start-container
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env bash
# Make sure correct user is set
if [ "$SUPERVISOR_PHP_USER" != "root" ] && [ "$SUPERVISOR_PHP_USER" != "sail" ]; then
echo "You should set SUPERVISOR_PHP_USER to either 'sail' or 'root'."
exit 1
fi
# Make sure the laravel project is installed
if [ ! -f "/var/www/html/artisan" ]; then
echo "Laravel artisan not found! Make sure project is installed."
exit 1
fi
# Git pull the latest changes
# echo "Pulling latest changes..."
# git config --global --add safe.directory /var/www/html
# git pull
# Check for configuration directories and files
config_dir="/var/www/config"
env_file="${config_dir}/env"
db_dir="${config_dir}/database"
db_file="${db_dir}/database.sqlite"
db_file_jobs="${db_dir}/jobs.sqlite"
epg_dir="${config_dir}/epg"
playlist_dir="${config_dir}/playlist"
backup_dir="${config_dir}/m3u-editor-backups"
log_dir="${config_dir}/logs"
queue_log_file="${log_dir}/queue.log"
websockets_log_file="${log_dir}/websocket.log"
swoole_log_file="${log_dir}/swoole_http.log"
laravel_log_file="${log_dir}/laravel.log"
# Not using these log files any longer
reverb_log_file="${log_dir}/reverb.log"
horizon_log_file="${log_dir}/horizon.log"
# Create config directories
if [ ! -d "${config_dir}" ]; then
echo "Missing config directory, please make sure you've linked it in volumes to continue. It should link to '/var/www/config' in the container."
exit 0
fi
if [ ! -d "${db_dir}" ]; then
echo "Creating database directory..."
mkdir "${db_dir}"
fi
if [ ! -d "${log_dir}" ]; then
echo "Creating log directory..."
mkdir "${log_dir}"
fi
if [ ! -d "${epg_dir}" ]; then
echo "Creating EPG directory..."
mkdir "${epg_dir}"
fi
if [ ! -d "${playlist_dir}" ]; then
echo "Creating Playlist directory..."
mkdir "${playlist_dir}"
fi
if [ ! -d "${backup_dir}" ]; then
echo "Creating Backup directory..."
mkdir "${backup_dir}"
fi
# Create environment file
if [ ! -f "${env_file}" ]; then
echo "Missing environment file, creating now..."
touch "${env_file}"
cat /var/www/html/.env.example >> "${env_file}"
fi
# Create database file
if [ ! -f "${db_file}" ]; then
echo "Missing database file, creating now..."
touch "${db_file}"
fi
if [ ! -f "${db_file_jobs}" ]; then
echo "Missing jobs database file, creating now..."
touch "${db_file_jobs}"
fi
# Create log files
if [ ! -f "${queue_log_file}" ]; then
echo "Missing queue log file, creating now..."
touch "${queue_log_file}"
fi
if [ ! -f "${websockets_log_file}" ]; then
echo "Missing websockets log file, creating now..."
touch "${websockets_log_file}"
fi
if [ ! -f "${swoole_log_file}" ]; then
echo "Missing swoole log file, creating now..."
touch "${swoole_log_file}"
fi
# Clean up old log files
if [ -f "${reverb_log_file}" ]; then
rm -f "${reverb_log_file}"
fi
if [ -f "${horizon_log_file}" ]; then
rm -f "${horizon_log_file}"
fi
# Using daily log file, base file will not be created
if [ -f "${laravel_log_file}" ]; then
rm -f "${laravel_log_file}"
fi
# Link the environment file to the laravel project root
ln -sf "${env_file}" .env
# Link the database file to the laravel `database` directory
ln -sf "${db_file}" "database/database.sqlite"
ln -sf "${db_file_jobs}" "database/jobs.sqlite"
# Clean up recursion EPG directory from previous push
if [ -d "storage/epgs" ]; then
rm -rf storage/epgs
fi
if [ -d "/var/www/config/epgs" ]; then
rm -rf /var/www/config/epgs
fi
# Link the log files to the laravel `storage/logs` directory
rm -rf storage/logs
ln -sf "${log_dir}" storage/
# Link EPG and Playlist directories
if [ ! -d "storage/app/private/epg" ]; then
echo "Linking EPG directory..."
ln -sf "${epg_dir}" storage/app/private/epg
fi
if [ ! -d "storage/app/private/playlist" ]; then
echo "Linking Playlist directory..."
ln -sf "${playlist_dir}" storage/app/private/playlist
fi
# Link Backup directory
if [ ! -d "storage/app/private/m3u-editor-backups" ]; then
echo "Linking Backup directory..."
ln -sf "${backup_dir}" storage/app/private/m3u-editor-backups
fi
# Link storage
if [ ! -d "public/storage" ]; then
echo "Linking storage directory..."
php artisan storage:link
fi
# Set app key, if not previously set
php artisan app:generate-key
# Check for updates
php artisan app:update-check
# Optimizing configuration
echo "Optimizing configuration..."
php artisan optimize
# Run any pending migrations
echo "Running migrations..."
php artisan migrate --force
# Install npm dependencies
echo "Building assets..."
npm install && npm run build
if [ ! -d /.composer ]; then
mkdir /.composer
fi
chmod -R ugo+rw /.composer
if [ $# -gt 0 ]; then
if [ "$SUPERVISOR_PHP_USER" = "root" ]; then
exec "$@"
else
exec gosu $WWWUSER "$@"
fi
else
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
fi