Compare commits
No commits in common. "main" and "v0.1" have entirely different histories.
|
@ -1 +1 @@
|
||||||
jilo-agent
|
go/jilo-agent
|
||||||
|
|
19
CHANGELOG.md
19
CHANGELOG.md
|
@ -4,23 +4,6 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Unreleased
|
|
||||||
|
|
||||||
#### Links
|
|
||||||
- upstream: https://code.lindeas.com/lindeas/jilo-agent/compare/v0.1...HEAD
|
|
||||||
- codeberg: https://codeberg.org/lindeas/jilo-agent/compare/v0.1...HEAD
|
|
||||||
- github: https://github.com/lindeas/jilo-agent/compare/v0.1...HEAD
|
|
||||||
- gitlab: https://gitlab.com/lindeas/jilo-agent/-/compare/v0.1...HEAD
|
|
||||||
|
|
||||||
### Added
|
|
||||||
- Removed PHP version
|
|
||||||
- Added support for HTTPS
|
|
||||||
- Added SysV init script
|
|
||||||
- Added Systemd service file
|
|
||||||
- Added installation script
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 0.1 - 2024-10-02
|
## 0.1 - 2024-10-02
|
||||||
|
|
||||||
#### Links
|
#### Links
|
||||||
|
@ -34,5 +17,5 @@ All notable changes to this project will be documented in this file.
|
||||||
- New version in folder "go", written in Go
|
- New version in folder "go", written in Go
|
||||||
- Added endpoints for /nginx, /prosody, /jicofo, /jvb, /jibri
|
- Added endpoints for /nginx, /prosody, /jicofo, /jvb, /jibri
|
||||||
- Added a config file and default values
|
- Added a config file and default values
|
||||||
- Initial version of a build script
|
- Initial vesion of a build script
|
||||||
- Works with JWT tokens
|
- Works with JWT tokens
|
||||||
|
|
|
@ -2,7 +2,11 @@
|
||||||
|
|
||||||
## overview
|
## overview
|
||||||
|
|
||||||
Jilo Agent - a remote agent for Jilo Web written in Go.
|
Jilo Agent - a remote agent for Jilo Web
|
||||||
|
|
||||||
|
Initial version is in PHP.
|
||||||
|
|
||||||
|
The current version is in "go" folder and is in Go.
|
||||||
|
|
||||||
## license
|
## license
|
||||||
|
|
||||||
|
@ -28,8 +32,6 @@ go build -o jilo-agent main.go
|
||||||
|
|
||||||
The config file is "jilo-agent.json", in the same folder as the "jilo-agent" binary.
|
The config file is "jilo-agent.json", in the same folder as the "jilo-agent" binary.
|
||||||
|
|
||||||
If you add the SSL config options, HTTPS will be used.
|
|
||||||
|
|
||||||
You can run the agent without a config file - then default vales are used.
|
You can run the agent without a config file - then default vales are used.
|
||||||
|
|
||||||
## usage
|
## usage
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$jicofoStatsURL = 'http://localhost:8888/stats';
|
||||||
|
$jvbStatsURL = 'http://localhost:8080/colibri/stats';
|
||||||
|
$nginxPort = '80';
|
||||||
|
|
||||||
|
?>
|
|
@ -1,79 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
###
|
|
||||||
# Jilo Agent installation script
|
|
||||||
#
|
|
||||||
# Description: Installation script for Jilo Agent
|
|
||||||
# Author: Yasen Pramatarov
|
|
||||||
# License: GPLv2
|
|
||||||
# Project URL: https://lindeas.com/jilo
|
|
||||||
# Year: 2024
|
|
||||||
# Version: 0.1
|
|
||||||
#
|
|
||||||
###
|
|
||||||
|
|
||||||
|
|
||||||
# Paths to init and systemd service files
|
|
||||||
SYSVINIT_SCRIPT="./jilo-agent.init"
|
|
||||||
SYSTEMD_SERVICE="./jilo-agent.service"
|
|
||||||
UPSTART_CONF="./jilo-agent.conf"
|
|
||||||
|
|
||||||
# Function to install the SysVinit script
|
|
||||||
install_sysvinit() {
|
|
||||||
|
|
||||||
echo "Detected SysVinit. Installing init script..."
|
|
||||||
cp "$SYSVINIT_SCRIPT" /etc/init.d/jilo-agent
|
|
||||||
chmod +x /etc/init.d/jilo-agent
|
|
||||||
|
|
||||||
# for Debian/Ubuntu
|
|
||||||
if command -v update-rc.d >/dev/null 2>&1; then
|
|
||||||
update-rc.d jilo-agent defaults
|
|
||||||
|
|
||||||
# for RedHat/CentOS/Fedora
|
|
||||||
elif command -v chkconfig >/dev/null 2>&1; then
|
|
||||||
chkconfig --add jilo-agent
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "SysVinit script installed."
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to install the systemd service file
|
|
||||||
install_systemd() {
|
|
||||||
|
|
||||||
echo "Detected systemd. Installing systemd service file..."
|
|
||||||
cp "$SYSTEMD_SERVICE" /etc/systemd/system/jilo-agent.service
|
|
||||||
systemctl daemon-reload
|
|
||||||
systemctl enable jilo-agent.service
|
|
||||||
|
|
||||||
# compatibility with sysV
|
|
||||||
sudo ln -s /etc/systemd/system/jilo-agent.service /etc/init.d/jilo-agent
|
|
||||||
|
|
||||||
# starting the agent
|
|
||||||
systemctl start jilo-agent.service
|
|
||||||
|
|
||||||
echo "Systemd service file installed."
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to install the Upstart configuration
|
|
||||||
install_upstart() {
|
|
||||||
|
|
||||||
echo "Detected Upstart. Installing Upstart configuration..."
|
|
||||||
cp "$UPSTART_CONF" /etc/init/jilo-agent.conf
|
|
||||||
initctl reload-configuration
|
|
||||||
|
|
||||||
echo "Upstart configuration installed."
|
|
||||||
}
|
|
||||||
|
|
||||||
# Detect the init system
|
|
||||||
if [[ `readlink /proc/1/exe` == */systemd ]]; then
|
|
||||||
install_systemd
|
|
||||||
|
|
||||||
elif [[ -f /sbin/init && `/sbin/init --version 2>/dev/null` =~ upstart ]]; then
|
|
||||||
install_upstart
|
|
||||||
|
|
||||||
else
|
|
||||||
install_sysvinit
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit 0
|
|
|
@ -1,76 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
# /etc/init.d/jilo-agent
|
|
||||||
# Init script for Jilo Agent
|
|
||||||
|
|
||||||
### BEGIN INIT INFO
|
|
||||||
# Provides: jilo-agent
|
|
||||||
# Required-Start: $network
|
|
||||||
# Required-Stop: $network
|
|
||||||
# Default-Start: 2 3 4 5
|
|
||||||
# Default-Stop: 0 1 6
|
|
||||||
# Short-Description: Start the Jilo Agent service
|
|
||||||
# Description: This script starts and stops the Jilo Agent service.
|
|
||||||
### END INIT INFO
|
|
||||||
|
|
||||||
AGENT_PATH="/usr/local/bin/jilo-agent"
|
|
||||||
CONFIG_FILE="/usr/local/etc/jilo-agent.conf"
|
|
||||||
AGENT_NAME="Jilo Agent"
|
|
||||||
AGENT_PID="/var/run/jilo-agent.pid"
|
|
||||||
LOG_FILE="/var/log/jilo-agent.log"
|
|
||||||
|
|
||||||
# Function to start the jilo agent
|
|
||||||
start_agent() {
|
|
||||||
if [ -f "$AGENT_PID" ]; then
|
|
||||||
echo "$AGENT_NAME is already running."
|
|
||||||
else
|
|
||||||
echo "Starting $AGENT_NAME..."
|
|
||||||
nohup $AGENT_PATH -c $CONFIG_FILE > $LOG_FILE 2>&1 &
|
|
||||||
echo $! > "$AGENT_PID"
|
|
||||||
echo "$AGENT_NAME started."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to stop the jilo agent
|
|
||||||
stop_agent() {
|
|
||||||
if [ ! -f "$AGENT_PID" ]; then
|
|
||||||
echo "$AGENT_NAME is not running."
|
|
||||||
else
|
|
||||||
echo "Stopping $AGENT_NAME..."
|
|
||||||
kill -9 $(cat "$AGENT_PID") && rm -f "$AGENT_PID"
|
|
||||||
echo "$AGENT_NAME stopped."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to restart the jilo agent
|
|
||||||
restart_agent() {
|
|
||||||
echo "Restarting $AGENT_NAME..."
|
|
||||||
stop_agent
|
|
||||||
sleep 1
|
|
||||||
start_agent
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check for the first argument
|
|
||||||
case "$1" in
|
|
||||||
start)
|
|
||||||
start_agent
|
|
||||||
;;
|
|
||||||
stop)
|
|
||||||
stop_agent
|
|
||||||
;;
|
|
||||||
restart)
|
|
||||||
restart_agent
|
|
||||||
;;
|
|
||||||
status)
|
|
||||||
if [ -f "$AGENT_PID" ]; then
|
|
||||||
echo "$AGENT_NAME is running with PID $(cat $AGENT_PID)."
|
|
||||||
else
|
|
||||||
echo "$AGENT_NAME is not running."
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Usage: /etc/init.d/agent {start|stop|restart|status}"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
exit 0
|
|
|
@ -1,14 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description=Jilo Agent Service
|
|
||||||
After=network.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
ExecStart=/usr/local/bin/jilo-agent -c /usr/local/etc/jilo-agent.conf
|
|
||||||
PIDFile=/run/jilo-agent.pid
|
|
||||||
Restart=always
|
|
||||||
SyslogIdentifier=jilo-agent
|
|
||||||
User=root
|
|
||||||
Group=root
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// get nginx data
|
||||||
|
function getNginxStatus() {
|
||||||
|
$status = trim(shell_exec('systemctl is-active nginx'));
|
||||||
|
return ($status === 'active') ? 'running' : 'not running';
|
||||||
|
}
|
||||||
|
function getNginxConnections() {
|
||||||
|
$connections = shell_exec("netstat -an | grep ':$nginxPort' | wc -l");
|
||||||
|
return intval(trim($connections));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// get prosody data
|
||||||
|
function getProsodyStatus() {
|
||||||
|
$status = trim(shell_exec('systemctl is-active prosody'));
|
||||||
|
return ($status === 'active') ? 'running' : 'not running';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// get jicofo data
|
||||||
|
function getJicofoStatus() {
|
||||||
|
$status = trim(shell_exec('systemctl is-active jicofo'));
|
||||||
|
return ($status === 'active') ? 'running' : 'not running';
|
||||||
|
}
|
||||||
|
function getJicofoStats($command) {
|
||||||
|
$data = shell_exec($command);
|
||||||
|
$decodedData = json_decode($data, true);
|
||||||
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
return ['error' => 'Failed to decode the JSON reply from the service.'];
|
||||||
|
}
|
||||||
|
return $decodedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// get JVB data
|
||||||
|
function getJVBStatus() {
|
||||||
|
$status = trim(shell_exec('systemctl is-active jitsi-videobridge2'));
|
||||||
|
return ($status === 'active') ? 'running' : 'not running';
|
||||||
|
}
|
||||||
|
function getJVBStats($command) {
|
||||||
|
$data = shell_exec($command);
|
||||||
|
$decodedData = json_decode($data, true);
|
||||||
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
return ['error' => 'Failed to decode the JSON reply from the service.'];
|
||||||
|
}
|
||||||
|
return $decodedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -15,6 +15,6 @@
|
||||||
# - upx
|
# - upx
|
||||||
###
|
###
|
||||||
|
|
||||||
CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o jilo-agent ../main.go
|
CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o jilo-agent main.go
|
||||||
upx --best --lzma -o jilo-agent-upx jilo-agent
|
upx --best --lzma -o jilo-agent-upx jilo-agent
|
||||||
mv jilo-agent-upx jilo-agent
|
mv jilo-agent-upx jilo-agent
|
|
@ -8,12 +8,6 @@ agent_port: 8081
|
||||||
# secret for checking JWT (same as in Jilo Web agent config)
|
# secret for checking JWT (same as in Jilo Web agent config)
|
||||||
secret_key: "mysecretkey"
|
secret_key: "mysecretkey"
|
||||||
|
|
||||||
# SSL certificate file (relative or full path)
|
|
||||||
ssl_cert: "jilo-agent.crt"
|
|
||||||
|
|
||||||
# SSL key file (relative or full path)
|
|
||||||
ssl_key: "jilo-agent.key"
|
|
||||||
|
|
||||||
# the port we check for nginx
|
# the port we check for nginx
|
||||||
nginx_port: 80
|
nginx_port: 80
|
||||||
|
|
|
@ -28,8 +28,6 @@ import (
|
||||||
// Config holds the structure of the configuration file
|
// Config holds the structure of the configuration file
|
||||||
type Config struct {
|
type Config struct {
|
||||||
AgentPort int `yaml:"agent_port"`
|
AgentPort int `yaml:"agent_port"`
|
||||||
SSLcert string `yaml:"ssl_cert"`
|
|
||||||
SSLkey string `yaml:"ssl_key"`
|
|
||||||
SecretKey string `yaml:"secret_key"`
|
SecretKey string `yaml:"secret_key"`
|
||||||
NginxPort int `yaml:"nginx_port"`
|
NginxPort int `yaml:"nginx_port"`
|
||||||
ProsodyPort int `yaml:"prosody_port"`
|
ProsodyPort int `yaml:"prosody_port"`
|
||||||
|
@ -319,8 +317,7 @@ func main() {
|
||||||
// start the http server
|
// start the http server
|
||||||
agentPortStr := fmt.Sprintf(":%d", config.AgentPort)
|
agentPortStr := fmt.Sprintf(":%d", config.AgentPort)
|
||||||
fmt.Printf("Starting Jilo agent on port %d.\n", config.AgentPort)
|
fmt.Printf("Starting Jilo agent on port %d.\n", config.AgentPort)
|
||||||
// if err := http.ListenAndServe(agentPortStr, corsHandler); err != nil {
|
if err := http.ListenAndServe(agentPortStr, corsHandler); err != nil {
|
||||||
if err := http.ListenAndServeTLS(agentPortStr, config.SSLcert, config.SSLkey, corsHandler); err != nil {
|
|
||||||
log.Fatalf("Could not start the agent: %v\n", err)
|
log.Fatalf("Could not start the agent: %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require 'config.php';
|
||||||
|
include 'functions.php';
|
||||||
|
|
||||||
|
$scriptname = basename($_SERVER['SCRIPT_NAME']);
|
||||||
|
$request = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||||
|
|
||||||
|
// the response is in JSON
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
// nginx status
|
||||||
|
if ($request === '/nginx' || $request === "/$scriptname/nginx") {
|
||||||
|
$data = [
|
||||||
|
'nginx_status' => getNginxStatus(),
|
||||||
|
'nginx_connections' => getNginxConnections(),
|
||||||
|
];
|
||||||
|
echo json_encode($data, JSON_PRETTY_PRINT) . "\n";
|
||||||
|
|
||||||
|
// prosody status
|
||||||
|
} elseif ($request === '/prosody' || $request === "/$scriptname/prosody") {
|
||||||
|
$data = [
|
||||||
|
'prosody_status' => getProsodyStatus(),
|
||||||
|
];
|
||||||
|
echo json_encode($data, JSON_PRETTY_PRINT) . "\n";
|
||||||
|
|
||||||
|
// jicofo status
|
||||||
|
} elseif ($request === '/jicofo' || $request === "/$scriptname/jicofo") {
|
||||||
|
$jicofoStatsCommand = "curl -s $jicofoStatsURL";
|
||||||
|
$jicofoStatsData = getJicofoStats($jicofoStatsCommand);
|
||||||
|
$data = [
|
||||||
|
'jicofo_status' => getJicofoStatus(),
|
||||||
|
'jicofo_API_stats' => $jicofoStatsData,
|
||||||
|
];
|
||||||
|
echo json_encode($data, JSON_PRETTY_PRINT) . "\n";
|
||||||
|
|
||||||
|
// jvb status
|
||||||
|
} elseif ($request === '/jvb' || $request === "/$scriptname/jvb") {
|
||||||
|
$jvbStatsCommand = "curl -s $jvbStatsURL";
|
||||||
|
$jvbStatsData = getJVBStats($jvbStatsCommand);
|
||||||
|
$data = [
|
||||||
|
'jvb_status' => getJVBStatus(),
|
||||||
|
'jvb_API_stats' => $jvbStatsData,
|
||||||
|
];
|
||||||
|
echo json_encode($data, JSON_PRETTY_PRINT) . "\n";
|
||||||
|
|
||||||
|
// default response - error
|
||||||
|
} else {
|
||||||
|
echo json_encode(['error' => 'Endpoint not found']) . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in New Issue