snapshot of https://github.com/centrifugal/centrifugo.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
test / Lint (push) Failing after 3s
test / Test with Go 1.26.8 (push) Failing after 2s

This commit is contained in:
upstream-mirror
2026-09-16 01:17:21 +05:00
commit b352a9a30d
472 changed files with 108375 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
[Unit]
Description=Centrifugo real-time messaging server
Documentation=https://github.com/centrifugal/centrifugo
# start once the network and logging subsystems available
After=network.target
[Service]
User=centrifugo
Group=centrifugo
LimitNOFILE=65536
Environment="CONFIG=/etc/centrifugo/config.json"
EnvironmentFile=/etc/default/centrifugo
ExecStartPre=/usr/bin/centrifugo checkconfig -c $CONFIG
ExecStart=/usr/bin/centrifugo -c $CONFIG $CENTRIFUGO_OPTS
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -SIGTERM $MAINPID
TimeoutStopSec=10
KillMode=control-group
RestartSec=1
Restart=on-failure
[Install]
WantedBy=multi-user.target
Alias=centrifugo.service

View File

@@ -0,0 +1,30 @@
# Upstart configuration file for centrifugo
description "Centrifugo real-time messaging server"
author "Alexandr Emelin <frvzmb@gmail.com>"
start on runlevel [2345]
# Always restart the runner if it dies / exits
respawn
# Log to /var/log/upstart/
console log
# Run the process as centrifugo:centrifugo
setuid centrifugo
setgid centrifugo
limit nofile 65536 65536
script
CONFIG=/etc/centrifugo/config.json
CENTRIFUGO_OPTS=
if [ -f /etc/default/centrifugo ]; then
. /etc/default/centrifugo
fi
exec /usr/bin/centrifugo -c $CONFIG $CENTRIFUGO_OPTS
end script

159
misc/packaging/initd.el6.sh Normal file
View File

@@ -0,0 +1,159 @@
#!/bin/bash
#
# /etc/init.d/centrifugo
#
# Startup script for centrifugo
#
# chkconfig: 2345 20 80
# description: Starts and stops centrifugo
# Source function library.
if [ -f /etc/init.d/functions ] ; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
else
exit 1
fi
# Daemon options
CENTRIFUGO_OPTS=
# Process name
NAME=centrifugo
USER=centrifugo
GROUP=centrifugo
# Daemon name, where is the actual executable
# If the daemon is not there, then exit.
DAEMON=/usr/bin/centrifugo
# Configuration file
CONFIG=/etc/centrifugo/config.json
# Max open files
OPEN_FILE_LIMIT=65536
# Logging
if [ -z "$STDOUT" ]; then
STDOUT=/var/log/centrifugo/centrifugo.log
fi
if [ ! -f "$STDOUT" ]; then
mkdir -p $(dirname $STDOUT)
fi
if [ -z "$STDERR" ]; then
STDERR=/var/log/centrifugo/centrifugo.log
fi
if [ ! -f "$STDERR" ]; then
mkdir -p $(dirname $STDERR)
fi
lockfile="/var/lock/subsys/centrifugo"
pidfile="/var/run/centrifugo.pid"
[ -e /etc/sysconfig/centrifugo ] && . /etc/sysconfig/centrifugo
if ! [ -x $DAEMON ]; then
echo "$DAEMON binary not found."
exit 5
fi
start() {
if ! [ -f $CONFIG ]; then
echo "configuration file not found $CONFIG"
exit 6
fi
# Bump the file limits, before launching the daemon.
ulimit -n $OPEN_FILE_LIMIT
if [ $? -ne 0 ]; then
exit 1
fi
configtest || return $?
echo -n $"Starting $NAME: "
daemon --pidfile=$pidfile --user centrifugo --check=$DAEMON "nohup $DAEMON -c $CONFIG $CENTRIFUGO_OPTS >>$STDOUT 2>&1 &"
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
pgrep -f "$DAEMON -c $CONFIG" > $pidfile
return $retval
}
stop() {
echo -n $"Stopping $NAME: "
killproc -p $pidfile $NAME -TERM
retval=$?
if [ $retval -eq 0 ]; then
if [ "$CONSOLETYPE" != "serial" ]; then
echo -en "\\033[16G"
fi
while rh_status_q
do
sleep 1
echo -n $"."
done
rm -f $lockfile
fi
echo
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $NAME: "
killproc $DAEMON -HUP
sleep 1
RETVAL=$?
echo
}
configtest() {
$DAEMON checkconfig -c $CONFIG
}
rh_status() {
status -p $pidfile $NAME
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
status|status_q)
rh_$1
;;
condrestart)
rh_status_q && restart || exit 0
;;
*)
echo $"Usage: $0 {start|stop|reload|status|restart|configtest|condrestart}"
exit 2
esac

