Nightlight-Centralized is an enhanced version of NightLight that supports managing multiple Nightlines through a centralized server. It offers a feature-rich API for streamlined status management across various Nightline platforms.
The latest API documentation is generated automatically on each build and can be downloaded here: Latest API Docs Artifacts
- Clone the repository by downloading it as a ZIP file or use
git clone https://github.com/inflac/NightLight-Centralized.git - Enter the base folder
NightLight-Centralized - Rename
.env.exampleto.env - Configure the variables in
.env- Use a strong Admin API-Key! E.g. 2048-bit with Mixed letters & Numbers
If you would like to reset the status before or after 00:00, update the cronjob. E.g. to run the reset at 01:00, do the following, based on the Method to run the API.
Docker Compose / Docker:
Enter the file: NightLight-Centralized/Dockerfile and change the time in the cron job command. Change:
RUN echo "0 1 * * * /bin/bash /app/reset_status.sh >> /var/log/cron.log 2>&1" >> /etc/cron.d/reset-status-cron
to
RUN echo "0 2 * * * /bin/bash /app/reset_status.sh >> /var/log/cron.log 2>&1" >> /etc/cron.d/reset-status-cron
Manual:
run: echo "0 1 * * * /bin/bash /app/reset_status.sh >> /var/log/cron.log 2>&1" > /etc/cron.d/reset-status-cron
For every method, you should also configure a reverse proxy.
This method requires docker compose to be installed.
- Enter the base folder
NightLight-Centralized - In a terminal run
docker compose up
This method requires docker to be installed
- Enter the base folder
NightLight-Centralized - In a terminal run the following commands
docker build -t status-api . --no-cache- Make sure to insert the port you also entered in your .env file
docker run --env-file .env -p THE_PORT_YOU_ENTERED_IN_DOT_ENV:5000 status-api
This method requires python and pip to be installed.
Caution
Do not run the API like this on your sever! For manual server deployment see the section below
- Enter the base folder
NightLight - Install the required python modules by running:
pip install -r requirements.txt- You can also use a virtual environment to install the requirements in there.
- In a terminal run
python server.py
Because the API is based on a flask application, we want to use WSGI to run the app. The Web server served by flask is perfect for development, but not as robust and hardened than others which are made for production.
Make sure to insert the host you also entered in your .env file.
- Enter the base folder
NightLight-Centralized - Install the required python modules by running:
pip install -r requirements.txt- You can also use a virtual environment to install the requirements in there.
-
gunicorn --log-level info --timeout 120 -w 3 -b THE_HOST_YOU_ENTERED_IN_DOT_ENV:5000 server:app- To keep Gunicorn running in the background and let you close the terminal, run:
nohup gunicorn --workers 3 --bind THE_HOST_YOU_ENTERED_IN_DOT_ENV:8000 server:app > gunicorn.log 2>&1 &
- To keep Gunicorn running in the background and let you close the terminal, run:
- Now you can configure the reset cron job to reset the status to "default" every night. If you want to change the time, the reset is triggered, take a look at the "optional" section above. Replace PATH_TO_NIGHTLIGHT with the actual path to the NightLight-Centralized folder
- Replace the path
/app/.envin the filereset_status.shwith the actual absolut path to your .env file. E.g./opt/NightLight-Centralized/.env - Make the reset script executable:
chmod +x PATH_TO_NIGHTLIGHT/NightLight/reset_status.sh - Configure the cron job:
echo "0 1 * * * /bin/bash PATH_TO_NIGHTLIGHT/NightLight-Centralized/reset_status.sh >> /var/log/cron.log 2>&1" > /etc/cron.d/reset-status-cron - Set correct permissions for the cron job configuration:
chmod 0644 /etc/cron.d/reset-status-cron - Add the cronjob config to crontab:
crontab /etc/cron.d/reset-status-cron
- Replace the path