Skip to content

Instantly share code, notes, and snippets.

@asheroto
Last active February 4, 2024 04:28
Show Gist options
  • Save asheroto/ff192448bb27b27e7c2d7cefdc24f308 to your computer and use it in GitHub Desktop.
Save asheroto/ff192448bb27b27e7c2d7cefdc24f308 to your computer and use it in GitHub Desktop.
Example of daemonized teler

Example of daemonized teler

This example turns teler into a service, then implements inotifywatch to monitor the configuration file for changes. This way teler will automatically load on start on boot, and when config.yaml changes the teler service will restart and load the changes.

Steps

  1. Install inotify-tools
apt-get -y install inotify-tools
  1. Move teler (binary) to /usr/local/bin

  2. Create folder /opt/teler

mkdir -p /opt/teler
  1. Put .sh and config.yaml files in that folder
  2. Make the files executable
chmod +x teler.sh
chmod +x teler-watcher.sh
  1. Put .service files in /etc/systemd/system/
  2. Reload systemd manager configuration
systemctl daemon-reload
  1. Enable services
systemctl enable teler.service
systemctl enable teler-watcher.service
  1. Adjust variable paths in config.yaml as needed
  2. Start services
systemctl start teler.service
systemctl start teler-watcher.service
# To write log format, see https://teler.app/configuration/log-format
log_format: |
$remote_addr $x $x $x [$time_local] "$request_method $request_uri $request_protocol" $status $body_bytes_sent "$http_referer" "$http_user_agent"
[Unit]
Description=Watch teler config for changes and restart teler service
After=network.target
[Service]
Type=simple
ExecStart=/opt/teler/teler-watcher.sh
[Install]
WantedBy=multi-user.target
#!/bin/sh
# Define vars
CONFIG_FILE="/opt/teler/config.yaml"
# Watch for configuration changes and restart teler
while inotifywait -e modify $CONFIG_FILE; do systemctl restart teler.service; done
[Unit]
Description=Teler Realtime HTTP Intrusion Detection
After=network.target
[Service]
Type=simple
ExecStart=/opt/teler/teler.sh
Restart=always
[Install]
WantedBy=multi-user.target
#!/bin/sh
# Define vars
CONFIG_FILE="/opt/teler/config.yaml"
LOG_FILE="/var/log/apache2/access.log"
# Start teler
tail -f $LOG_FILE | teler -c $CONFIG_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment