Skip to content

Instantly share code, notes, and snippets.

@marvin
Last active March 14, 2019 19:46
Show Gist options
  • Save marvin/9aa7193300cadf1014f704dd4ab9bfb5 to your computer and use it in GitHub Desktop.
Save marvin/9aa7193300cadf1014f704dd4ab9bfb5 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;
}
};
}
@marvin
Copy link
Author

marvin commented Apr 1, 2016

restart looks like this

david@vpn02:~/brotherhood/arma03_01$ ./restart.pl
Greuh Liberation stopped ...
Updating Arma 3 via steam ...
Redirecting stderr to '/home/david/Steam/logs/stderr.txt'
[  0%] Checking for available updates...
[----] Verifying installation...
Steam Console Client (c) Valve Corporation
-- type 'quit' to exit --
Loading Steam API...Created shared memory when not owner SteamController_Shared_mem
OK.

Logging in user 'saijitsu' to Steam Public...Logged in OK
Waiting for license info...OK
Success! App '233780' already up to date.

Restart Arma 3 Liberation server...
wait...
Starting Headless Client ...
19728
19810
All started ... Lets Rock ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment