2006-02-21 01:30:38 +01:00
// yacyVersion.java
2007-04-27 11:23:44 +02:00
// ----------------
// (C) 2007 by Michael Peter Christen; mc@anomic.de, Frankfurt a. M., Germany
// first published 27.04.2007 on http://yacy.net
//
// This is a part of YaCy, a peer-to-peer based web search engine
2006-02-21 01:30:38 +01:00
//
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
//
2007-04-27 11:23:44 +02:00
// LICENSE
//
2006-02-21 01:30:38 +01:00
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2005-09-22 12:30:55 +02:00
package de.anomic.yacy ;
2008-04-10 11:53:07 +02:00
import java.io.BufferedOutputStream ;
2007-06-28 16:52:26 +02:00
import java.io.File ;
2008-04-05 15:17:16 +02:00
import java.io.FileOutputStream ;
2007-04-27 11:23:44 +02:00
import java.io.IOException ;
2007-07-02 17:16:05 +02:00
import java.util.ArrayList ;
2007-04-27 11:23:44 +02:00
import java.util.Comparator ;
2007-07-02 17:16:05 +02:00
import java.util.HashMap ;
2007-04-27 11:23:44 +02:00
import java.util.Iterator ;
import java.util.Map ;
import java.util.TreeSet ;
2007-07-12 18:23:33 +02:00
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
2007-04-27 11:23:44 +02:00
import de.anomic.htmlFilter.htmlFilterContentScraper ;
2008-04-05 15:17:16 +02:00
import de.anomic.http.HttpClient ;
import de.anomic.http.HttpResponse ;
2008-04-10 01:35:20 +02:00
import de.anomic.http.JakartaCommonsHttpClient ;
2008-04-05 15:17:16 +02:00
import de.anomic.http.HttpResponse.Saver ;
2007-06-28 16:52:26 +02:00
import de.anomic.plasma.plasmaSwitchboard ;
2007-07-02 00:43:08 +02:00
import de.anomic.server.serverCore ;
2007-06-29 15:56:28 +02:00
import de.anomic.server.serverSystem ;
import de.anomic.server.logging.serverLog ;
2007-04-27 11:23:44 +02:00
2008-01-11 15:13:08 +01:00
public final class yacyVersion implements Comparator < yacyVersion > , Comparable < yacyVersion > {
2007-04-27 11:23:44 +02:00
// general release info
2005-09-22 12:30:55 +02:00
public static final float YACY_SUPPORTS_PORT_FORWARDING = ( float ) 0 . 383 ;
public static final float YACY_SUPPORTS_GZIP_POST_REQUESTS = ( float ) 0 . 40300772 ;
2005-11-11 00:48:20 +01:00
public static final float YACY_ACCEPTS_RANKING_TRANSMISSION = ( float ) 0 . 414 ;
2006-11-20 03:46:53 +01:00
public static final float YACY_HANDLES_COLLECTION_INDEX = ( float ) 0 . 486 ;
2007-11-29 03:07:37 +01:00
public static final float YACY_POVIDES_REMOTECRAWL_LISTS = ( float ) 0 . 550 ;
2007-12-20 03:46:41 +01:00
public static final float YACY_STANDARDREL_IS_PRO = ( float ) 0 . 557 ;
2007-04-27 11:23:44 +02:00
// information about latest release, retrieved by other peers release version
public static double latestRelease = 0 . 1 ; // this value is overwritten when a peer with later version appears
// information about latest release, retrieved from download pages
2007-06-28 16:52:26 +02:00
// this static information should be overwritten by network-specific locations
2008-03-16 23:31:54 +01:00
// for details see defaults/yacy.network.freeworld.unit
2008-01-12 01:43:33 +01:00
private static HashMap < yacyURL , DevMain > latestReleases = new HashMap < yacyURL , DevMain > ( ) ;
2008-03-16 23:31:54 +01:00
public static ArrayList < yacyURL > latestReleaseLocations = new ArrayList < yacyURL > ( ) ; // will be initialized with value in defaults/yacy.network.freeworld.unit
2007-04-27 11:23:44 +02:00
2007-07-11 01:56:25 +02:00
// private static release info about this release; is generated only once and can be retrieved by thisVersion()
private static yacyVersion thisVersion = null ;
2007-04-27 11:23:44 +02:00
// class variables
public float releaseNr ;
public String dateStamp ;
public int svn ;
2008-01-12 01:43:33 +01:00
public boolean mainRelease ;
2007-09-05 11:01:35 +02:00
public yacyURL url ;
2007-06-28 16:52:26 +02:00
public String name ;
2007-04-27 11:23:44 +02:00
2007-09-05 11:01:35 +02:00
public yacyVersion ( yacyURL url ) {
2007-04-27 11:23:44 +02:00
this ( url . getFileName ( ) ) ;
this . url = url ;
}
public yacyVersion ( String release ) {
// parse a release file name
// the have the following form:
// yacy_dev_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz
// yacy_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz
// i.e. yacy_v0.51_20070321_3501.tar.gz
this . url = null ;
2007-06-28 16:52:26 +02:00
this . name = release ;
2007-04-27 11:23:44 +02:00
if ( ( release = = null ) | | ( ! release . endsWith ( " .tar.gz " ) ) ) {
throw new RuntimeException ( " release file name ' " + release + " ' is not valid, no tar.gz " ) ;
}
// cut off tail
release = release . substring ( 0 , release . length ( ) - 7 ) ;
2007-06-28 16:52:26 +02:00
if ( release . startsWith ( " yacy_pro_v " ) ) {
2007-12-20 03:46:41 +01:00
release = release . substring ( 10 ) ;
} else if ( release . startsWith ( " yacy_emb_v " ) ) {
2008-01-12 01:43:33 +01:00
throw new RuntimeException ( " release file name ' " + release + " ' is not valid, no support for emb " ) ;
2007-04-27 11:23:44 +02:00
} else if ( release . startsWith ( " yacy_v " ) ) {
release = release . substring ( 6 ) ;
} else {
throw new RuntimeException ( " release file name ' " + release + " ' is not valid, wrong prefix " ) ;
}
// now all release names have the form
// ${releaseVersion}_${DSTAMP}_${releaseNr}
String [ ] comp = release . split ( " _ " ) ; // should be 3 parts
if ( comp . length ! = 3 ) {
throw new RuntimeException ( " release file name ' " + release + " ' is not valid, 3 information parts expected " ) ;
}
try {
this . releaseNr = Float . parseFloat ( comp [ 0 ] ) ;
} catch ( NumberFormatException e ) {
throw new RuntimeException ( " release file name ' " + release + " ' is not valid, ' " + comp [ 0 ] + " ' should be a float number " ) ;
}
2007-06-28 16:52:26 +02:00
this . mainRelease = ( ( int ) ( this . releaseNr * ( float ) 1000 ) ) % 10 = = 0 ;
//System.out.println("Release version " + this.releaseNr + " is " + ((this.mainRelease) ? "main" : "std"));
2007-04-27 11:23:44 +02:00
this . dateStamp = comp [ 1 ] ;
if ( this . dateStamp . length ( ) ! = 8 ) {
throw new RuntimeException ( " release file name ' " + release + " ' is not valid, ' " + comp [ 1 ] + " ' should be a 8-digit date string " ) ;
}
try {
this . svn = Integer . parseInt ( comp [ 2 ] ) ;
} catch ( NumberFormatException e ) {
throw new RuntimeException ( " release file name ' " + release + " ' is not valid, ' " + comp [ 2 ] + " ' should be a integer number " ) ;
}
// finished! we parsed a relase string
}
2008-01-12 01:43:33 +01:00
public static final class DevMain {
public TreeSet < yacyVersion > dev , main ;
public DevMain ( TreeSet < yacyVersion > dev , TreeSet < yacyVersion > main ) {
this . dev = dev ;
this . main = main ;
}
}
2008-01-11 15:13:08 +01:00
public int compareTo ( yacyVersion obj ) {
2007-07-11 01:56:25 +02:00
// returns 0 if this object is equal to the obj, -1 if this is smaller than obj and 1 if this is greater than obj
2008-01-11 15:13:08 +01:00
return compare ( this , obj ) ;
2007-04-27 11:23:44 +02:00
}
2008-01-11 15:13:08 +01:00
public int compare ( yacyVersion v0 , yacyVersion v1 ) {
2007-04-27 11:23:44 +02:00
// compare-operator for two yacyVersion objects
// must be implemented to make it possible to put this object into
// a ordered structure, like TreeSet or TreeMap
2008-01-11 15:13:08 +01:00
return ( new Integer ( v0 . svn ) ) . compareTo ( new Integer ( v1 . svn ) ) ;
2007-04-27 11:23:44 +02:00
}
public boolean equals ( Object obj ) {
yacyVersion v = ( yacyVersion ) obj ;
2007-07-19 17:32:10 +02:00
return ( this . svn = = v . svn ) & & ( this . url . toNormalform ( true , true ) . equals ( v . url . toNormalform ( true , true ) ) ) ;
2007-04-27 11:23:44 +02:00
}
public int hashCode ( ) {
2007-07-19 17:32:10 +02:00
return this . url . toNormalform ( true , true ) . hashCode ( ) ;
2007-04-27 11:23:44 +02:00
}
public String toAnchor ( ) {
// generates an anchor string that can be used to embed in an html for direct download
2008-01-12 01:43:33 +01:00
return " <a href= " + this . url . toNormalform ( true , true ) + " >YaCy " + ( ( this . mainRelease ) ? " main release " : " dev release " ) + " v " + this . releaseNr + " , SVN " + this . svn + " </a> " ;
2007-06-28 16:52:26 +02:00
}
2007-04-27 11:23:44 +02:00
2007-07-11 01:56:25 +02:00
// static methods:
public static final yacyVersion thisVersion ( ) {
// construct a virtual release name for this release
if ( thisVersion = = null ) {
plasmaSwitchboard sb = plasmaSwitchboard . getSwitchboard ( ) ;
2008-04-10 00:59:17 +02:00
if ( sb = = null ) return null ;
2007-12-20 03:46:41 +01:00
boolean full = new File ( sb . getRootPath ( ) , " libx " ) . exists ( ) ;
2007-07-11 01:56:25 +02:00
thisVersion = new yacyVersion (
2007-12-20 03:46:41 +01:00
" yacy " + ( ( full ) ? " " : " _emb " ) +
2007-07-11 01:56:25 +02:00
" _v " + sb . getConfig ( " version " , " 0.1 " ) + " _ " +
sb . getConfig ( " vdate " , " 19700101 " ) + " _ " +
sb . getConfig ( " svnRevision " , " 0 " ) + " .tar.gz " ) ;
}
return thisVersion ;
}
2007-07-17 01:47:21 +02:00
public static final yacyVersion rulebasedUpdateInfo ( boolean manual ) {
2007-07-11 01:56:25 +02:00
// according to update properties, decide if we should retrieve update information
// if true, the release that can be obtained is returned.
// if false, null is returned
plasmaSwitchboard sb = plasmaSwitchboard . getSwitchboard ( ) ;
2007-12-20 03:46:41 +01:00
// check if update process allows update retrieve
2007-07-11 01:56:25 +02:00
String process = sb . getConfig ( " update.process " , " manual " ) ;
2007-07-17 01:47:21 +02:00
if ( ( ! manual ) & & ( ! process . equals ( " auto " ) ) ) {
2007-07-18 15:03:20 +02:00
yacyCore . log . logInfo ( " rulebasedUpdateInfo: not an automatic update selected " ) ;
2007-07-17 01:47:21 +02:00
return null ; // no, its a manual or guided process
}
2007-07-11 01:56:25 +02:00
2007-07-12 18:23:33 +02:00
// check if the last retrieve time is a minimum time ago
2007-07-19 00:45:29 +02:00
long cycle = Math . max ( 1 , sb . getConfigLong ( " update.cycle " , 168 ) ) * 60 * 60 * 1000 ; // update.cycle is hours
2007-07-12 18:23:33 +02:00
long timeLookup = sb . getConfigLong ( " update.time.lookup " , System . currentTimeMillis ( ) ) ;
2007-07-17 01:47:21 +02:00
if ( ( ! manual ) & & ( timeLookup + cycle > System . currentTimeMillis ( ) ) ) {
2007-07-18 15:03:20 +02:00
yacyCore . log . logInfo ( " rulebasedUpdateInfo: too early for a lookup for a new release (timeLookup = " + timeLookup + " , cycle = " + cycle + " , now = " + System . currentTimeMillis ( ) + " ) " ) ;
2007-07-17 01:47:21 +02:00
return null ; // no we have recently made a lookup
}
2007-07-11 01:56:25 +02:00
2007-07-12 18:23:33 +02:00
// check if we know that there is a release that is more recent than that which we are using
2008-01-12 01:43:33 +01:00
DevMain releasess = yacyVersion . allReleases ( true ) ;
yacyVersion latestmain = ( releasess . main . size ( ) = = 0 ) ? null : releasess . main . last ( ) ;
yacyVersion latestdev = ( releasess . dev . size ( ) = = 0 ) ? null : releasess . dev . last ( ) ;
2007-07-11 01:56:25 +02:00
String concept = sb . getConfig ( " update.concept " , " any " ) ;
String blacklist = sb . getConfig ( " update.blacklist " , " . \\ ...[123] " ) ;
2007-07-19 17:32:10 +02:00
2007-07-17 01:47:21 +02:00
if ( ( manual ) | | ( concept . equals ( " any " ) ) ) {
2007-07-11 01:56:25 +02:00
// return a dev-release or a main-release
2007-07-19 17:32:10 +02:00
if ( ( latestdev ! = null ) & &
( ( latestmain = = null ) | | ( latestdev . compareTo ( latestmain ) > 0 ) ) & &
( ! ( Float . toString ( latestdev . releaseNr ) . matches ( blacklist ) ) ) ) {
// consider a dev-release
if ( latestdev . compareTo ( thisVersion ( ) ) > 0 ) {
return latestdev ;
} else {
yacyCore . log . logInfo (
" rulebasedUpdateInfo: latest dev " + latestdev . name +
" is not more recent than installed release " + thisVersion ( ) . name ) ;
2007-07-17 01:47:21 +02:00
return null ;
}
2007-07-19 17:32:10 +02:00
}
if ( latestmain ! = null ) {
// consider a main release
2007-07-17 01:47:21 +02:00
if ( ( Float . toString ( latestmain . releaseNr ) . matches ( blacklist ) ) ) {
2007-07-19 17:32:10 +02:00
yacyCore . log . logInfo (
" rulebasedUpdateInfo: latest dev " + latestdev . name +
" matches with blacklist ' " + blacklist + " ' " ) ;
2007-07-17 01:47:21 +02:00
return null ;
}
if ( latestmain . compareTo ( thisVersion ( ) ) > 0 ) return latestmain ; else {
2007-07-19 17:32:10 +02:00
yacyCore . log . logInfo (
" rulebasedUpdateInfo: latest main " + latestmain . name +
" is not more recent than installed release (1) " + thisVersion ( ) . name ) ;
2007-07-17 01:47:21 +02:00
return null ;
}
2007-07-11 01:56:25 +02:00
}
}
2007-07-19 17:32:10 +02:00
if ( ( concept . equals ( " main " ) ) & & ( latestmain ! = null ) ) {
2007-07-11 01:56:25 +02:00
// return a main-release
2007-07-17 01:47:21 +02:00
if ( ( Float . toString ( latestmain . releaseNr ) . matches ( blacklist ) ) ) {
2007-07-19 17:32:10 +02:00
yacyCore . log . logInfo (
" rulebasedUpdateInfo: latest main " + latestmain . name +
" matches with blacklist' " + blacklist + " ' " ) ;
2007-07-17 01:47:21 +02:00
return null ;
}
if ( latestmain . compareTo ( thisVersion ( ) ) > 0 ) return latestmain ; else {
2007-07-19 17:32:10 +02:00
yacyCore . log . logInfo (
" rulebasedUpdateInfo: latest main " + latestmain . name +
" is not more recent than installed release (2) " + thisVersion ( ) . name ) ;
2007-07-17 01:47:21 +02:00
return null ;
}
2007-07-11 01:56:25 +02:00
}
2007-07-17 01:47:21 +02:00
yacyCore . log . logInfo ( " rulebasedUpdateInfo: failed to find more recent release " ) ;
2007-07-11 01:56:25 +02:00
return null ;
}
2008-01-12 01:43:33 +01:00
public static DevMain allReleases ( boolean force ) {
2007-06-28 16:52:26 +02:00
// join the release infos
2008-01-12 01:43:33 +01:00
DevMain [ ] a = new DevMain [ latestReleaseLocations . size ( ) ] ;
2007-07-02 17:16:05 +02:00
for ( int j = 0 ; j < latestReleaseLocations . size ( ) ; j + + ) {
2008-01-12 01:43:33 +01:00
a [ j ] = getReleases ( latestReleaseLocations . get ( j ) , force ) ;
2007-04-27 11:23:44 +02:00
}
2008-01-12 01:43:33 +01:00
TreeSet < yacyVersion > alldev = new TreeSet < yacyVersion > ( ) ;
TreeSet < yacyVersion > allmain = new TreeSet < yacyVersion > ( ) ;
for ( int j = 0 ; j < a . length ; j + + ) if ( ( a [ j ] ! = null ) & & ( a [ j ] . dev ! = null ) ) alldev . addAll ( a [ j ] . dev ) ;
for ( int j = 0 ; j < a . length ; j + + ) if ( ( a [ j ] ! = null ) & & ( a [ j ] . main ! = null ) ) allmain . addAll ( a [ j ] . main ) ;
return new DevMain ( alldev , allmain ) ;
2007-04-27 11:23:44 +02:00
}
2008-01-12 01:43:33 +01:00
private static DevMain getReleases ( yacyURL location , boolean force ) {
2007-06-28 16:52:26 +02:00
// get release info from a internet resource
2008-01-12 01:43:33 +01:00
DevMain latestRelease = latestReleases . get ( location ) ;
2007-07-11 01:56:25 +02:00
if ( force | |
2007-07-12 18:23:33 +02:00
( latestRelease = = null ) / * | |
2007-07-02 17:16:05 +02:00
( ( latestRelease [ 0 ] . size ( ) = = 0 ) & &
( latestRelease [ 1 ] . size ( ) = = 0 ) & &
( latestRelease [ 2 ] . size ( ) = = 0 ) & &
2007-07-12 18:23:33 +02:00
( latestRelease [ 3 ] . size ( ) = = 0 ) ) * / ) {
2007-07-02 17:16:05 +02:00
latestRelease = allReleaseFrom ( location ) ;
2007-07-12 18:23:33 +02:00
latestReleases . put ( location , latestRelease ) ;
2007-04-27 11:23:44 +02:00
}
2007-07-02 17:16:05 +02:00
return latestRelease ;
2007-04-27 11:23:44 +02:00
}
2008-01-12 01:43:33 +01:00
private static DevMain allReleaseFrom ( yacyURL url ) {
2007-04-27 11:23:44 +02:00
// retrieves the latest info about releases
// this is done by contacting a release location,
// parsing the content and filtering+parsing links
// returns the version info if successful, null otherwise
htmlFilterContentScraper scraper ;
try {
scraper = htmlFilterContentScraper . parseResource ( url ) ;
} catch ( IOException e ) {
return null ;
}
// analyse links in scraper resource, and find link to latest release in it
2008-01-22 12:51:43 +01:00
Map < yacyURL , String > anchors = scraper . getAnchors ( ) ; // a url (String) / name (String) relation
Iterator < yacyURL > i = anchors . keySet ( ) . iterator ( ) ;
2008-01-12 01:43:33 +01:00
TreeSet < yacyVersion > devreleases = new TreeSet < yacyVersion > ( ) ;
TreeSet < yacyVersion > mainreleases = new TreeSet < yacyVersion > ( ) ;
2007-04-27 11:23:44 +02:00
yacyVersion release ;
while ( i . hasNext ( ) ) {
2008-01-22 12:51:43 +01:00
url = i . next ( ) ;
2007-04-27 11:23:44 +02:00
try {
release = new yacyVersion ( url ) ;
//System.out.println("r " + release.toAnchor());
2008-01-12 01:43:33 +01:00
if ( release . mainRelease ) mainreleases . add ( release ) ;
if ( ! release . mainRelease ) devreleases . add ( release ) ;
2007-04-27 11:23:44 +02:00
} catch ( RuntimeException e ) {
// the release string was not well-formed.
// that might have been another link
// just dont care
continue ;
}
}
2007-07-11 01:56:25 +02:00
plasmaSwitchboard . getSwitchboard ( ) . setConfig ( " update.time.lookup " , System . currentTimeMillis ( ) ) ;
2008-01-12 01:43:33 +01:00
return new DevMain ( devreleases , mainreleases ) ;
2007-06-28 16:52:26 +02:00
}
2008-04-08 23:36:33 +02:00
public static boolean downloadRelease ( yacyVersion release ) {
2007-06-28 16:52:26 +02:00
File storagePath = plasmaSwitchboard . getSwitchboard ( ) . releasePath ;
// load file
2007-07-04 00:55:47 +02:00
File download = new File ( storagePath , release . url . getFileName ( ) ) ;
2008-04-10 01:35:20 +02:00
HttpClient client = new JakartaCommonsHttpClient ( 120000 , null , null ) ;
2008-04-05 15:17:16 +02:00
HttpResponse res = null ;
try {
res = client . GET ( release . url . toString ( ) ) ;
2008-04-10 11:53:07 +02:00
Saver . writeContent ( res , new BufferedOutputStream ( new FileOutputStream ( download ) ) , null ) ;
2008-04-08 23:36:33 +02:00
if ( ( ! download . exists ( ) ) | | ( download . length ( ) = = 0 ) ) throw new IOException ( " wget of url " + release . url + " failed " ) ;
} catch ( IOException e ) {
serverLog . logSevere ( " yacyVersion " , " download of " + release . name + " failed: " + e . getMessage ( ) ) ;
if ( download . exists ( ) ) download . delete ( ) ;
2008-04-05 15:17:16 +02:00
} finally {
2008-04-08 23:36:33 +02:00
if ( res ! = null ) {
2008-04-05 15:17:16 +02:00
// release connection
res . closeStream ( ) ;
}
}
2007-07-11 01:56:25 +02:00
plasmaSwitchboard . getSwitchboard ( ) . setConfig ( " update.time.download " , System . currentTimeMillis ( ) ) ;
2008-04-08 23:36:33 +02:00
return download . exists ( ) ;
2007-04-27 11:23:44 +02:00
}
2007-06-28 22:36:15 +02:00
2007-06-29 15:56:28 +02:00
public static void restart ( ) {
2007-07-11 01:56:25 +02:00
plasmaSwitchboard sb = plasmaSwitchboard . getSwitchboard ( ) ;
2007-06-29 15:56:28 +02:00
if ( System . getProperty ( " os.name " ) . toLowerCase ( ) . startsWith ( " win " ) ) {
// create yacy.restart file which is used in Windows startscript
2007-07-11 01:56:25 +02:00
final File yacyRestart = new File ( sb . getRootPath ( ) , " DATA/yacy.restart " ) ;
2007-06-29 15:56:28 +02:00
if ( ! yacyRestart . exists ( ) ) {
try {
yacyRestart . createNewFile ( ) ;
plasmaSwitchboard . getSwitchboard ( ) . terminate ( 5000 ) ;
} catch ( IOException e ) {
serverLog . logSevere ( " SHUTDOWN " , " restart failed " , e ) ;
}
}
}
2007-06-29 23:36:18 +02:00
if ( serverSystem . canExecUnix ) {
// start a re-start daemon
try {
serverLog . logInfo ( " RESTART " , " INITIATED " ) ;
2007-07-02 17:16:05 +02:00
String script =
2007-12-14 20:17:54 +01:00
" #!/bin/sh " + serverCore . LF_STRING +
" cd " + sb . getRootPath ( ) + " /DATA/RELEASE/ " + serverCore . LF_STRING +
" while [ -f ../yacy.running ]; do " + serverCore . LF_STRING +
" sleep 1 " + serverCore . LF_STRING +
" done " + serverCore . LF_STRING +
" cd ../../ " + serverCore . LF_STRING +
" nohup ./startYACY.sh > /dev/null " + serverCore . LF_STRING ;
2007-08-20 23:52:52 +02:00
File scriptFile = new File ( sb . getRootPath ( ) , " DATA/RELEASE/restart.sh " ) ;
2007-06-29 23:36:18 +02:00
serverSystem . deployScript ( scriptFile , script ) ;
serverLog . logInfo ( " RESTART " , " wrote restart-script to " + scriptFile . getAbsolutePath ( ) ) ;
serverSystem . execAsynchronous ( scriptFile ) ;
serverLog . logInfo ( " RESTART " , " script is running " ) ;
2007-07-11 01:56:25 +02:00
sb . terminate ( 5000 ) ;
2007-06-29 23:36:18 +02:00
} catch ( IOException e ) {
serverLog . logSevere ( " RESTART " , " restart failed " , e ) ;
}
}
2007-06-29 15:56:28 +02:00
}
2007-07-02 17:16:05 +02:00
public static void deployRelease ( String release ) {
2007-06-29 15:56:28 +02:00
//byte[] script = ("cd " + plasmaSwitchboard.getSwitchboard().getRootPath() + ";while [ -e ../yacy.running ]; do sleep 1;done;tar xfz " + release + ";cp -Rf yacy/* ../../;rm -Rf yacy;cd ../../;startYACY.sh").getBytes();
2007-07-02 17:16:05 +02:00
try {
2007-07-11 01:56:25 +02:00
plasmaSwitchboard sb = plasmaSwitchboard . getSwitchboard ( ) ;
2008-02-01 00:40:47 +01:00
String apphome = sb . getRootPath ( ) . toString ( ) ;
2007-07-02 17:16:05 +02:00
serverLog . logInfo ( " UPDATE " , " INITIATED " ) ;
String script =
2007-12-14 20:17:54 +01:00
" #!/bin/sh " + serverCore . LF_STRING +
" cd " + sb . getRootPath ( ) + " /DATA/RELEASE/ " + serverCore . LF_STRING +
2007-12-31 15:52:17 +01:00
" if gunzip -t " + release + serverCore . LF_STRING +
" then " + serverCore . LF_STRING +
2007-12-14 20:17:54 +01:00
" gunzip -c " + release + " | tar xf - " + serverCore . LF_STRING +
" while [ -f ../yacy.running ]; do " + serverCore . LF_STRING +
" sleep 1 " + serverCore . LF_STRING +
" done " + serverCore . LF_STRING +
2008-02-01 00:40:47 +01:00
" cp -Rf yacy/* " + apphome + serverCore . LF_STRING +
2007-12-14 20:17:54 +01:00
" rm -Rf yacy " + serverCore . LF_STRING +
2007-12-31 15:52:17 +01:00
" else " + serverCore . LF_STRING +
" while [ -f ../yacy.running ]; do " + serverCore . LF_STRING +
" sleep 1 " + serverCore . LF_STRING +
2008-01-03 21:22:21 +01:00
" done " + serverCore . LF_STRING +
2007-12-31 15:52:17 +01:00
" fi " + serverCore . LF_STRING +
2008-02-01 00:40:47 +01:00
" cd " + apphome + serverCore . LF_STRING +
2007-12-14 20:17:54 +01:00
" nohup ./startYACY.sh > /dev/null " + serverCore . LF_STRING ;
2007-07-11 01:56:25 +02:00
File scriptFile = new File ( sb . getRootPath ( ) , " DATA/RELEASE/update.sh " ) ;
2007-07-02 17:16:05 +02:00
serverSystem . deployScript ( scriptFile , script ) ;
serverLog . logInfo ( " UPDATE " , " wrote update-script to " + scriptFile . getAbsolutePath ( ) ) ;
serverSystem . execAsynchronous ( scriptFile ) ;
serverLog . logInfo ( " UPDATE " , " script is running " ) ;
2007-07-11 01:56:25 +02:00
sb . setConfig ( " update.time.deploy " , System . currentTimeMillis ( ) ) ;
sb . terminate ( 5000 ) ;
2007-07-02 17:16:05 +02:00
} catch ( IOException e ) {
serverLog . logSevere ( " UPDATE " , " update failed " , e ) ;
}
2007-06-28 22:36:15 +02:00
}
2007-07-12 18:23:33 +02:00
/ * *
* Converts combined version - string to a pretty string , e . g . " 0.435/01818 " or " dev/01818 " ( development version ) or " dev/00000 " ( in case of wrong input )
*
* @param ver Combined version string matching regular expression : " \ A( \ d+ \ . \ d{3})( \ d{4}| \ d{5}) \ z " < br >
* ( i . e . : start of input , 1 or more digits in front of decimal point , decimal point followed by 3 digits as major version , 4 or 5 digits for SVN - Version , end of input )
* @return If the major version is & lt ; 0 . 11 - major version is separated from SVN - version by '/' , e . g . " 0.435/01818 " < br >
* If the major version is & gt ; = 0 . 11 - major version is replaced by " dev " and separated SVN - version by '/' , e . g . " dev/01818 " < br >
* " dev/00000 " - If the input does not matcht the regular expression above
* /
public static String combined2prettyVersion ( String ver ) {
return combined2prettyVersion ( ver , " " ) ;
}
public static String combined2prettyVersion ( String ver , String computerName ) {
final Matcher matcher = Pattern . compile ( " \\ A( \\ d+ \\ . \\ d{1,3})( \\ d{0,5}) \\ z " ) . matcher ( ver ) ;
if ( ! matcher . find ( ) ) {
serverLog . logWarning ( " STARTUP " , " Peer ' " + computerName + " ': wrong format of version-string: ' " + ver + " '. Using default string 'dev/00000' instead " ) ;
return " dev/00000 " ;
}
String mainversion = ( Double . parseDouble ( matcher . group ( 1 ) ) < 0 . 11 ? " dev " : matcher . group ( 1 ) ) ;
String revision = matcher . group ( 2 ) ;
for ( int i = revision . length ( ) ; i < 5 ; + + i ) revision + = " 0 " ;
return mainversion + " / " + revision ;
}
/ * *
* Combines the version of YaCy with the versionnumber from SVN to a
* combined version
*
* @param version Current given version .
* @param svn Current version given from SVN .
* @return String with the combined version .
* /
2008-04-05 15:17:16 +02:00
public static double versvn2combinedVersion ( double version , int svn ) {
return ( Math . rint ( ( version * 100000000 . 0 ) + ( ( double ) svn ) ) / 100000000 ) ;
2007-07-12 18:23:33 +02:00
}
public static void main ( String [ ] args ) {
2008-04-05 15:17:16 +02:00
System . out . println ( thisVersion ( ) ) ;
2007-07-12 18:23:33 +02:00
float base = ( float ) 0 . 53 ;
String blacklist = " ....[123] " ;
String test ;
for ( int i = 0 ; i < 20 ; i + + ) {
test = Float . toString ( base + ( ( ( float ) i ) / 1000 ) ) ;
System . out . println ( test + " is " + ( ( test . matches ( blacklist ) ) ? " blacklisted " : " not blacklisted " ) ) ;
}
}
2005-09-22 12:30:55 +02:00
}