From 78235f057beb022c6778806bf90a2f4fce74cf1e Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Wed, 2 Oct 2024 19:21:58 +0300 Subject: [PATCH] Adds install script and init scripts --- CHANGELOG.md | 5 ++- doc/install.sh | 27 +++++++++++++++ doc/jilo-agent.init | 76 ++++++++++++++++++++++++++++++++++++++++++ doc/jilo-agent.service | 14 ++++++++ 4 files changed, 121 insertions(+), 1 deletion(-) create mode 100755 doc/install.sh create mode 100644 doc/jilo-agent.init create mode 100644 doc/jilo-agent.service diff --git a/CHANGELOG.md b/CHANGELOG.md index e94d09a..10a30b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ All notable changes to this project will be documented in this file. ### Added - Removed PHP version - Added support for HTTPS +- Added SysV init script +- Added Systemd service file +- Added installation script --- @@ -31,5 +34,5 @@ All notable changes to this project will be documented in this file. - New version in folder "go", written in Go - Added endpoints for /nginx, /prosody, /jicofo, /jvb, /jibri - Added a config file and default values -- Initial vesion of a build script +- Initial version of a build script - Works with JWT tokens diff --git a/doc/install.sh b/doc/install.sh new file mode 100755 index 0000000..e6b2851 --- /dev/null +++ b/doc/install.sh @@ -0,0 +1,27 @@ +#!/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 +# +### + +# systemV +cp jilo-agent.init /etc/init.d/jilo-agent +chmod +x /etc/init.d/jilo-agent +update-rc.d jilo-agent defaults + +# systemd +cp jilo-agent.service /lib/systemd/system/jilo-agent.service +systemctl daemon-reload +systemctl enable jilo-agent.service +systemctl start jilo-agent.service + +# compatibility with sysV +sudo ln -s /lib/systemd/system/jilo-agent.service /etc/init.d/jilo-agent diff --git a/doc/jilo-agent.init b/doc/jilo-agent.init new file mode 100644 index 0000000..df6ef45 --- /dev/null +++ b/doc/jilo-agent.init @@ -0,0 +1,76 @@ +#!/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 diff --git a/doc/jilo-agent.service b/doc/jilo-agent.service new file mode 100644 index 0000000..17d7448 --- /dev/null +++ b/doc/jilo-agent.service @@ -0,0 +1,14 @@ +[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