Skip to content

Instantly share code, notes, and snippets.

@wallopthecat
Forked from marvin/restart.pl
Created July 11, 2017 16:35
Show Gist options
  • Save wallopthecat/6fed3ecda1347741c041d455fe9fe318 to your computer and use it in GitHub Desktop.
Save wallopthecat/6fed3ecda1347741c041d455fe9fe318 to your computer and use it in GitHub Desktop.
TBH Arma3 Greuh Liberation restart script
#!/usr/bin/perl
use warnings;
use strict;
use constant PORT => 2302;
use constant PATH => $ENV{'PWD'}.'/';
use constant PIDFILE => PATH.PORT.'.pid';
use constant HCPIDFILE => PATH.PORT.'.hcpid';
unless (-f PATH.'arma3server') {
print STDERR "Can't found server binary!\n";
exit;
}
# check for arma3server PID
if (-f PIDFILE) {
open (IN, '<'.PIDFILE) or die "Can't open: $!";
my $pid1 = int(<IN>);
close (IN);
my $res1 = `kill -TERM $pid1 2>&1`;
print STDERR $res1,"\n" if $res1;
unlink (PIDFILE) if (-f PIDFILE);
}
# check for arma3 headless client PID
if (-f HCPIDFILE) {
open (IN, '<'.HCPIDFILE) or die "Can't open: $!";
my $pid2 = int(<IN>);
close (IN);
my $res2 = `kill -TERM $pid2 2>&1`;
print STDERR $res2,"\n" if $res2;
unlink (HCPIDFILE) if (-f HCPIDFILE);
}
print STDERR "Greuh Liberation stopped ...\n";
print STDERR "Updating Arma 3 via steam ...\n";
my $steamcmd = 'sh /home/david/steamcmd/update_arma3_01.sh';
my $steamres = `$steamcmd`;
print STDERR $steamres,"\n" if $steamres;
print STDERR "Restart Arma 3 Liberation server...\n";
chdir (PATH);
# sleep then start server
my $cmd1 = '/usr/bin/screen -h 20000 -fa -d -m -S greuhsrv '.PATH.'run.sh';
my $res1 = `$cmd1`;
print STDERR $res1,"\n" if $res1;
# sleep again bevor starting headless
print STDERR "wait...\n";
select(undef, undef, undef, 20.0);
print STDERR "Starting Headless Client ...\n";
my $cmd2 = '/usr/bin/screen -h 20000 -fa -d -m -S greuhhc '.PATH.'run_client.sh';
my $res2 = `$cmd2`;
print STDERR $res2,"\n" if $res2;
create_pid();
print STDERR "All started ... Lets Rock ...\n";
exit;
sub create_pid {
open(my $fh1, "screen -list|grep greuhsrv|");
while (<$fh1>){
if (/Detached/) {
/\s*(\d*)\.(.*?)\s/;
my ($pid1, $name1) = ($1, $2);
print STDERR $pid1,"\n" if $pid1;
open(my $f1, '>', PIDFILE) or die "Could not open: $!";
print $f1 $pid1;
close $f1;
}
};
open(my $fh2, "screen -list|grep greuhhc|");
while (<$fh2>){
if (/Detached/) {
/\s*(\d*)\.(.*?)\s/;
my ($pid2, $name2) = ($1, $2);
print STDERR $pid2,"\n" if $pid2;
open(my $f2, '>', HCPIDFILE) or die "Could not open: $!";
print $f2 $pid2;
close $f2;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment