Commit de3238b6 authored by Caillat Michel's avatar Caillat Michel
Browse files

Adapted the code so that it takes into account the configuration environment...

Adapted the code so that it takes into account the configuration environment variables and can be easly deployed
parent 2098e8f1
%% Cell type:code id: tags:
``` python
import png
import h5py
```
%% Cell type:code id: tags:
``` python
```
......@@ -2,11 +2,13 @@ var express = require('express');
var router = express.Router();
const request = require('request');
var miningPyHost = "http://yafitss"
var miningPyPort = "4251"
var yafitssHost = process.env.YAFITSS_HOST;
var yafitssPort = process.env.YAFITSS_PORT;
console.log("I'll collaborate with ..." + yafitssHost + ":" + yafitssPort + " ...for the FITS files services");
var clienthttp = {
server : miningPyHost+":"+miningPyPort+"/artemix",
server : "http://"+yafitssHost+":"+yafitssPort+"/artemix",
getEntries : function(relKey, callback) {
let input = {
"relKey" : relKey
......
......@@ -10,10 +10,16 @@ var EXIT = function () { console.log(arguments.callee.name + ": exiting."); };
var PNG_ROOT_DIR = '/home/partemix/dataroot/PNG';
var miningPyHost = "http://yafitss"
var miningPyPort = "4251"
var yafitssHost = process.env.YAFITSS_HOST;
var yafitssPort = process.env.YAFITSS_PORT;
var yafitsvHost = process.env.YAFITSV_HOST;
var yafitsvPort = process.env.YAFITSV_PORT;
console.log("I'll collaborate with ..." + yafitssHost + ":" + yafitssPort + " ...for the FITS files services");
var useSAMP = false;
console.log ("Using SAMP ..." + useSAMP);
var renderingCapabilities = null;
......@@ -22,7 +28,7 @@ var renderingCapabilities = null;
/***************************************************/
var clienthttp = {
server : miningPyHost+":"+miningPyPort+"/artemix",
server : "http://"+yafitssHost+":"+yafitssPort+"/artemix",
setData : function(fileName, sessionID, callback){
request(this.server+"/setData?fileName="+fileName+"&sessionID="+sessionID, { json: true }, function(error, response, body){
callback(error, response, body);
......@@ -205,14 +211,14 @@ function(req, res, next) {
},
function(req, res) {
ENTER();
console.log("getHeader http request callback: arming");
var path_to_fits = req.query.path;
// retrieve the product name, i.e. the simple filename without extension nor prefix.
var product = path.parse(req.query.path).name;
console.log("product = " + product)
clienthttp.getHeader(path_to_fits, req.query.sessionID ? req.query.sessionID : 0, (error, response, body) => {
console.log("getHeader http request callback: entering")
if (error) {
var message = error.toString();
res.send(JSON.stringify({ error: message }));
......@@ -228,7 +234,7 @@ function(req, res) {
else {
header = JSON.parse(body["result"]);
useSAMP = header["INSTRUME"] != "SITELLE";
// Let's render the page depending on the dimensionality of the dataset.
// Ok it's a regular 3D dataset
......@@ -239,7 +245,8 @@ function(req, res) {
product: product,
header: header,
useSAMP: useSAMP,
renderingCapabilities: renderingCapabilities
renderingCapabilities: renderingCapabilities,
yafitsvPort:process.env.YAFITSV_PORT
};
res.render('olqv', params);
}
......@@ -253,7 +260,8 @@ function(req, res) {
product: product,
header: header,
useSAMP: useSAMP,
renderingCapabilities: renderingCapabilities
renderingCapabilities: renderingCapabilities,
yafitsvPort:process.env.YAFITSV_PORT
};
console.log("About to render olqv_2d with params = " + JSON.stringify(params, 0,4 ));
res.render('olqv_2d', params)
......@@ -268,8 +276,9 @@ function(req, res) {
res.render('olqv_error', params);
}
}
console.log("getHeader http request callback: exiting")
});
EXIT();
console.log("getHeader http request callback: armed");
});
router.get('/setData', function (req, res, next){
......@@ -282,24 +291,6 @@ router.get('/setData', function (req, res, next){
EXIT();
});
/*
router.get('/sumpng', function (req, res, next) {
var sliceIndex0 = req.query.si0;
var sliceIndex1 = req.query.si1;
var path_to_fits = req.query.path;
var sessionID = req.query.sessionID;
client.invoke("getSummedSliceRangeAsPNG", req.sessionID, sliceIndex0, sliceIndex1, path_to_fits, function (error, png, more) {
if (error){
console.log(error);
}
else {
res.set({'Content-type': 'image/png'});
res.send(png);
}
});
});
*/
/* A route to retrieve a PNG file indexed by a slice index */
router.get('/:product/:sliceIndex', function(req, res, next) {
......@@ -321,22 +312,6 @@ router.get('/:product/:sliceIndex', function(req, res, next) {
});
/* A route to display a spectrum */
router.get('/spectrum/:path'), function(req, res, next) {
path = req.params['path'];
client.invoke("setData", path, req.sessionID ?req.sessionID : 0, function (error, res, more) {
if (error) {
var message = error.toString();
console.log(message);
}
else {
header = JSON.parse(res);
res.render('index', {title: 'Express', op: 'spectrum', header:header})
}
});
}
/******************/
/* POST routes */
/******************/
......
looking for '/obs/partemix/TestPolymaps/bin/www' in the result of a ps aux.
----------------------------
/obs/partemix/TestPolymaps/bin/www /obs/partemix/TestPolymaps/bin/www
ARTEMIX '/obs/partemix/TestPolymaps/bin/www' server is running in process #450793
#!/usr/bin/env python
#
# --------------------------------------------------------------------------------------------
# This script is made to be run by cron at regular interval of time.
# It checks if a given application is running
# It this is not the case it launches it.
#
# Michel Caillat
# January 8th, 2018
# 3 septembre 2018
# 25 novembre 2018
#---------------------------------------------------------------------------------------------
import psutil, sys, subprocess, os, shlex
import smtplib
import socket
from email.mime.text import MIMEText
#
# Where are we ?
#
OLQVDir = os.path.dirname(os.path.realpath(__file__))
#
# What's the command we are looking for ?
#
lookingFor = OLQVDir + "/bin/www"
print ("looking for '%s' in the result of a ps aux." % lookingFor)
#
# Are we running the server already ?
#
# for item in p.cmdline():
for p in psutil.process_iter():
try:
for item in p.cmdline():
item = p.cmdline()[-1]
if str(lookingFor) == str(item) :
pinfo = p.as_dict(attrs=['pid'])
print ("----------------------------")
print (item + " " + lookingFor)
print ("ARTEMIX '%s' server is running in process #%d" % (lookingFor, pinfo['pid']))
sys.exit(1)
except psutil.NoSuchProcess:
pass
#
# Who are we ?
#
hostname = socket.gethostname()
#
# Which command do we want to launch
#
#
# Define the PORT to be listened at
#
port = "3001"
d = dict(os.environ.copy())
d["PORT"]=port
#
# Define the command to be launched
#
command = "/usr/bin/nohup %s"% (lookingFor)
args = shlex.split(command)
#
# The logging output
#
nohup_out = open(OLQVDir+"/nohup.out", "a")
#
# And go !
#
try :
print ("About to start command %r in a subprocess" % args)
subprocess.Popen(args, stdout=nohup_out, stderr=nohup_out, cwd=OLQVDir, env=d)
except Exception as e :
print (e.child_traceback)
#
# Send an email about the restarting of the server.
#
COMMASPACE = ', '
artemixCrew = ['Philippe.Salome@obspm.fr', 'yaye-awa.ba@obspm.fr', 'Michel.Caillat@obspm.fr']
msg = MIMEText('Everything\'s in the subject')
msg['Subject'] = "'" + command + "' has been relaunched on " + hostname +" ."
msg['From'] = 'partemix@obspm.fr'
msg['To'] = COMMASPACE.join(artemixCrew)
server = smtplib.SMTP('smtp.obspm.fr')
server.sendmail('artemix.lerma@obspm.fr', 'michel.caillat@obspm.fr', msg.as_string())
server.quit()
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -294,9 +294,6 @@
var ENTER = function () { console.log(arguments.callee.name + ": entering."); };
var EXIT = function () { console.log(arguments.callee.name + ": exiting."); };
//var server = "artemix.obspm.fr/fits";
var server = "juliette.obspm.fr:3021/";
<%if(useSAMP){%>
var sAMPPublisher = null;
<%}%>
......@@ -829,29 +826,6 @@ var SAMPPNGPublishControl = (function (Control) {
_map_2.addInteraction(_dragBox_2);
let _updateSlice = function () {
ENTER();
console.log('Request for a new slice');
document.getElementById('loading').style.display="block";
if (_im_layer_1) {
_map_1.removeLayer(_im_layer_1);
}
_im_layer_1 = new ol.layer.Image({
source: new ol.source.ImageStatic({
url: 'http://'+server+'/png/?path="'+_path+'"&si='+_sliceIndex,
projection: _projection_1,
imageExtent: _extent,
imageLoadFunction: _imageLoadFunction_1
})
});
console.log("adding the image layer");
_map_1.addLayer(_im_layer_1);
EXIT();
};
let _updateSliceWithPOST = function () {
console.log('_updateSliceWithPOST: entering');
document.getElementById('loading').style.display="block";
......@@ -879,9 +853,11 @@ var SAMPPNGPublishControl = (function (Control) {
if (_im_layer_1) {
_map_1.removeLayer(_im_layer_1);
}
console.log("I'll display " + path_to_png);
_im_layer_1 = new ol.layer.Image({
source: new ol.source.ImageStatic({
url : "http://"+server+"/"+path_to_png,
url : window.location.origin+"/"+path_to_png,
projection: _projection_1,
imageExtent: _extent,
imageLoadFunction: _imageLoadFunction_1})
......@@ -904,11 +880,7 @@ var SAMPPNGPublishControl = (function (Control) {
_sliceIndex = sliceIndex;
_path = path;
//_updateSlice();
_updateSliceWithPOST();
// var info=document.getElementById("info");
// info.innerText="channel #"+sliceIndex;
// info.style.opacity=0.75;
console.log('_displaySlice : exiting');
};
......@@ -935,7 +907,7 @@ var SAMPPNGPublishControl = (function (Control) {
}
_im_layer_2 = new ol.layer.Image({
source : new ol.source.ImageStatic({
url : "http://"+server+"/"+path_to_png,
url: window.location.origin+"/"+path_to_png,
projection : _projection_2,
imageExtent: _extent,
imageLoadFunction: _imageLoadFunction_2
......
......@@ -659,7 +659,7 @@ var _marker_styles_f = function(feature) {
}
_im_layer_1 = new ol.layer.Image({
source: new ol.source.ImageStatic({
url : "http://"+server+"/"+path_to_png,
url : window.location.origin + "/" + path_to_png,
projection: _projection_1,
imageExtent: _extent,
imageLoadFunction: _imageLoadFunction_1})
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment