From 05e7b43a372dad7d56a1af176ac8c48aac3e860a Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Wed, 29 Jan 2025 12:08:33 +0200 Subject: [PATCH] Adds build and install scripts, init scripts --- doc/build.sh | 21 +++++++ doc/install.sh | 79 ++++++++++++++++++++++++ jilo-server.conf => doc/jilo-server.conf | 6 +- doc/jilo-server.init | 76 +++++++++++++++++++++++ doc/jilo-server.service | 14 +++++ 5 files changed, 195 insertions(+), 1 deletion(-) create mode 100755 doc/build.sh create mode 100755 doc/install.sh rename jilo-server.conf => doc/jilo-server.conf (56%) create mode 100644 doc/jilo-server.init create mode 100644 doc/jilo-server.service diff --git a/doc/build.sh b/doc/build.sh new file mode 100755 index 0000000..78a1900 --- /dev/null +++ b/doc/build.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +### +# Jilo Server building script +# +# Description: Building script for Jilo Server +# Author: Yasen Pramatarov +# License: GPLv2 +# Project URL: https://lindeas.com/jilo +# Year: 2025 +# Version: 0.1 +# +# requirements: +# - go +# - upx +### + +#CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o jilo-server ../main.go +CGO_ENABLED=1 go build -trimpath -ldflags="-s -w" -o jilo-server ../main.go +upx --best --lzma -o jilo-server-upx jilo-server +mv jilo-server-upx jilo-server diff --git a/doc/install.sh b/doc/install.sh new file mode 100755 index 0000000..01d7176 --- /dev/null +++ b/doc/install.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash + +### +# Jilo Server installation script +# +# Description: Installation script for Jilo Server +# Author: Yasen Pramatarov +# License: GPLv2 +# Project URL: https://lindeas.com/jilo +# Year: 2025 +# Version: 0.1 +# +### + + +# Paths to init and systemd service files +SYSVINIT_SCRIPT="./jilo-server.init" +SYSTEMD_SERVICE="./jilo-server.service" +UPSTART_CONF="./jilo-server.conf" + +# Function to install the SysVinit script +install_sysvinit() { + + echo "Detected SysVinit. Installing init script..." + cp "$SYSVINIT_SCRIPT" /etc/init.d/jilo-server + chmod +x /etc/init.d/jilo-server + + # for Debian/Ubuntu + if command -v update-rc.d >/dev/null 2>&1; then + update-rc.d jilo-server defaults + + # for RedHat/CentOS/Fedora + elif command -v chkconfig >/dev/null 2>&1; then + chkconfig --add jilo-server + 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-server.service + systemctl daemon-reload + systemctl enable jilo-server.service + + # compatibility with sysV + sudo ln -s /etc/systemd/system/jilo-server.service /etc/init.d/jilo-server + + # starting the server + systemctl start jilo-server.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-server.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 diff --git a/jilo-server.conf b/doc/jilo-server.conf similarity index 56% rename from jilo-server.conf rename to doc/jilo-server.conf index 1341c24..9896ab9 100644 --- a/jilo-server.conf +++ b/doc/jilo-server.conf @@ -1,5 +1,9 @@ +## +# configuration file for Jilo Server +## + # database location -database_path: "./jilo-server.db" +database_path: "/usr/local/etc/jilo-server.db" # health check health_check_enabled: true diff --git a/doc/jilo-server.init b/doc/jilo-server.init new file mode 100644 index 0000000..686ca49 --- /dev/null +++ b/doc/jilo-server.init @@ -0,0 +1,76 @@ +#!/bin/bash +# /etc/init.d/jilo-server +# Init script for Jilo Server + +### BEGIN INIT INFO +# Provides: jilo-server +# Required-Start: $network +# Required-Stop: $network +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start the Jilo Server service +# Description: This script starts and stops the Jilo Server service. +### END INIT INFO + +SERVER_PATH="/usr/local/bin/jilo-server" +CONFIG_FILE="/usr/local/etc/jilo-server.conf" +SERVER_NAME="Jilo Agent" +SERVER_PID="/var/run/jilo-server.pid" +LOG_FILE="/var/log/jilo-server.log" + +# Function to start the jilo server +start_server() { + if [ -f "$SERVER_PID" ]; then + echo "$SERVER_NAME is already running." + else + echo "Starting $SERVER_NAME..." + nohup $SERVER_PATH -c $CONFIG_FILE > $LOG_FILE 2>&1 & + echo $! > "$SERVER_PID" + echo "$SERVER_NAME started." + fi +} + +# Function to stop the jilo server +stop_server() { + if [ ! -f "$SERVER_PID" ]; then + echo "$SERVER_NAME is not running." + else + echo "Stopping $SERVER_NAME..." + kill -9 $(cat "$SERVER_PID") && rm -f "$SERVER_PID" + echo "$SERVER_NAME stopped." + fi +} + +# Function to restart the jilo server +restart_server() { + echo "Restarting $SERVER_NAME..." + stop_server + sleep 1 + start_server +} + +# Check for the first argument +case "$1" in + start) + start_server + ;; + stop) + stop_server + ;; + restart) + restart_server + ;; + status) + if [ -f "$SERVER_PID" ]; then + echo "$SERVER_NAME is running with PID $(cat $SERVER_PID)." + else + echo "$SERVER_NAME is not running." + fi + ;; + *) + echo "Usage: /etc/init.d/jilo-server {start|stop|restart|status}" + exit 1 + ;; +esac + +exit 0 diff --git a/doc/jilo-server.service b/doc/jilo-server.service new file mode 100644 index 0000000..2cca386 --- /dev/null +++ b/doc/jilo-server.service @@ -0,0 +1,14 @@ +[Unit] +Description=Jilo Server Service +After=network.target + +[Service] +ExecStart=/usr/local/bin/jilo-server -c /usr/local/etc/jilo-server.conf +PIDFile=/run/jilo-server.pid +Restart=on-failure +SyslogIdentifier=jilo-server +User=root +Group=root + +[Install] +WantedBy=multi-user.target