From c22e63e98106b1007094aa37731f57a9e0ca44c0 Mon Sep 17 00:00:00 2001 From: Ricardo Matsui Date: Sun, 19 Nov 2017 23:46:20 -0800 Subject: [PATCH] Restart unison if CPU usage high --- Dockerfile | 6 ++++-- monitrc | 4 ++++ supervisor.daemon.conf | 8 +++++++- 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 monitrc diff --git a/Dockerfile b/Dockerfile index 02d01e3..783ecdd 100644 --- a/Dockerfile +++ b/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} \ @@ -26,6 +26,7 @@ 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 \ @@ -33,7 +34,8 @@ RUN mkdir -p /docker-entrypoint.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 diff --git a/monitrc b/monitrc new file mode 100644 index 0000000..91214c1 --- /dev/null +++ b/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 diff --git a/supervisor.daemon.conf b/supervisor.daemon.conf index 150dc2a..c06906a 100644 --- a/supervisor.daemon.conf +++ b/supervisor.daemon.conf @@ -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 \ No newline at end of file +autorestart=true + +[program:monit] +command = monit -c /etc/monitrc -d 5 -v -I +redirect_stderr = true +autorestart = true +priority = 1000