Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 118 additions & 50 deletions manifest.jps
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
type: update
id: file-sync
name: File Synchronization
version: '1.1'
logo: images/icon.png
homepage: http://docs.jelastic.com/file-synchronization
description: Lsyncd is a light-weight, live mirror solution used to synchronize app servers. Being wisely coupled with inotify, lsyncd initiates file sync only if it has detected any actual changes in the system. In such a way, the load on CPU is decreased and you do not burn up many resources on processing the synchronization.

version: '1.1'
baseUrl: https://raw.githubusercontent.com/jelastic-jps/file-sync/master/
baseUrl: https://raw.githubusercontent.com/sych74/file-sync/JE-70232/

targetEditions: any

Expand All @@ -30,55 +33,87 @@ targetNodes:
- llsmp
- lemp
- jetty
description: Lsyncd is a light-weight, live mirror solution used to synchronize app servers. Being wisely coupled with inotify, lsyncd initiates file sync only if it has detected any actual changes in the system. In such a way, the load on CPU is decreased and you do not burn up many resources on processing the synchronization.

name: File Synchronization

id: file-sync
settings:
main:
fields:
- default: one_env
values:
one_env:
en: One environment synchronization
two_envs:
en: Two environments synchronization
name: optional
showIf:
one_env:
- placeholder: relative to ${WEBROOT} for cp layer or /data for storage
name: path
caption: Sync path
type: string
required: false
- default: '10'
name: delay
caption: Sync delay (sec)
type: string
required: false
- caption: Exclude paths
name: exclude
type: text
height: 200
required: false
default: |
# Exclude paths for lsyncd/rsync synchronization
# One path per line, relative to sync source directory
# Examples:
# ROOT/wp-content/uploads/
# ROOT/wp-config.php
# *.log
# tmp/

onInstall: installRsyncDaemon
two_envs:
- placeholder: relative to ${WEBROOT} for cp layer or /data for storage
name: path
caption: Sync path
type: string
required: false
- default: '10'
name: delay
caption: Sync delay (sec)
type: string
required: false
- caption: Exclude paths
name: exclude
type: text
height: 200
required: false
default: |
# Exclude paths for lsyncd/rsync synchronization
# One path per line, relative to sync source directory
# Examples:
# ROOT/wp-content/uploads/
# ROOT/wp-config.php
# *.log
# tmp/
- placeholder: optional
name: address
caption: IP second environment
type: string
- placeholder: optional
name: password
caption: Password
type: string
type: radio-fieldset

configure:
fields: []
onBeforeInit: script: scripts/configureOnBeforeInit.js

settings:
fields:
- default: one_env
values:
one_env:
en: One environment synchronization
two_envs:
en: Two environments synchronization
name: optional
showIf:
one_env:
- placeholder: relative to ${WEBROOT} for cp layer or /data for storage
name: path
caption: Sync path
type: string
required: false
- default: '10'
name: delay
caption: Sync delay (sec)
type: string
required: false
two_envs:
- placeholder: relative to ${WEBROOT} for cp layer or /data for storage
name: path
caption: Sync path
type: string
required: false
- default: '10'
name: delay
caption: Sync delay (sec)
type: string
required: false
- placeholder: optional
name: address
caption: IP second environment
type: string
- placeholder: optional
name: password
caption: Password
type: string
type: radio-fieldset
buttons:
- caption: Configure
action: configure
settings: configure
loadingText: Configuring...
successText: The lsync/rsync configs have been updated successfully.

onAfterCloneNodes: installRsyncDaemon

Expand All @@ -90,19 +125,48 @@ onBeforeDeploy:

onAfterRemoveNode: installRsyncDaemon

onInstall: installRsyncDaemon

actions:
getLsyncdPath:
- cmd [${targetNodes.nodeGroup}]: |-
[ "${targetNodes.nodeGroup}" == "storage" ] && echo "/data/" || echo "${SERVER_WEBROOT}/"
- setGlobals:
lsyncdPath: ${response.out}

removeLsyncd:
- getLsyncdPath:
- cmd [${targetNodes.nodeGroup}]: |-
killall rsync lsyncd 2>&1
[ "${targetNodes.nodeGroup}" == "storage" ] && lsyndPath="/data" || lsyndPath="/var/www/webroot"
rm -rf ${lsyndPath}/lsyncd* 2>&1
rm -rf ${globals.lsyncdPath}lsyncd* 2>&1
crontab -l | sed "/lsyncd/d" | crontab -
- script: "${baseUrl}scripts/firewallRules.js"
param: uninstall

installRsyncDaemon:
- script: scripts/firewallRules.js
param: install
- script: scripts/installRsyncDaemon.js

configure:
- getLsyncdPath
- setupExcludeList:
execOn: ${targetNodes.nodeGroup}
lsyncdPath: ${globals.lsyncdPath}
- cmd [${targetNodes.nodeGroup}]: |-
sed -i "s|delay=[0-9]*|delay=${settings.delay}|g" ${globals.lsyncdPath}lsyncd/etc/lsyncd.conf
killall lsyncd 2>&1
/usr/bin/lsyncd ${globals.lsyncdPath}lsyncd/etc/lsyncd.conf &>>${globals.lsyncdPath}lsyncd/var/log/lsyncd_start.log

