Last Watch AI - Ubuntu Installation and Upgrade Guide

The preferred method to install Last Watch on Ubuntu is directly from the source code. Installing from source makes it much easier to upgrade in the future by just pulling the latest code and rebuilding. Alternatively, you can install using the official releases.

For a full walkthrough on setting up Last Watch and integrating with an NVR system, see [coming soon...].

Dependencies

First, make sure you have Docker installed. Last Watch runs in Docker containers.

  1. Install Docker Engine - https://docs.docker.com/engine/install/ubuntu/
  2. Install Docker Compose - https://docs.docker.com/compose/install/

Installing From Source

I typically install everything in the home directory of a non-root user.

1. Clone the source code and go to the application root folder

git clone https://github.com/akmolina28/last-watch-ai.git && cd last-watch-ai

2. Set up your configuration by creating and editing the .env file in the application root folder.

cp .env.example .env
nano .env
  • Set WATCH_FOLDER to the path for your input files
  • Set other settings as desired

3. Build the application. This will install dependencies, set up the app keys, symlinks, database, and compile/optimize the code.

sudo cp src/.env.example src/.env &&
sudo docker-compose up -d mysql &&
sudo docker-compose run --rm composer install --optimize-autoloader --no-dev &&
sudo docker-compose run --rm artisan route:cache &&
sudo docker-compose run --rm artisan key:generate --force &&
sudo docker-compose run --rm artisan storage:link &&
sudo docker-compose run --rm artisan migrate --force &&
sudo docker-compose run --rm npm install --verbose &&
sudo docker-compose run --rm npm run prod --verbose

4. Bring up the containers (downloading the images can take a few minutes).

sudo docker-compose up -d --build site

Now, from your network you can access the web app using the IP of your server and the port number in the .env file.

Upgrading From Source

This assumes you installed from source.

1. Stop the containers during the upgrade

cd /path/to/last-watch-ai

sudo docker-compose down

2. Pull latest source code

git pull

3. Re-build application

sudo docker-compose run --rm composer install --optimize-autoloader --no-dev &&
sudo docker-compose run --rm artisan route:cache &&
sudo docker-compose run --rm artisan migrate --force &&
sudo docker-compose run --rm npm install --verbose &&
sudo docker-compose run --rm npm rebuild &&
sudo docker-compose run --rm npm run prod --verbose

The re-build will install any new dependencies and re-compile the code, and it will migrate your database to the latest version. Once the rebuild finishes, you may need to refresh your browser.

4. Restart the containers

sudo docker-compose up -d --build site

Install From Release Version

You also have the option to install a pre-compiled release. The releases are primarily meant to simplify things for Windows users, but they also work on Ubuntu. There is just one extra step at the end to re-create the symlinks, which don't work out-of-the-box on Linux.

I typically install everything in the home directory of a non-root user.

1. Download/unzip the latest release from Github using the command below, or by grabbing the desired release from the Releases page.

curl -s https://api.github.com/repos/akmolina28/last-watch-ai/releases/latest \
| grep "browser_download_url" \
| cut -d : -f 2,3 \
| tr -d \" \
| wget -qi -

unzip <zip_file>

2. Go to the application root folder, which is called `last-watch-ai` if you unzipped using the previous step.

cd last-watch-ai

3. Set up your configuration by editing the environment file in the application root folder.

nano .env
Example .env settings
  • Set WATCH_FOLDER to the path for your input files.
  • Set other settings as desired.

4. Set file permissions for the web server.

sudo chown -R www-data:www-data src

sudo find src -type f -exec chmod 644 {} \;

sudo find src -type d -exec chmod 755 {} \;

5. Bring up the containers (downloading the images can take a few minutes)

sudo docker-compose up -d --build site

6. Set up symlinks (the symlinks in the pre-compiled release do not work on Linux and have to be recreated)

sudo docker exec -it lw_php rm /var/www/app/public/storage

sudo docker exec -it lw_php php artisan storage:link

Now the web app should be up and running on port 8080 (or whichever port you configured).

Upgrading to Release Version

You can also upgrade an existing install using a pre-compiled release. These steps should work even if you originally installed from source.

1. Stop containers

sudo docker stop $(sudo docker ps -a -q)

sudo docker rm $(sudo docker ps -a -q)

2. Move previous install to a backup folder

mv last-watch-ai last-watch-ai_bak

3. Download/unzip the latest release from Github using the command below, or by grabbing the desired release from the Releases page.

curl -s https://api.github.com/repos/akmolina28/last-watch-ai/releases/latest \
| grep "browser_download_url" \
| cut -d : -f 2,3 \
| tr -d \" \
| wget -qi -

unzip <zip_file>

4. Copy over the environment file from your previous install

cp last-watch-ai_bak/.env last-watch-ai/.env

5. Migrate your app data (unless you want to start fresh)

   a. Copy over the database

rm -rf last-watch-ai/mysql

cp -R last-watch-ai_bak/mysql last-watch-ai/mysql

   b. Copy over your mask files

cp -R last-watch-ai_bak/src/storage/app/public/masks/. last-watch-ai/src/storage/app/public/masks/

   c. Go to the new application root and run the migrations to update your database

cd last-watch-ai
			
sudo docker-compose run --rm artisan migrate

6. Set file permissions for the web server

sudo chown -R www-data:www-data src

sudo find src -type f -exec chmod 644 {} \;

sudo find src -type d -exec chmod 755 {} \;

7. Bring up the containers

sudo docker-compose up -d --build site

8. Set up symlinks

sudo docker exec -it lw_php rm /var/www/app/public/storage

sudo docker exec -it lw_php php artisan storage:link

Now the updated app should be up and running. You may need to refresh your browser to empty your cache.

Uninstalling

To uninstall Last Watch, you first have to stop and remove the containers. Then you can simply delete the application folder to remove it.

1. Stop and remove the containers

cd /path/to/last-watch-ai

sudo docker-compose down

2. Delete the application

sudo rm -rf /path/to/last-watch-ai