Libki / libki-server

Libki Server
Other
55 stars 28 forks source link

LIBKI_PROM_DIR var not being recognized #310

Closed rootchick closed 1 year ago

rootchick commented 1 year ago

Describe the bug

Recently you added the LIBKI_PROM_DIR variable to Libki.pm instead of using /dev/libki_metrics so that multiple instances of Libki could be run on the same server.

I've added it to the init script for each instance with a unique path, and it's still defaulting to /dev/libki_metrics. (Is that the correct place for it?)

Thanks!

To Reproduce Steps to reproduce the behavior:

  1. Set a unique path for LIBKI_PROM_DIR in the init script for your instance in /etc/init/instacename
  2. Restart libki (service instancename restart)
  3. check for existence of directory in /dev matching path of LIBKI_PROM_DIR

Expected behavior Existence of a libki metrics dir under the desired path instead of /dev/libki_metrics

Deployment architecture: Ubuntu server edition 22.04

kylemhall commented 1 year ago

@rootchick can you post your init script here?

rootchick commented 1 year ago

Sure, here it is for one of the instances. I've also tried /dev/libki_metrics/bensonlibki for the path as well.

Thanks!

#!/bin/bash

### BEGIN INIT INFO
# Provides:          bensonlibki
# Required-Start:    mysql
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start Libki at boot time
# Description:       Enable Libki
### END INIT INFO

# Source function library.
. /lib/lsb/init-functions

#HANDLER="gazelle" # gazelle or starman
HANDLER="starman"

#PORT="3000"
PORT="8081"

WORKERS="2"
REQUESTS="50000"

HOME_DIR="/home/bensonlibki"
MYAPP="libki"
MYAPP_PATH="$HOME_DIR/libki-server"
PIDFILE="$HOME_DIR/libki.pid"
STATUSFILE="$HOME_DIR/libki.status"
ERRORLOG="/var/log/libki/bensonlibki/libki_server.log"
LIBKI_PROM_DIR="/dev/bensonlibki_metrics"

START_SERVER="/usr/local/bin/start_server"
STARMAN="/usr/local/bin/starman"
PLACKUP="/usr/local/bin/plackup"
DAEMON="/usr/local/bin/start_server"

PSGI_FILE="$MYAPP_PATH/$MYAPP.psgi"

DAEMON_OPTS="--daemonize --port $PORT --pid-file $PIDFILE --status-file $STATUSFILE --log-file $ERRORLOG -- "

STARMAN_OPTS="$PLACKUP -I $MYAPP_PATH/lib -s Starman --workers $WORKERS --max-requests $REQUESTS -E production -a $PSGI_FILE"
GAZELLE_OPTS="$PLACKUP -I $MYAPP_PATH/lib -s Gazelle --workers $WORKERS --max-reqs-per-child $REQUESTS -E production -a $PSGI_FILE"

if [ $HANDLER == 'starman' ]
        then
                HANDLER_OPTS=$STARMAN_OPTS
elif [ $HANDLER == 'gazelle' ]
        then
                HANDLER_OPTS=$GAZELLE_OPTS
else
        echo -n "Unkown handler!"
        exit
fi

START_LIBKI="$DAEMON $DAEMON_OPTS $HANDLER_OPTS"

start() {
        echo -n "Starting Libki for bensonlibki... "

        eval $START_LIBKI
        RETVAL=$?

        echo -n "$START_LIBKI"

        echo [ $RETVAL = 0 ]
        return $RETVAL
}

restart() {
        echo -n "Restarting Libki... "
        eval $DAEMON --restart $DAEMON_OPTS
}

stop() {
        echo -n "Stopping Libki... "
        eval $DAEMON --stop $DAEMON_OPTS
}

kill() {
        echo -n "Stopping Libki... "
        killproc -p $PIDFILE $START_SERVER
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  restart)
        restart
         ;;
  stop)
        stop
        ;;
  *)
        echo $"Usage: bensonlibki {start|restart|stop|kill}"
        exit 1
esac

exit $RETVAL
kylemhall commented 1 year ago

Thanks! I believe if you change LIBKI_PROM_DIR="/dev/bensonlibki_metrics" to export LIBKI_PROM_DIR="/dev/bensonlibki_metrics" you should be good to go! Without the export command the variable can only be seen inside the init script itself and not by commands invoked by it.

rootchick commented 1 year ago

Confirmed! Thanks Kyle!!

kylemhall commented 1 year ago

😁 Glad to help!

rootchick commented 1 year ago

Just adding a note here in case anyone else is trying to do this that you also need to add the "export LIBKI_PROM_DIR" line to .bashrc for the libki user account as well, otherwise the cronjobs won't work!