Skip to content

Commit

Permalink
Restart unison if CPU usage high
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmatsui committed Nov 20, 2017
1 parent 2128af6 commit c22e63e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
@@ -1,7 +1,7 @@
FROM alpine:edge

ARG UNISON_VERSION=2.48.4
RUN apk add --no-cache build-base curl bash supervisor inotify-tools rsync ruby\
RUN apk add --no-cache build-base curl bash monit supervisor inotify-tools rsync ruby\
&& apk add --update-cache --repository http://dl-4.alpinelinux.org/alpine/edge/testing/ ocaml \
&& curl -L https://github.com/bcpierce00/unison/archive/$UNISON_VERSION.tar.gz | tar zxv -C /tmp \
&& cd /tmp/unison-${UNISON_VERSION} \
Expand All @@ -26,14 +26,16 @@ ENV TZ="Europe/Helsinki" \

COPY entrypoint.sh /entrypoint.sh
COPY precopy_appsync.sh /usr/local/bin/precopy_appsync
COPY monitrc /etc/monitrc

RUN mkdir -p /docker-entrypoint.d \
&& chmod +x /entrypoint.sh \
&& mkdir -p /etc/supervisor.conf.d \
&& mkdir /unison \
&& touch /tmp/unison.log \
&& chmod u=rw,g=rw,o=rw /tmp/unison.log \
&& chmod +x /usr/local/bin/precopy_appsync
&& chmod +x /usr/local/bin/precopy_appsync \
&& chmod u=rw,g=,o= /etc/monitrc

COPY supervisord.conf /etc/supervisord.conf
COPY supervisor.daemon.conf /etc/supervisor.conf.d/supervisor.daemon.conf
Expand Down
4 changes: 4 additions & 0 deletions monitrc
@@ -0,0 +1,4 @@
check process unison with pidfile /var/run/unison.pid
start program = "/bin/bash -c 'supervisorctl start unison && supervisorctl pid unison > /var/run/unison.pid'"
stop program = "/bin/bash -c 'supervisorctl stop unison && rm -rf /var/run/unison.pid'"
if cpu usage > 50% for 2 cycles then restart
8 changes: 7 additions & 1 deletion supervisor.daemon.conf
Expand Up @@ -4,4 +4,10 @@ user = %(ENV_OWNER)s
directory = %(ENV_APP_VOLUME)s
environment=HOME="%(ENV_OWNER_HOMEDIR)s",USER="%(ENV_OWNER)s"
redirect_stderr = true
autorestart=true
autorestart=true

[program:monit]
command = monit -c /etc/monitrc -d 5 -v -I
redirect_stderr = true
autorestart = true
priority = 1000

0 comments on commit c22e63e

Please sign in to comment.