This is a tutorial for adding autostart functionality to a CAM-AI server (Raspi or PC). We assume that the server was installed following these instructions.
When you use your surveillance camera and the CAM-AI server for real-life applications, it is important to make sure that the system restarts completely after a reboot or a power outage. This can be achieved by making a Linux system service that starts the CAM-AI server. Here is how this works. Following this procedure, your CAM-AI server will run independently from your PC’s terminal.
Log into your server as user cam_ai. If the name of your machine is different from cam-ai-raspi (cam-ai-debian for example), replace this term with the real name or the IP address.
ssh cam_ai@cam-ai-raspi
First, you create a service definition file:
sudo nano /etc/systemd/system/c_server.service
Then you add the following content to that file:
[Unit]
Description=CAM-AI-Server
After=network-online.target mariadb.service
[Service]
User=cam_ai
KillMode=process
KillSignal=SIGTERM
WorkingDirectory=/home/cam_ai/bashes
ExecStart=/home/cam_ai/bashes/start-c_server-service.sh
[Install]
WantedBy=multi-user.target
You save the file and close Nano. After that, you create the directory and bash file:
mkdir ~/bashes
If the directory already exists, you will get an error message, never mind…
nano ~/bashes/start-c_server-service.sh
Then you add the following content to that file: One line is different for servers running on PC hardware. For Debian PCs replace the red line with:
source ~/miniconda3/etc/profile.d/conda.sh
#!/bin/bash
mkdir -p /home/cam_ai/cam-ai/data/logs
sleep 30s
exec >> /home/cam_ai/cam-ai/data/logs/c_server.log 2>> /home/cam_ai/cam-ai/data/logs/c_server.err
cd /home/cam_ai/cam-ai
source ~/miniforge3/etc/profile.d/conda.sh
conda activate tf
python cam-ai-server.py manage.py runserver 0.0.0.0:8000 --noreload
Save the file and leave Nano. Then you make the new file executable and enable the newly created service:
sudo chmod +x ~/bashes/start-c_server-service.sh
sudo systemctl enable c_serversudo reboot now
It’s done. Your server will now autostart your server automatically.