fix: initialize the tick manager

This commit is contained in:
Emmanuel BENOîT 2024-12-31 12:13:52 +01:00
parent dcec07be8a
commit 4772e7cdc4
Signed by: Emmanuel BENOîT
SSH key fingerprint: SHA256:l7PFUUF5TCDsvYeQC9OnTNz08dFY7Fvf4Hv3neIqYpg
3 changed files with 4 additions and 93 deletions

View file

@ -9,6 +9,7 @@ RUN <<EOF
curl -sSLo /tmp/debsuryorg-archive-keyring.deb \ curl -sSLo /tmp/debsuryorg-archive-keyring.deb \
https://packages.sury.org/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
dpkg -i /tmp/debsuryorg-archive-keyring.deb dpkg -i /tmp/debsuryorg-archive-keyring.deb
rm -f /tmp/debsuryorg-archive-keyring.deb
echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" \ echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" \
> /etc/apt/sources.list.d/php.list > /etc/apt/sources.list.d/php.list
apt-get update apt-get update
@ -17,7 +18,7 @@ RUN <<EOF
php8.3-xml socat php8.3-xml socat
a2dismod mpm_event a2dismod mpm_event
a2enmod mpm_prefork a2enmod mpm_prefork
adduser --system --group \ adduser --system --in-group www-data \
--shell '/usr/bin/php /opt/lwb5/scripts/ticks.php' \ --shell '/usr/bin/php /opt/lwb5/scripts/ticks.php' \
--comment 'LWB5 Ticks' \ --comment 'LWB5 Ticks' \
--home /opt/lwb5 --no-create-home \ --home /opt/lwb5 --no-create-home \

View file

@ -5,8 +5,7 @@ socat -u \
SYSTEM:"(sed -z 's/$/\\\\n/'; /bin/echo)" \ SYSTEM:"(sed -z 's/$/\\\\n/'; /bin/echo)" \
& &
#perl /opt/lwb5/scripts/control.pl --start perl /opt/lwb5/scripts/control.pl --start
#perl /opt/lwb5/scripts/control.pl TMINIT
: "${APACHE_CONFDIR:=/etc/apache2}" : "${APACHE_CONFDIR:=/etc/apache2}"
: "${APACHE_RUN_DIR:=/run/apache2}" : "${APACHE_RUN_DIR:=/run/apache2}"

View file

@ -110,11 +110,6 @@ chmod 0770, $ctrlPath;
NOEND => \&gameCancelEnd, NOEND => \&gameCancelEnd,
"END" => \&gameChangeEnd, "END" => \&gameChangeEnd,
SETDEF => \&setDefaultGame, SETDEF => \&setDefaultGame,
BOTON => \&startBot,
BOTOFF => \&killBot,
PCPID => \&proxyDetectorID,
PCON => \&startProxyDetector,
PCOFF => \&stopProxyDetector
); );
# Reader loop # Reader loop
@ -164,14 +159,8 @@ sub start {
print "LegacyWorlds - Initialising game\n"; print "LegacyWorlds - Initialising game\n";
print " -> Controller\n"; print " -> Controller\n";
sleep(1); sleep(1);
print " -> Proxy detector\n";
&sendMessage("PCON");
sleep(1);
print " -> Ticks manager\n"; print " -> Ticks manager\n";
&sendMessage("TMINIT"); &sendMessage("TMINIT");
sleep(1);
print " -> IRC bot\n";
&sendMessage("BOTON");
exit(0); exit(0);
} }
} }
@ -179,15 +168,9 @@ sub start {
sub stop { sub stop {
print "LegacyWolrds - Shutting down\n"; print "LegacyWolrds - Shutting down\n";
print " -> IRC bot\n";
&sendMessage("BOTOFF");
sleep(1);
print " -> Ticks manager\n"; print " -> Ticks manager\n";
&sendMessage("TMSTOP"); &sendMessage("TMSTOP");
sleep(1); sleep(1);
print " -> Proxy detector\n";
&sendMessage("PCOFF");
sleep(1);
print " -> Controller\n"; print " -> Controller\n";
&sendMessage("DIE"); &sendMessage("DIE");
exit(0); exit(0);
@ -261,7 +244,7 @@ sub tickManagerStart {
return if &tickManagerStatus(); return if &tickManagerStatus();
return unless -f "$Bin/ticks.php"; return unless -f "$Bin/ticks.php";
if ($> == 0) { if ($> == 0) {
system("su - lwticks"); system("runuser -u lwticks -- bash -c 'cd $Bin; php ticks.php'");
} else { } else {
system("cd $Bin; php ticks.php"); system("cd $Bin; php ticks.php");
} }
@ -277,28 +260,6 @@ sub tickManagerStop {
unlink("$ctrlPath/tickManager.pid"); unlink("$ctrlPath/tickManager.pid");
} }
#
# Start IRC bot
#
sub startBot {
&killBot();
if ($> == 0) {
system("su - lwbot");
} else {
system("cd $Bin/../ircbot; (php bot.php &) </dev/null >/dev/null 2>&1");
}
}
#
# Stop IRC bot
#
sub killBot {
return unless -f "$ctrlPath/ircbot.pid";
my $pid = `cat $ctrlPath/ircbot.pid`;
kill 15, $pid;
unlink("$ctrlPath/ircbot.pid");
}
# #
# Check tick manager status # Check tick manager status
# #
@ -522,53 +483,3 @@ sub setDefaultGame {
print NEWCONF @newConf; print NEWCONF @newConf;
close(NEWCONF); close(NEWCONF);
} }
#
# Proxy detector PID update
#
sub proxyDetectorID {
my $pid = shift;
return unless $pid;
open(PIDFILE, "> $ctrlPath/proxyDetector.pid");
print PIDFILE "$pid " . time() . "\n";
close(PIDFILE);
}
#
# Start proxy detector
#
sub startProxyDetector {
return if &proxyDetectorStatus();
return unless -f "$Bin/proxycheck.php";
if ($> == 0) {
system("su - lwproxy");
} else {
system("cd $Bin; php proxycheck.php");
}
}
#
# Stop proxy detector
#
sub stopProxyDetector {
my $pid;
return unless ($pid = &proxyDetectorStatus());
kill 15, $pid;
unlink("$ctrlPath/proxyDetector.pid");
}
#
# Check proxy detector status
#
sub proxyDetectorStatus {
return 0 unless -f "$ctrlPath/proxyDetector.pid";
open(PIDFILE, "< $ctrlPath/proxyDetector.pid");
my $data = <PIDFILE>;
close(PIDFILE);
chomp($data);
my ($pid, $time) = split / /, $data;
return (time() - $time < 22 ? $pid : 0);
}