Skip to content

Commit 18bc439

Browse files
committed
Fix initialization of dockerized services (closes #182)
1 parent 042a5ca commit 18bc439

File tree

4 files changed

+38
-83
lines changed

4 files changed

+38
-83
lines changed
Lines changed: 34 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,53 @@
11
#!/bin/sh
2+
23
### BEGIN INIT INFO
34
# Provides:
4-
# Required-Start: $remote_fs $syslog
5-
# Required-Stop: $remote_fs $syslog
6-
# Default-Start: 2 3 4 5
7-
# Default-Stop: 0 1 6
8-
# Short-Description: Start daemon at boot time
9-
# Description: Enable service provided by daemon.
5+
# Required-Start: $docker
6+
# Required-Stop: $docker
7+
# Default-Start: 2 3 4 5
8+
# Default-Stop: 0 1 6
9+
# Short-Description: Snowplow Mini Services
1010
### END INIT INFO
1111

12-
cmd="docker-compose -f /home/ubuntu/snowplow/docker-compose.yml up -d && sleep 20"
13-
user="ubuntu"
12+
set -e
13+
14+
YAMLFILE=/home/ubuntu/snowplow/docker-compose.yml
15+
OPTS="-f $YAMLFILE"
16+
UPOPTS="-d --no-recreate"
17+
18+
up_cmd="cd /home/ubuntu/snowplow && sudo docker-compose up $UPOPTS"
19+
stop_cmd="cd /home/ubuntu/snowplow && sudo docker-compose stop"
20+
down_cmd="cd /home/ubuntu/snowplow && sudo docker-compose down"
1421

1522
name="snowplow_mini"
1623
pid_file="/var/run/$name.pid"
1724
stdout_log="/var/log/$name.log"
1825
stderr_log="/var/log/$name.err"
1926

20-
get_pid() {
21-
cat "$pid_file"
22-
}
23-
24-
is_running() {
25-
[ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
26-
}
27-
2827
case "$1" in
2928
start)
30-
if is_running; then
31-
echo "Already started"
32-
else
33-
echo "Starting $name"
34-
if [ -z "$user" ]; then
35-
sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
36-
else
37-
sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
38-
fi
39-
echo $! > "$pid_file"
40-
if ! is_running; then
41-
echo "Unable to start, see $stdout_log and $stderr_log"
42-
exit 1
43-
fi
44-
fi
45-
;;
46-
stop)
47-
if is_running; then
48-
echo -n "Stopping $name.."
49-
kill `get_pid`
50-
for i in {1..10}
51-
do
52-
if ! is_running; then
53-
break
54-
fi
29+
echo -n "Starting Snowplow Mini..."
30+
$up_cmd >> "$stdout_log" 2>> "$stderr_log" &
31+
echo "done"
32+
;;
5533

56-
echo -n "."
57-
sleep 1
58-
done
59-
echo
34+
stop)
35+
echo -n "Stopping Snowplow Mini..."
36+
$stop_cmd >> "$stdout_log" 2>> "$stderr_log" &
37+
echo "done"
38+
;;
6039

61-
if is_running; then
62-
echo "Not stopped; may still be shutting down or shutdown may have failed"
63-
exit 1
64-
else
65-
echo "Stopped"
66-
if [ -f "$pid_file" ]; then
67-
rm "$pid_file"
68-
fi
69-
fi
70-
else
71-
echo "Not running"
72-
fi
73-
;;
7440
restart)
75-
$0 stop
76-
if is_running; then
77-
echo "Unable to stop, will not attempt to start"
78-
exit 1
79-
fi
80-
$0 start
81-
;;
82-
status)
83-
if is_running; then
84-
echo "Running"
85-
else
86-
echo "Stopped"
87-
exit 1
88-
fi
89-
;;
41+
echo -n "Restarting Snowplow Mini..."
42+
$down_cmd >> "$stdout_log" 2>> "$stderr_log" &
43+
$up_cmd >> "$stdout_log" 2>> "$stderr_log" &
44+
echo "done"
45+
;;
46+
9047
*)
91-
echo "Usage: $0 {start|stop|restart|status}"
92-
exit 1
93-
;;
48+
echo "Usage: /etc/init.d/snowplow_mini {start|stop|restart|status}"
49+
exit 1
50+
;;
9451
esac
9552

96-
exit 0
53+
exit 0

provisioning/roles/docker/files/docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ services:
3232
image: docker.elastic.co/kibana/kibana-oss:6.3.1
3333
container_name: kibana
3434
restart: always
35-
environment:
36-
- /Users/oguzhanunlu/work/snowplow-mini/provisioning/resources/elasticsearch/config/kibana.yml:/usr/share/kibana/config/kibana.yml
3735
ports:
3836
- "5601:5601"
3937
depends_on:

provisioning/roles/docker/tasks/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
become: yes
3333
shell: cd {{main_dir}} && docker-compose up -d && sleep 20
3434

35+
- name: Increase mmap count to recommended 262144 for Elasticsearch
36+
become: yes
37+
shell: echo "vm.max_map_count=262144" >> /etc/sysctl.conf && service procps restart
38+
3539
- name: Wait for Elasticsearch port 9200 to become open on the host, don't start checking for 10 seconds
3640
wait_for:
3741
port: 9200

provisioning/roles/sp_mini_7_setup_init/tasks/main.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
become: yes
3030
shell: systemctl start snowplow_mini_control_plane_api
3131

32-
- name: Increase mmap count to recommended 262144 for Elasticsearch
33-
become: yes
34-
shell: echo "vm.max_map_count=262144" >> /etc/sysctl.conf && service procps start
35-
3632
- cron:
3733
name: "Add cronjob to crop ES good index's docs older than a week"
3834
special_time: weekly

0 commit comments

Comments
 (0)