262
misc/packaging/initd.sh Normal file
View File

@@ -0,0 +1,262 @@
#! /usr/bin/env bash
### BEGIN INIT INFO
# Provides: centrifugo
# Required-Start: $all
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start centrifugo at boot time
### END INIT INFO
# Command-line options that can be set in /etc/default/centrifugo. These will override
# any config file values. Example: CENTRIFUGO_OPTS="--engine=redis"
DEFAULT=/etc/default/centrifugo
# Daemon options
CENTRIFUGO_OPTS=
# Process name
readonly NAME=centrifugo
# Absolute path to the printf executable.
readonly PRINT=/usr/bin/printf
# Absolute path to the which executable.
readonly WHICH=/usr/bin/which
# User and group
USER=centrifugo
GROUP=centrifugo
# Daemon name, where is the actual executable
# If the daemon is not there, then exit.
DAEMON=/usr/bin/centrifugo
[ -x $DAEMON ] || exit 5
# Configuration file
CONFIG=/etc/centrifugo/config.json
# PID file for the daemon
PIDFILE=/var/run/centrifugo/centrifugo.pid
PIDDIR=`dirname $PIDFILE`
if [ ! -d "$PIDDIR" ]; then
mkdir -p $PIDDIR
chown $USER:$GROUP $PIDDIR
fi
# Max open files
OPEN_FILE_LIMIT=65536
if [ -r /lib/lsb/init-functions ]; then
source /lib/lsb/init-functions
fi
readonly EC_INVALID_ARGUMENT=2
readonly EC_SUPER_USER_ONLY=4
readonly EC_DAEMON_NOT_FOUND=5
readonly EC_RELOADING_FAILED=95
readonly EC_RESTART_STOP_FAILED=96
readonly EC_RESTART_START_FAILED=97
readonly EC_START_FAILED=98
readonly EC_STOP_FAILED=99
# Logging
if [ -z "$STDOUT" ]; then
STDOUT=/var/log/centrifugo/centrifugo.log
fi
if [ ! -f "$STDOUT" ]; then
mkdir -p $(dirname $STDOUT)
fi
if [ -z "$STDERR" ]; then
STDERR=/var/log/centrifugo/centrifugo.log
fi
if [ ! -f "$STDERR" ]; then
mkdir -p $(dirname $STDERR)
fi
# Overwrite init script variables with /etc/default/centrifugo values
if [ -r $DEFAULT ]; then
source $DEFAULT
fi
# Exit the script with an error code.
die() {
log_end_msg $1
exit $1
}
# End the script.
end() {
log_end_msg 0
exit 0
}
# Display failure message.
fail() {
log_failure_msg "${NAME}" "$1"
}
# Display success message.
ok() {
log_success_msg "${NAME}" "$1"
}
# Reloads the service.
reload_service()
{
start-stop-daemon --stop --signal HUP --pidfile $PIDFILE
if [ $? -ne 0 ]; then
fail "failed to reload"
else
ok "reloaded"
fi
}
# Starts the service.
start_service()
{
# Check if config file exist
if [ ! -r $CONFIG ]; then
fail "config file doesn't exist (or you don't have permission to view)"
return 1
fi
# Bump the file limits, before launching the daemon. These will carry over to
# launched processes.
ulimit -n $OPEN_FILE_LIMIT
if [ $? -ne 0 ]; then
fail "set open file limit to $OPEN_FILE_LIMIT"
return 1
fi
start-stop-daemon --start --chuid $GROUP:$USER --quiet --background --make-pidfile --pidfile $PIDFILE --startas /bin/bash -- -c "exec $DAEMON -c $CONFIG $CENTRIFUGO_OPTS >> $STDOUT 2>&1"
if [ $? -ne 0 ]; then
fail "failed to start"
else
ok "started"
fi
}
# Stops the service.
stop_service() {
start-stop-daemon --stop --signal QUIT --retry=TERM/30/KILL/5 --pidfile $PIDFILE
if [ $? -ne 0 ]; then
fail "failed to stop"
else
ok "stopped"
fi
}
# Load the LSB log_* functions.
INCLUDE=/lib/lsb/init-functions
if [ -r "${INCLUDE}" ]
then
. "${INCLUDE}"
else
"${PRINT}" '%s: unable to load LSB functions, cannot start service.\n' "${NAME}" 1>&2
exit ${EC_DAEMON_NOT_FOUND}
fi
# Make sure only one argument was passed to the script.
if [ $# -ne 1 ]
then
if [ $# -lt 1 -o "$1" = '' ]
then fail 'action not specified.'
else fail 'too many arguments.'
fi
usage 1>&2
die ${EC_INVALID_ARGUMENT}
fi
readonly ACTION="$1"
# Check if daemon is a recognized program and get absolute path.
readonly DAEMON=$("${WHICH}" "${NAME}")
if [ ! -x "${DAEMON}" ]
then
if [ "${ACTION}" = 'stop' ]
then
fail 'executable not found: stop request ignored'
end
else
fail "executable not found: cannot ${ACTION} service"
die ${EC_DAEMON_NOT_FOUND}
fi
fi
# Check start-stop-daemon
readonly SSD=$("${WHICH}" "start-stop-daemon")
if [ ! -x "${SSD}" ]
then
fail "start-stop-daemon required"
end
fi
# Determine the service's status.
start-stop-daemon --status --pidfile "${PIDFILE}" 2>/dev/null 1>/dev/null
readonly STATUS=$?
configtest() {
$DAEMON checkconfig -c $CONFIG
}
status_q() {
status_of_proc "${DAEMON}" "${NAME}" >/dev/null 2>&1
}
case $1 in
start)
if [ ${STATUS} -eq 0 ]
then
ok 'already started.'
else
start_service || die ${EC_START_FAILED}
fi
;;
stop)
if [ ${STATUS} -eq 0 ]
then
stop_service || die ${EC_STOP_FAILED}
else
ok 'already stopped.'
fi
;;
restart)
if [ ${STATUS} -eq 0 ]
then
stop_service || die ${EC_RESTART_STOP_FAILED}
sleep 1
fi
start_service || die ${EC_RESTART_START_FAILED}
;;
configtest)
$1
;;
status)
status_of_proc "${DAEMON}" "${NAME}" || exit $?
;;
reload)
if [ ${STATUS} -eq 0 ]
then
configtest
if [[ $? -ne 0 ]]; then
die ${EC_RELOADING_FAILED}
fi
reload_service || die ${EC_RELOADING_FAILED}
else
fail 'service not running, nothing to be done.'
fi
;;
version)
$DAEMON version
;;
condrestart)
status_q && $0 restart || exit 0
;;
*)
# For invalid arguments, print the usage message.
echo "Usage: $0 {start|stop|restart|condrestart|reload|configtest|status|version}"
exit 2
;;
esac