setupExcludeList:
- cmd [${execOn}]: |-
echo -n '' > ${lsyncdPath}lsyncd/etc/exclude.list
echo "${settings.exclude}" | while IFS= read -r line; do
line=$(echo "$line" | xargs)
[[ -z "$line" || "$line" == \#* || "$line" == /* || "$line" == *..* || "$line" =~ [\;\|\&\>\<\`\$\(] ]] && continue
echo "$line" >> ${lsyncdPath}lsyncd/etc/exclude.list
done

installLsync:
- cmd [${this.nodeId}]: |-
grep -a 'AlmaLinux' /etc/system-release && microdnf -y install lsyncd || yum install lsyncd -y;
Expand All @@ -127,13 +191,17 @@ actions:
sed -i "s|_USER|admin|g" ${this.lsyncdPath}lsyncd/etc/lsyncd.conf
sed -i "s|_INSTALL_DIRECTORY|${this.lsyncdPath}lsyncd|g" ${this.lsyncdPath}lsyncd/etc/rsync.conf
sed -i "s|apache|${this.user}|g" ${this.lsyncdPath}lsyncd/etc/rsync.conf
sed -i "/exclude = {/i\\ excludeFrom = \"${this.lsyncdPath}lsyncd/etc/exclude.list\"," ${this.lsyncdPath}lsyncd/etc/lsyncd.conf
sed -i "s|name|syncmodule|g" ${this.lsyncdPath}lsyncd/etc/lsyncd.conf
sed -i "s|_NAME|syncmodule|g" ${this.lsyncdPath}lsyncd/etc/rsync.conf
sed -i "s|_USER|admin|g" ${this.lsyncdPath}lsyncd/etc/rsync.conf
sed -i "s|_USER|admin|g" ${this.lsyncdPath}lsyncd/etc/lsyncd.conf
sed -i "s|_INSTALL_DIRECTORY|${this.lsyncdPath}lsyncd|g" ${this.lsyncdPath}lsyncd/etc/lsyncd.conf
sed -i "s|_USER|admin|g" ${this.lsyncdPath}lsyncd/etc/rsyncd.secrets
sed -i "s|_INSTALL_DIRECTORY|${this.lsyncdPath}lsyncd/|g" ${this.lsyncdPath}lsyncd/init.sh
- setupExcludeList:
execOn: ${this.nodeId}
lsyncdPath: ${this.lsyncdPath}
- cmd [${this.nodeId}]: |-
cd ${this.lsyncdPath}lsyncd/
chmod 600 etc/rsyncd.pass etc/rsyncd.secrets
Expand Down
63 changes: 63 additions & 0 deletions scripts/configureOnBeforeInit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Configure dialog: delay + exclude.list via api.env.file.Read (nodeId required).
// Placeholders: ${env.name}, ${targetNodes.nodeGroup}

var envName = "${env.name}";
var nodeGroup = "${targetNodes.nodeGroup}";
var currentDelay = "10";
var currentExclude = "";
var envResp, sampleNodeId, envInfo, ni, confPath, excludeFullPath, confRead, dm, exRead;
var lp = "/data/";

if (nodeGroup != "storage") {
envResp = api.env.control.GetContainerEnvVarsByGroup(envName, session, nodeGroup);
if (envResp.result == 0 && envResp.object && envResp.object.WEBROOT) {
lp = envResp.object.WEBROOT;
if (lp.charAt(lp.length - 1) != "/") {
lp += "/";
}
} else {
lp = "/var/www/webroot/";
}
}

envInfo = jelastic.environment.control.GetEnvInfo(envName, session);
if (envInfo.result == 0 && envInfo.nodes) {
for (ni = 0; ni < envInfo.nodes.length; ni++) {
if (envInfo.nodes[ni].nodeGroup == nodeGroup) {
sampleNodeId = envInfo.nodes[ni].id;
break;
}
}
}

function readNodeFile(path) {
return api.env.file.Read(envName, session, String(path), null, nodeGroup, sampleNodeId);
}

confPath = lp + "lsyncd/etc/lsyncd.conf";
excludeFullPath = lp + "lsyncd/etc/exclude.list";
confRead = readNodeFile(confPath);
if (confRead.result == 0 && confRead.body) {
dm = String(confRead.body).match(/delay=(\d+)/);
if (dm) {
currentDelay = dm[1];
}
}
exRead = readNodeFile(excludeFullPath);
if (exRead.result == 0 && exRead.body != null) {
currentExclude = String(exRead.body);
}
settings.fields.push({
name: "delay",
caption: "Sync delay (sec)",
type: "string",
value: currentDelay
});
settings.fields.push({
name: "exclude",
caption: "Exclude paths",
type: "text",
height: 200,
value: currentExclude
});
return settings;
1 change: 1 addition & 0 deletions scripts/twoEnvs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ grep -q "@"${EXT_IP}"/" ${lsyncdPath}/lsyncd/etc/lsyncd.conf || echo "sync {
target=\"rsync://admin@"${EXT_IP}"/syncmodule\",
delay=${syncDelay},
delete='running',
excludeFrom = \"${lsyncdPath}lsyncd/etc/exclude.list\",
exclude = {
\"lsyncd/\",
\"lsyncd_tmp/\"
Expand Down