+ return badre.search(out) or badre.search(err) or self.node.check_bad_host(out,err)
+
+
+class CCNxDaemon(Application):
+ """
+ An application also has dependencies, but also a command to be ran and monitored.
+
+ It adds the output of that command as traces.
+ """
+
+ def __init__(self, api=None):
+ super(CCNxDaemon,self).__init__(api)
+
+ # Attributes
+ self.ccnLocalPort = None
+ self.ccnRoutes = None
+ self.ccnxVersion = "0.7.1"
+
+ #self.ccnx_0_6_0_sources = "http://yans.pl.sophia.inria.fr/libs/ccnx-0.6.0.tar.gz"
+ self.ccnx_sources = "http://www.ccnx.org/releases/ccnx-%s.tar.gz"
+ self.buildDepends = 'make gcc openssl-devel expat-devel libpcap-devel libxml2-devel'
+
+ self.ccnx_build = (
+ " ( "
+ " cd .. && "
+ " test -d ccnx-src/build/bin "
+ " ) || ( "
+ # Not working, rebuild
+ "("
+ " mkdir -p ccnx-src && "
+ " wget -q -c -O ccnx-src.tar.gz %(ccnx_source_url)s &&"
+ " tar xf ccnx-src.tar.gz --strip-components=1 -C ccnx-src "
+ ") && "
+ "cd ccnx-src && "
+ "./configure && make"
+ " )") % dict(
+ ccnx_source_url = server.shell_escape(self.ccnx_sources % self.ccnxVersion),
+ )
+
+ self.ccnx_install = (
+ " ( "
+ " test -d ${BUILD}/ccnx-src/bin && "
+ " cp -r ${BUILD}/ccnx-src/bin ${SOURCES}"
+ " )"
+ )
+
+ self.env['PATH'] = "$PATH:${SOURCES}/bin"
+
+ def setup(self):
+ # setting ccn sources
+ if not self.build:
+ self.build = self.ccnx_build
+
+ if not self.install:
+ self.install = self.ccnx_install
+
+ super(CCNxDaemon, self).setup()
+
+ def start(self):
+ self.command = ""
+ if self.ccnLocalPort:
+ self.command = "export CCN_LOCAL_PORT=%s ; " % self.ccnLocalPort
+ self.command += " ccndstart "
+
+ # configure ccn routes
+ if self.ccnRoutes:
+ routes = self.ccnRoutes.split("|")
+
+ if self.ccnLocalPort:
+ routes = map(lambda route: "%s %s" %(route,
+ self.ccnLocalPort) if _ccnre.match(route) else route,
+ routes)
+
+ routes = map(lambda route: "ccndc add ccnx:/ %s" % route,
+ routes)
+
+ routescmd = " ; ".join(routes)
+ self.command += " ; "
+ self.command += routescmd
+
+ # Start will be invoked in prestart step
+ super(CCNxDaemon, self).start()
+
+ def kill(self):
+ self._logger.info("Killing %s", self)
+
+ command = "${SOURCES}/bin/ccndstop"
+
+ if self.ccnLocalPort:
+ self.command = "export CCN_LOCAL_PORT=%s; %s" % (self.ccnLocalPort, command)
+
+ cmd = self._replace_paths(command)
+ command = cStringIO.StringIO()
+ command.write(cmd)
+ command.seek(0)
+
+ try:
+ self._popen_scp(
+ command,
+ '%s@%s:%s' % (self.node.slicename, self.node.hostname,
+ os.path.join(self.home_path, "kill.sh"))
+ )
+ except RuntimeError, e:
+ raise RuntimeError, "Failed to kill ccndxdaemon: %s %s" \
+ % (e.args[0], e.args[1],)
+
+
+ script = "bash ./kill.sh"
+ (out,err),proc = rspawn.remote_spawn(
+ script,
+ pidfile = 'kill-pid',
+ home = self.home_path,
+ stdin = '/dev/null',
+ stdout = 'killlog',
+ stderr = rspawn.STDOUT,
+
+ host = self.node.hostname,
+ port = None,
+ user = self.node.slicename,
+ agent = None,
+ ident_key = self.node.ident_path,
+ server_key = self.node.server_key,
+ hostip = self.node.hostip,
+ )
+
+ if proc.wait():
+ raise RuntimeError, "Failed to kill cnnxdaemon: %s %s" % (out,err,)
+
+ super(CCNxDaemon, self).kill()
+