8
misc/packaging/logrotate Normal file
View File

@@ -0,0 +1,8 @@
/var/log/centrifugo/centrifugo.log {
daily
rotate 7
missingok
dateext
copytruncate
compress
}

View File

@@ -0,0 +1,100 @@
#!/bin/bash
BIN_DIR=/usr/bin
DATA_DIR=/var/lib/centrifugo
LOG_DIR=/var/log/centrifugo
SCRIPT_DIR=/usr/lib/centrifugo/scripts
function install_init {
cp -f $SCRIPT_DIR/initd.sh /etc/init.d/centrifugo
chmod +x /etc/init.d/centrifugo
}
function install_initel6 {
cp -f $SCRIPT_DIR/initd.el6.sh /etc/init.d/centrifugo
chmod +x /etc/init.d/centrifugo
}
function install_systemd {
cp -f $SCRIPT_DIR/centrifugo.service /lib/systemd/system/centrifugo.service
systemctl is-enabled centrifugo &>/dev/null
if [[ $? -ne 0 ]]; then
systemctl enable centrifugo &>/dev/null
fi
systemctl daemon-reload
}
function install_upstart {
cp -f $SCRIPT_DIR/centrifugo.upstart /etc/init/centrifugo.conf
initctl reload-configuration
}
function install_update_rcd {
update-rc.d centrifugo defaults
}
function install_chkconfig {
chkconfig --add centrifugo
}
id centrifugo &>/dev/null
if [[ $? -ne 0 ]]; then
useradd --system -U -M centrifugo -s /bin/false -d $DATA_DIR
fi
if [ ! -d $DATA_DIR ]; then
mkdir -p $DATA_DIR
fi
if [ ! -d $LOG_DIR ]; then
mkdir -p $LOG_DIR
fi
chown -R -L centrifugo:centrifugo $DATA_DIR
chown -R -L centrifugo:centrifugo $LOG_DIR
# Add defaults file, if it doesn't exist
if [[ ! -f /etc/default/centrifugo ]]; then
touch /etc/default/centrifugo
fi
# Generate config with unique secret key, if it doesn't exist
if [[ ! -f /etc/centrifugo/config.json ]]; then
/usr/bin/centrifugo genconfig -c /etc/centrifugo/config.json
fi
# Distribution-specific logic
if [[ -f /etc/redhat-release ]]; then
# RHEL-variant logic
which systemctl &>/dev/null
if [[ $? -eq 0 ]]; then
install_systemd
else
# Assuming sysv
install_initel6
install_chkconfig
fi
elif [[ -f /etc/debian_version ]]; then
# Debian/Ubuntu logic
which systemctl &>/dev/null
if [[ $? -eq 0 ]]; then
install_systemd
else
/sbin/init --version >/dev/null 2>/dev/null
if [[ $? -eq 0 && `/sbin/init --version` =~ upstart ]]; then
# Assuming upstart
install_upstart
else
# Assuming sysv
install_init
install_update_rcd
fi
fi
elif [[ -f /etc/os-release ]]; then
source /etc/os-release
if [[ $ID = "amzn" ]]; then
# Amazon Linux logic
install_init
install_chkconfig
fi
fi

