mirror of
https://github.com/vvzvlad/vestasync.git
synced 2025-08-21 12:37:53 +03:00
refactoting services and remove upload by timer
This commit is contained in:
@ -1,9 +0,0 @@
|
||||
[Unit]
|
||||
Description=Pull git changes
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/bin/pullgit.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
@ -1,6 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
git config --global user.name vestasync_wb_$(hostname)
|
||||
git config --global user.email "vestasync@fake.mail"
|
||||
cd /mnt/data/etc/
|
||||
git fetch > /dev/null 2>&1 || true
|
||||
git pull > /dev/null 2>&1 || true
|
@ -1,10 +0,0 @@
|
||||
[Unit]
|
||||
Description=Run pullgit.service every 10 min
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*:0/10
|
||||
Persistent=true
|
||||
Unit=pullgit.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
@ -1,9 +0,0 @@
|
||||
[Unit]
|
||||
Description=Push git changes
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/bin/pushgit.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
@ -1,11 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
apt-mark showmanual > /mnt/data/etc/vestasync/packages
|
||||
echo $(hostname) > /mnt/data/etc/vestasync/hostname
|
||||
export GIT_AUTHOR_NAME="vestasync_wb_$(hostname)"
|
||||
export GIT_COMMITTER_NAME="vestasync_wb_$(hostname)"
|
||||
export LC_TIME=en_GB.UTF-8
|
||||
cd /mnt/data/etc/ > /dev/null 2>&1 || true
|
||||
git add . > /dev/null 2>&1 || true
|
||||
git commit -m "$(date +"%Y-%m-%d %H:%M:%S %z %Z")" > /dev/null 2>&1 || true
|
||||
git push -u origin master > /dev/null 2>&1 || true
|
||||
|
@ -1,10 +0,0 @@
|
||||
[Unit]
|
||||
Description=Run pushgit.service daily
|
||||
|
||||
[Timer]
|
||||
OnCalendar=daily
|
||||
Persistent=true
|
||||
Unit=pushgit.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
7
files/pushgit/pushgit.sh
Normal file
7
files/pushgit/pushgit.sh
Normal file
@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
apt-mark showmanual > /mnt/data/etc/vestasync/packages
|
||||
echo $(hostname) > /mnt/data/etc/vestasync/hostname
|
||||
cd /mnt/data/etc/
|
||||
git add .
|
||||
git commit -m "$(date +"%Y-%m-%d %H:%M:%S %z %Z")"
|
||||
git push -u origin master
|
@ -1,9 +1,9 @@
|
||||
[Unit]
|
||||
Description=Script triggered by file changes in a folder (including subfolders)
|
||||
Description=Main pushgit
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/bin/pushgit_inotify.sh
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
12
files/pushgit/pushgit_inotify.sh
Normal file
12
files/pushgit/pushgit_inotify.sh
Normal file
@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
export GIT_AUTHOR_NAME="vestasync_wb_$(hostname)"
|
||||
export GIT_COMMITTER_NAME="vestasync_wb_$(hostname)"
|
||||
export LC_TIME=en_GB.UTF-8
|
||||
EXCLUDE_PATTERN='(^|\/)(\.git|packages|hostname|wb-mqtt-mbgate\.conf|resolv\.conf)($|\/)'
|
||||
inotifywait -m -r -e close_write,move,create,delete --exclude "$EXCLUDE_PATTERN" --format '%w%f' /mnt/data/etc | while read FILE
|
||||
do
|
||||
/usr/local/bin/pushgit.sh
|
||||
done
|
||||
|
||||
|
||||
|
12
files/pushgit/pushgit_inotify_special.service
Normal file
12
files/pushgit/pushgit_inotify_special.service
Normal file
@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=Script triggered by file changes in a folder (including subfolders)
|
||||
|
||||
[Service]
|
||||
ExecStartPre=systemctl stop pushgit_inotify.service
|
||||
ExecStart=systemctl start pushgit_inotify.service
|
||||
ExecStop=systemctl stop pushgit_inotify.service
|
||||
Type=oneshot
|
||||
RemainAfterExit=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
9
files/pushgit/pushgit_run_on_start.timer
Normal file
9
files/pushgit/pushgit_run_on_start.timer
Normal file
@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Run pushgit.service on start
|
||||
|
||||
[Timer]
|
||||
OnBootSec=180
|
||||
Unit=pushgit_inotify_special.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
@ -1,14 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
EXCLUDE_PATTERN='(^|/)(\.git($|/)|wb-mqtt-mbgate\.conf$|resolv\.conf$)'
|
||||
|
||||
inotifywait -m -r -e close_write,move,create,delete --exclude "$EXCLUDE_PATTERN" --format '%w%f' /mnt/data/etc | while read FILE
|
||||
do
|
||||
echo $(hostname) > /mnt/data/etc/vestasync/hostname
|
||||
export GIT_AUTHOR_NAME="vestasync_wb_$(hostname)_inotify"
|
||||
export GIT_COMMITTER_NAME="vestasync_wb_$(hostname)_inotify"
|
||||
export LC_TIME=en_GB.UTF-8
|
||||
cd /mnt/data/etc/
|
||||
git add .
|
||||
git commit -m "$(date +"%Y-%m-%d %H:%M:%S %z %Z")" # > /dev/null 2>&1 || true
|
||||
git push -u origin master
|
||||
done
|
@ -16,11 +16,6 @@ defineVirtualDevice("vestasync", {
|
||||
value: false,
|
||||
title: "Auto push on files changed"
|
||||
},
|
||||
autopush_timer: {
|
||||
type: "switch",
|
||||
value: false,
|
||||
title: "Auto push every day"
|
||||
},
|
||||
push_now: {
|
||||
type: "pushbutton",
|
||||
value: false,
|
||||
@ -70,15 +65,7 @@ function _update_vestasync() {
|
||||
}
|
||||
});
|
||||
|
||||
runShellCommand("systemctl is-active pushgit_inotify.service", {
|
||||
captureOutput: true,
|
||||
exitCallback: function (exitCode, capturedOutput) {
|
||||
var isEnabled = capturedOutput.trim() === "active";
|
||||
getControl("vestasync/autopush_inotify").setValue({ value: isEnabled, notify: false })
|
||||
}
|
||||
});
|
||||
|
||||
runShellCommand("systemctl is-active pushgit.timer", {
|
||||
runShellCommand("systemctl is-active pushgit_inotify_special.service", {
|
||||
captureOutput: true,
|
||||
exitCallback: function (exitCode, capturedOutput) {
|
||||
var isEnabled = capturedOutput.trim() === "active";
|
||||
@ -100,28 +87,16 @@ function _update_vestasync() {
|
||||
|
||||
};
|
||||
|
||||
defineRule("_vestasync_autopush_timer", {
|
||||
whenChanged: "vestasync/autopush_timer",
|
||||
then: function (newValue, devName, cellName) {
|
||||
if (dev.vestasync.autopush_timer) {
|
||||
runShellCommand("systemctl stop pushgit.timer ; systemctl disable pushgit.timer ; systemctl daemon-reload ; systemctl enable pushgit.timer ; systemctl start pushgit.timer");
|
||||
_update_vestasync();
|
||||
} else {
|
||||
runShellCommand("systemctl stop pushgit.timer ; systemctl disable pushgit.timer");
|
||||
_update_vestasync();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
defineRule("_vestasync_autopush_inotify", {
|
||||
whenChanged: "vestasync/autopush_inotify",
|
||||
then: function (newValue, devName, cellName) {
|
||||
if (dev.vestasync.autopush_inotify) {
|
||||
runShellCommand("systemctl stop pushgit_inotify.service ; systemctl disable pushgit_inotify.service ; systemctl daemon-reload ; systemctl enable pushgit_inotify.service ; systemctl start pushgit_inotify.service");
|
||||
runShellCommand("systemctl start pushgit_inotify_special.service");
|
||||
_update_vestasync();
|
||||
} else {
|
||||
runShellCommand("systemctl stop pushgit_inotify.service ; systemctl disable pushgit_inotify.service");
|
||||
runShellCommand("systemctl stop pushgit_inotify_special.service");
|
||||
_update_vestasync();
|
||||
}
|
||||
}
|
||||
@ -133,9 +108,7 @@ defineRule("_vestasync_push", {
|
||||
whenChanged: "vestasync/push_now",
|
||||
then: function (newValue, devName, cellName) {
|
||||
if (dev.vestasync.push_now) {
|
||||
runShellCommand("systemctl start pushgit.service");
|
||||
dev.vestasync.push_now = false;
|
||||
_update_vestasync();
|
||||
runShellCommand("/usr/local/bin/pushgit.sh");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user