-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
90 lines (80 loc) · 2.88 KB
/
run.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
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
#!/bin/bash
set -e
# Check and if needed install/renew certs
# Note that this script (certbot.sh) is also
# run weekly from /etc/periodic/weekly/croncert.sh
#
# WARNING:
# During the weekly check, if certs are renewed,
# the mosquitto process is restarted, causing
# a brief (few second) unavoidable service disruption
/certbot.sh
# This script assumes a standard persistent directory and file layout of:
# /mosquitto/
# conf/
# mosquitto.conf - the main configuration file
# passwd - the password file
# log/
#
# The presence and location of mosquitto.conf isn't optional.
# (We could allow user definition via environment var, but honestly why bother)
#
# The location of the log directory and passwd file can be
# mapped differently in mosquitto.conf. If so, this script will
# simply generate warnings, but continue to function.
# create log file if it doesn't exist
if [ -d "/mosquitto/log" ]; then
if [ ! -f "/mosquitto/log/mosquitto.log" ]; then
echo "Creating blank log file at /mosquitto/log"
touch /mosquitto/log/mosquitto.log
fi
else
echo "WARNING: missing /mosquitto/log directory"
echo "WARNING: ignore if your mosquitto.conf has a non-standard configuration"
fi
## create blank passwd if it doesn't exist
#if [ -d "/mosquitto/conf" ]; then
# if [ ! -f "/mosquitto/conf/passwd" ]; then
# echo "Creating blank passwd file at /mosquitto/conf/passwd"
# touch /mosquitto/conf/passwd
# fi
#else
# echo "WARNING: /mosquitto/conf should be mapped to persistent docker volume"
# echo "WARNING: ignore if your mosquitto.conf has a non-standard configuration"
#fi
# execute any pre-exec scripts, useful for customization of images
if [ -d "/scripts" ]; then
echo "Looking for user scripts to execute..."
for i in /scripts/*sh
do
if [ -e "${i}" ]; then
echo "Found user script - processing $i"
. "${i}"
fi
done
fi
chown mosquitto:mosquitto -R /var/lib/mosquitto
chown mosquitto:mosquitto -R /mosquitto
echo "Starting mosquitto process (daemon)..."
if [ "$1" = 'mosquitto' ]; then
exec /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
fi
exec "$@"
if [ -f "/mosquitto/conf/mosquitto.conf" ]; then
# Note that this method of starting mosquitto results in the process
# not receiving the SIGTERM signal from Docker on shutdown. This is
# necessary because mosquitto must be restarted automatically when
# certificates are renewed. In other words, we need the container to
# continue running beyond the life of the mosquitto process.
#
# A possible enhancement would be to include an "is alive" check
# for mosquitto to restart it if required or exit the container.
/usr/sbin/mosquitto -c /mosquitto/conf/mosquitto.conf&
echo "Going to sleep..."
# sleep infinity not available, so 9999d should be an acceptable substitute :-)
sleep 9999d
else
echo "ERROR: missing /mosquitto/conf/mosquitto.conf"
echo "ERROR: check your Docker volume mappings"
echo "Exiting..."
fi