View File

@@ -0,0 +1,76 @@
#!/bin/bash
function disable_systemd {
systemctl is-active centrifugo &>/dev/null
if [[ $? -eq 0 ]]; then
systemctl stop centrifugo || :
fi
systemctl is-enabled centrifugo &>/dev/null
if [[ $? -ne 0 ]]; then
systemctl disable centrifugo &>/dev/null
fi
rm -f /lib/systemd/system/centrifugo.service
systemctl daemon-reload
}
function disable_upstart {
initctl stop centrifugo || :
rm -f /etc/init/centrifugo.conf
initctl reload-configuration
}
function disable_update_rcd {
service centrifugo stop || :
update-rc.d -f centrifugo remove
rm -f /etc/init.d/centrifugo
}
function disable_chkconfig {
service centrifugo stop || :
chkconfig --del centrifugo
rm -f /etc/init.d/centrifugo
}
if [[ -f /etc/redhat-release ]]; then
# RHEL-variant logic
if [[ "$1" = "0" ]]; then
# Centrifugo is no longer installed, remove from init system
which systemctl &>/dev/null
if [[ $? -eq 0 ]]; then
disable_systemd
else
# Assuming sysv
disable_chkconfig
fi
rm -f /etc/default/centrifugo
fi
elif [[ -f /etc/debian_version ]]; then
# Debian/Ubuntu logic
if [[ "$1" != "upgrade" ]]; then
# Remove/purge
which systemctl &>/dev/null
if [[ $? -eq 0 ]]; then
disable_systemd
else
/sbin/init --version >/dev/null 2>/dev/null
if [[ $? -eq 0 && `/sbin/init --version` =~ upstart ]]; then
# Assuming upstart
disable_upstart
else
# Assuming sysv
disable_update_rcd
fi
fi
rm -f /etc/default/centrifugo
fi
elif [[ -f /etc/os-release ]]; then
source /etc/os-release
if [[ $ID = "amzn" ]]; then
# Amazon Linux logic
if [[ "$1" = "0" ]]; then
# Centrifugo is no longer installed, remove from init system
disable_chkconfig
rm -f /etc/default/centrifugo
fi
fi
fi

View File

@@ -0,0 +1 @@
#!/bin/bash