I have completed a robust script to persist OLS config overrides.
This script's working method and usage are different from the cPFence's one here, so you can go with the one that fits your needs.
-> github
Use this script at your own risk
Test in a development environment first.
How does it work?
- Uses both real-time file monitoring (inotify) and a fallback cron job to monitor 2 files, the OLS config, and a custom overrides txt file.
- Delays are 10 secs for the real-time monitoring, 3 mins for the cron job, and then a graceful OLS reload.
- Adds your current overrides in OLS config at both the start and the end to ensure it overrides first-wins and last-wins directives (I'm not really sure how the parser reads the config file, so I went this way; you can adjust it).
- Automatic backups to your OLS config before applying changes.
- log file.
- Retention for both logs and backups.
- Adds a systemd service to ensure the persistence works flawlessly after reboots.
Installation
Run:
sudo bash -c 'cd /root && rm -f ols-config-persistence-install.sh && curl -o ols-config-persistence-install.sh -fL https://cdn.jsdelivr.net/gh/abdeenoz/enhance-ols-config-persistence@main/ols-config-persistence-install.sh && bash ols-config-persistence-install.sh'
After completing installation, add your custom overrides:
nano /root/ols_custom_config.txt
Save, you are done!
Uninstallation
sudo bash /root/ols-config-persistence-install.sh uninstall
Notes:
- I've used a strict monitoring method to ensure my custom overrides are always applied since I mainly use it for security directives. You can adjust that and rely only on the cron job and set it to 5 mins.
- I haven't tested it on a production environment yet.
- Make sure to write your custom overrides correctly; it won't break the web server anyway.