Merge branch 'master' of https://Governor-Tarkin@bitbucket.org/Governor-Tarkin/swg...
[swg-src.git] / tools / startServer.pl
blobb78730878ae016fda8e73181e30f75e7c6bd585c
1 #! /usr/bin/perl
2 # ======================================================================
3 # ======================================================================
5 use strict;
6 use warnings;
8 # ======================================================================
9 # Globals
10 # ======================================================================
12 my $scriptName = $0;
13 $scriptName =~ s/^(.*)[\\\/]//;
15 # ======================================================================
16 # Subroutines
17 # ======================================================================
19 sub usage()
21 die "\nUsage:\n\t$scriptName current [ debug | release ] (default is debug)\n";
24 sub perforceWhere
26 local $_;
28 # find out where a perforce file resides on the local machine
29 my $result;
31 open(P4, "p4 where $_[0] |");
32 $_ = <P4>;
33 chomp;
34 my @where = split;
35 $result = $where[2];
36 close(P4);
39 return $result;
42 # ======================================================================
43 # Main
44 # ======================================================================
46 usage() if(@ARGV == 0 || (@ARGV >= 2 && $ARGV[1] ne "debug" && $ARGV[1] ne "release"));
48 my $branch = shift;
49 my $serverType = (@ARGV) ? shift : "debug";
51 # Update database
53 chdir(perforceWhere("//depot/swg/$branch/src/game/server/database/build/linux")) or die "Cannot change directory to database directory\n";
55 my $update_complete = 1;
56 my $dbUser = $ENV{"USER"};
57 $dbUser .= "_$branch" if($branch ne "current");
59 system("perl database_update.pl --delta --username=$dbUser > startServer.log") == 0 or die "database_update failed\n";
60 open(DBLOG, "startServer.log");
61 while(<DBLOG>)
63 $update_complete = 0 if(/ERROR/);
65 close(DBLOG);
67 die "Error while updating database - detailed info in startServer.log\n" if(!$update_complete);
68 unlink("startServer.log");
71 chdir(perforceWhere("//depot/swg/$branch/bootleg/linux")) || die "Cannot chdir to ".perforceWhere("//depot/swg/$branch/bootleg/linux")."\n";
73 # Extract new server exes if they exist
74 if(-e "servers_${serverType}.tar.gz")
76 print STDERR "Extracting new server exes...\n";
77 system("tar -xzf servers_${serverType}.tar.gz") == 0 || die "error extracting from $serverType server gzip\n";
78 system("rm -f servers_${serverType}.tar.gz") == 0 || die "error removing servers_${serverType}.gzip\n";
81 # Start up the server
82 system("$serverType/LoginServer -- \@loginServer.cfg &") == 0 || die "error starting LoginServer\n";
83 system("$serverType/TaskManager -- \@taskmanager.cfg &") == 0 || die "error starting TaskManager\n";