adopted for Unifi 5.6., small fixes an enhancements

This commit is contained in:
Tommi2Day
2017-11-11 10:48:26 +01:00
parent a85f9f3eae
commit ddc5d707c7
6 changed files with 34 additions and 34 deletions

View File

@@ -1,10 +1,13 @@
FROM ubuntu:16.04
ENV DEBIAN_FRONTEND noninteractive
ARG REPO
RUN mkdir -p /usr/lib/unifi/data /backups /logs
# add unifi repo +keys
RUN echo "deb http://www.ubnt.com/downloads/unifi/debian unifi5 ubiquiti" >/etc/apt/sources.list.d/ubnt.list && \
RUN if [ -z "$REPO" ]; then REPO="stable"; fi && \
echo "deb http://www.ubnt.com/downloads/unifi/debian $REPO ubiquiti" >/etc/apt/sources.list.d/ubnt.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv C0A52C50
# update then install
@@ -15,6 +18,9 @@ RUN apt-get update -q -y && \
COPY ["unifi.sh","backup_unifi.sh","restore_unifi.sh", "/usr/lib/unifi/"]
RUN echo "10 02 * * * root /usr/lib/unifi/backup_unifi.sh >/logs/backup.log 2>&1" >/etc/cron.d/unifi_backup
# https://community.ubnt.com/t5/UniFi-Wireless-Beta/IMPORTANT-Debian-Ubuntu-users-MUST-READ-Updated-06-21/td-p/1968253/jump-to/first-unread-message
RUN echo "JSVC_EXTRA_OPTS=\"\$JSVC_EXTRA_OPTS -Xss1280k\"" >>/etc/default/unifi
#redirect logs and backup
RUN rm -f /usr/lib/unifi/logs && ln -s /logs /usr/lib/unifi/logs
RUN rm -f /usr/lib/unifi/backups && ln -s /backups /usr/lib/unifi/backups
@@ -22,7 +28,7 @@ RUN rm -f /usr/lib/unifi/backups && ln -s /backups /usr/lib/unifi/backups
#define interface
VOLUME /usr/lib/unifi/data
VOLUME /backups /logs
EXPOSE 8443 8880 8080
EXPOSE 3748/udp 8443 8880 8080 27117
#Runtime Env
ENV PATH "$PATH:/usr/lib/unifi"

View File

@@ -12,8 +12,8 @@ docker build -t tommi2day/unifi5 -f Dockerfile.unifi5 .
see also build_unifi.sh
### exposed Ports
```sh
# WebUI Inform mongodb
EXPOSE 8443 8080 8880
# WebUI Inform mongodb STUN
EXPOSE 8443 8080 8880 27117 3478/udp
```
### Volumes
```sh
@@ -27,7 +27,7 @@ None
```
### Run
Specify the environment variable and a volume
Specify the environment variable and a volume
for the datafiles when launching a new container, e.g:
```sh
@@ -35,24 +35,36 @@ docker volume create --name unifi_data
docker run -d \
-v unifi_data:/usr/lib/unifi/data \
-v /shared/unifi5/backups:/backups \
-v /shared/unifi5/logs":/logs \
-v /shared/unifi5/logs:/logs \
--hostname unifi5 \
--name unifi5 \
--restart=always \
-p 8080:8080 \
-p 8880:8880 \
-p 8443:8443 \
-p 3478:3478/udp \
-p 27117:27117 \
tommi2day/unifi5
```
see run_unifi.sh for an example
### Update
**always** backup your existing running settings first!
stop container, pull new image, restart
```
docker stop unifi5
docker rm unifi5
docker pull tommi2day/unifi5
docker run .... #see section Run
```
i prefer to start the first run after update interactive to keep track of the update process and restart normally after sucessfully migration. If something goes wrong (usually within mongodb) you may try to remove the data/db and data/site directory, do a brand new installation and restore the backup file. It should be automatic migrated to the new version
### Addons
All Addons are in /usr/lib/unifi
####internal start/stop script
unifi.sh is a start/stop/status script. the start script calls finally a tail -f server.log to keep the container running
####Backup script
There is a cronjob in place calling backup_unifi.sh , which will trigger a logrotate for mongodb and afterwards
stop the Controler to tar the unifi data tree to /backups and restart finally.
stop the Controler to tar the unifi data tree to /backups and restart finally.
You can start it manually as well.
```
docker exec -ti unifi5 bash
@@ -63,7 +75,7 @@ To return to the console prompt press CTRL-C
####Restore script
for restoring a backup call/exec restore_unifi.sh [filename]. filename will be expected in /backups. Without filename the last backup
unifi_data.$(date '+%Y%m%d').tar.gz is assumed as default.
unifi_data.$(date '+%Y%m%d').tar.gz is assumed as default.
Sample for the running container:
```
docker exec -ti unifi5 bash
@@ -71,13 +83,3 @@ docker exec -ti unifi5 bash
exit
```
This will stop and restart the unifi process. To return to the console prompt press CTRL-C
####Systemd service definition
unifi.service is a sample systemd start script for the already created container.
```
sudo cp unifi.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable unifi.service
sudo systemctl start unifi.service
```
see https://help.ubnt.com/hc/en-us/articles/220066768-UniFi-Debian-Ubuntu-APT-howto

View File

@@ -7,7 +7,7 @@ if [ -n "$MONGOPID" ]; then
kill -SIGUSR1 $MONGOPID
fi
#backup
cd /usr/lib/unifi1
cd /usr/lib/unifi
bash ./unifi.sh stop
sleep 5
tar -czf backups/unifi_data.$(date '+%Y%m%d').tar.gz data >/dev/null

View File

@@ -1,13 +1,15 @@
#!/bin/bash
VERSION=5.4.11
VERSION=5.6.22
#REPO=unifi-5.5
REPO=stable
VMNAME=${1:-unifi5}
if [ -r Dockerfile.$VMNAME ]; then
DOCKER_USER=${DOCKER_USER:-tommi2day}
#build the container
docker stop $VMNAME
docker rm $VMNAME
docker build -t $DOCKER_USER/$VMNAME:$VERSION -f Dockerfile.$VMNAME . |tee build.log
IMAGE=$(awk '/^Successfully/ {print $3}' build.log)
docker build --no-cache --build-arg REPO=$REPO -t $DOCKER_USER/$VMNAME:$VERSION -f Dockerfile.$VMNAME . |tee build.log
IMAGE=$(awk '/^Successfully built/ {print $3}' build.log)
if [ -n "$IMAGE" ]; then
docker tag $IMAGE $DOCKER_USER/$VMNAME:latest
fi

View File

@@ -64,6 +64,8 @@ $DOCKER run $RUN \
-p :8080:8080 \
-p 8880:8880 \
-p 8443:8443 \
-p 3478:3478/udp \
-p 27117:27117 \
$DOCKER_USER/$VMNAME $1 " >starter
if [ "$OSTYPE" = "msys" ]; then
mv starter starter.ps1

View File

@@ -1,12 +0,0 @@
[Unit]
Description=Unifi Controler container
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStart=/usr/bin/docker start -a unifi5
ExecStop=/usr/bin/docker stop -t 2 unifi5
[Install]
WantedBy=default.target