FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 0c401d4a authored by James Nairn's avatar James Nairn
Browse files

Tweaks and systemd config

parent 0a8cf0ad
No related branches found
No related tags found
No related merge requests found
[Unit]
Description=Runs Canto weekly_routine.sh script
After=network-online.target
Wants=network-online.target
[Service]
WorkingDirectory=/data/export/canto/canto
ExecStart=/data/export/canto/canto/jwrn3_test.sh
[Install]
WantedBy=default.target
\ No newline at end of file
[Unit]
Description=Run canto_weekly.service Monday morning at 1am.
[Timer]
OnCalendar=01:00:00
\ No newline at end of file
#!/bin/sh
# JWRN test script from within docker root
echo "jwrn3_test" > ./jwrn3_test_result
\ No newline at end of file
Notes
canto-space = /data/export/canto/canto
OnCalendar=Mon 01:00:00
Copy files to /etc/systemd/system/
sudo systemctl start canto_weekly.timer
Is ssh passwordless set up for root?
Shuold weekly run as root or another user?
test.sh 0 → 100755
#!/bin/sh
# Called if total failure happens
function fail {
# Echo output to stderr
echo "${1}" >&2
# Exit with non-zero code
exit 1
}
function retry {
# Define local vars
# Starting number
local n=1
# Max number of attempts
local max=5
# Sleep period in seconds until retry
local delay=2
# Loop
while true; do
# Run array of commands passed in and break loop if successful
"${@}" && break || {
# Else loop while attempt no is less than max
if [[ "${n}" -lt "${max}" ]]; then
# Increment attempt counter
((n++))
# echo status
echo "Command failed. Attempt ${n}/${max}"
# Sleep for period
sleep ${delay}
else
# Hit max attempts and still failed so giving up
fail "The command has failed after ${n} attempts."
fi
}
done
}
# Grab file from Daneb
FILENAME="marker_file.txt"
retry scp jwrn3@ent.csi.cam.ac.uk:"${FILENAME}" /tmp/
# Get DBNAME from downloaded file
if [[ -e "/tmp/${FILENAME}" ]]; then
DBNAME=$(cat "/tmp/${FILENAME}")
fi
# Check DBNAME is not blank
if [[ -z ${BDNAME }]]; then
echo "${DBNAME} is blank, cannot continue"
exit 1
fi
# Transform $DBNAME
sed -E "s/(^[[:space:]]+\-[[:space:]]\"dbi\:Pg\:dbname=)[[:alpha:]]+(\;[[:space:]]host=deneb\.pdn\.cam\.ac\.uk\")/\1${DBNAME}\2/" canto_deployment.yaml
\ No newline at end of file
#!/bin/sh
#weekly routine on Sunday pm /Monday am. This script should be run from /canto-space/
# JWRN
# /canto-space/ == /data/export/canto/canto
# copy/update of ontologies from /data/export/curfiles/ontologies/trunk/ into 'canto-space/import_export'
## gm comment: I don't really know how rsync works so I didn't know which options to choose (so didn't try to!) and the syntax may not be correct, but the first path should be OK if Canto is installed on the current vm.
......@@ -32,6 +34,8 @@ done
#replace merged ontology and reload all ontologies to Canto
##vt comment: Ideally, add the following 'if' routine . If hard to implement, remove the 'if' routine and make the three commands run by default
## JWRN comment: how do we know an ontology has been changed? Is there a piece of information we can write out and read back in?
## JWRN comment: may be easier to just update whatever and improve in time
if <any ontology has been changed>, then
......@@ -44,14 +48,84 @@ if <any ontology has been changed>, then
fi
# JWRN additions
#update of database name in canto_deploy.yaml
##vt comment: need lots of help here (as per point 6 in https://docs.google.com/document/d/19C-J8sJmZb_OSluxyzBWJxUkdR_N4sIpgjHI7u5pp0I/edit)
## query SELECT name FROM chado WHERE type='production' AND current='t'; > $
## to replace the value of dbi:Pg:dbname (i.e. 'flybase') in:
## Model::ChadoModel:
## connect_info:
## "dbi:Pg:dbname=flybase; host=deneb.pdn.cam.ac.uk"
# Function called by retry function if total failure happens
function fail {
# Echo output to stderr
echo "${1}" >&2
# Exit with non-zero code
exit 1
}
# Function to retry command until sucessful with max number of attempts
function retry {
# Starting number
local n=1
# Max number of attempts
local max=5
# Sleep period in seconds until retry
local delay=2
# Loop
while true; do
# Run array of commands passed in and break loop if successful
"${@}" && break || {
# Else loop while attempt no is less than max
if [[ "${n}" -lt "${max}" ]]; then
# Increment attempt counter
((n++))
# echo status
echo "Command failed. Attempt ${n}/${max}"
# Sleep for period
sleep ${delay}
else
# Hit max attempts and still failed so giving up
fail "The command has failed after ${n} attempts."
fi
}
done
}
# Set filename of file to pull from
MARKERFILE="./canto_done"
# Use retry function to pull marker file from deneb
# JWRN comment: requires ssh keys be setup for root to fbadmin
retry /usr/bin/scp fbadmin@deneb.pdb.cam.ac.uk:instance/canto_done "${MARKERFILE}"
# Get DBNAME from downloaded file
if [[ -e "${MARKERFILE}" ]]; then
DBNAME=$(cat "${MARKERFILE}")
else
echo "${MARKERFILE} does not exist, cannot continue"
exit 1
fi
# Check DBNAME is not blank
if [[ -z ${BDNAME }]]; then
echo "${DBNAME} is blank, cannot continue"
exit 1
fi
# Transform $DBNAME
CANTO_CONFIG="./canto_deployment.yaml"
if [[ -e "${CANTO_CONFIG}" ]]; then
sed -i.bak -E "s/(^[[:space:]]+\-[[:space:]]\"dbi\:Pg\:dbname=)[[:alpha:]]+(\;[[:space:]]host=deneb\.pdn\.cam\.ac\.uk\")/\1${DBNAME}\2/" "${CANTO_CONFIG}"
else
echo "${CANTO_CONFIG} does not exist, cannot continue"
exit 1
fi
#data import (using Gillian's scripts in the vm - see point 7.d in https://docs.google.com/document/d/19C-J8sJmZb_OSluxyzBWJxUkdR_N4sIpgjHI7u5pp0I/edit)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment