Configuring Jexus Web Server Auto-Start on CentOS 7

Navigate to the system initialization directory to create the service script:

cd /etc/init.d/

Create a new file named jexus within this directory:

vim jexus

Input the following Bash script to manage the Jexus service lifecycle. This script handles starting, stopping, and restarting the server while ensuring root privileges are present.

#!/bin/bash
#
# jexus        Init script for the Jexus Web Server
#
# chkconfig: 2345 90 10
# description: Manages the Jexus web server service.

APP_NAME="jexus"
APP_HOME="/usr/jexus"
DAEMON="${APP_HOME}/jws"
PID_FILE="/var/run/${APP_NAME}.pid"
LOG_FILE="/var/log/${APP_NAME}.log"

# Ensure the user is root
if [ "$(id -u)" != "0" ]; then
    echo "Operation denied. This script requires root privileges." >&2
    exit 1
fi

start_service() {
    if [ -f "$PID_FILE" ]; then
        echo "The ${APP_NAME} service is already active."
        exit 1
    fi
    
    echo "Initializing ${APP_NAME}..."
    # Run the daemon in the background
    nohup $DAEMON start > "$LOG_FILE" 2>&1 &
    
    # Acquire the Process ID
    sleep 1
    PROCESS_ID=$(pgrep -f "jws")
    
    if [ -n "$PROCESS_ID" ]; then
        echo $PROCESS_ID > "$PID_FILE"
        echo "${APP_NAME} started successfully with PID ${PROCESS_ID}."
    else
        echo "Failure encountered while starting ${APP_NAME}."
        exit 1
    fi
}

stop_service() {
    if [ ! -f "$PID_FILE" ]; then
        echo "The ${APP_NAME} service is not currently running."
        exit 1
    fi
    
    echo "Terminating ${APP_NAME}..."
    PROCESS_ID=$(cat "$PID_FILE")
    kill "$PROCESS_ID" 2>/dev/null
    rm -f "$PID_FILE"
    echo "${APP_NAME} has been stopped."
}

case "$1" in
    start)
        start_service
        ;;
    stop)
        stop_service
        ;;
    restart)
        stop_service
        sleep 2
        start_service
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac

exit 0

Assign executable permissions to the script:

chmod +x jexus

Register the script with the system startup process:

chkconfig --add jexus

Confirm that the service is listed correctly in the startup configuration:

chkconfig --list

Tags: Linux centos Jexus Server Configuration Shell Scripting

Posted on Wed, 16 Sep 2026 16:33:12 +0000 by carnold