changeset 1693:45eaaf5146f3

add backup autostart
author Vadim Filimonov <fffilimonov@yandex.ru>
date Mon, 20 Jun 2022 10:29:43 +0300
parents d6ec67fa4a61
children 09aaca079ff3
files backup/classpath.sh backup/doc/autostart.txt backup/doc/install.txt backup/luan.sh backup/macos/addStartupScripts.sh backup/macos/removeStartupScripts.sh backup/macos/startLuanBackup.plist backup/macos/startLuanBackup.sh backup/macos/startupScripts.sh backup/restart.sh backup/start.sh backup/stop.sh
diffstat 12 files changed, 128 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backup/classpath.sh	Mon Jun 20 10:29:43 2022 +0300
@@ -0,0 +1,7 @@
+DIR=`pwd`;
+CLASSPATH=;
+
+for file in ${DIR}/../build/luan/jars/*.jar; do
+  CLASSPATH=${CLASSPATH}:${file};
+done
+export CLASSPATH
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backup/doc/autostart.txt	Mon Jun 20 10:29:43 2022 +0300
@@ -0,0 +1,16 @@
+Autostart macOS:
+
+1) Disable Mac OS SIP
+  https://developer.apple.com/library/content/documentation/Security/Conceptual/System_Integrity_Protection_Guide/ConfiguringSystemIntegrityProtection/ConfiguringSystemIntegrityProtection.html
+  Ask hosting support.
+
+2) Disable buit-in firewall
+  sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.pfctl.plist
+
+3) Add plists (need sudo password)
+  cd macos
+  ./addStartupScripts.sh
+
+If you need to remove plists use
+  cd macos
+  ./removeStartupScripts.sh
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backup/doc/install.txt	Mon Jun 20 10:29:43 2022 +0300
@@ -0,0 +1,10 @@
+Install on local machine:
+
+1) install java
+  brew tap caskroom/versions
+  brew install caskroom/cask/java8
+
+2) clone repo
+  hg clone https://hg.luan.software/luan
+
+3) make autostart
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backup/luan.sh	Mon Jun 20 10:29:43 2022 +0300
@@ -0,0 +1,2 @@
+. classpath.sh
+java -classpath $CLASSPATH luan.Luan "$@"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backup/macos/addStartupScripts.sh	Mon Jun 20 10:29:43 2022 +0300
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+. startupScripts.sh;
+
+mkdir -p $localStartup 2>/dev/null;
+
+cd $startup;
+for file in *.plist; do
+    log=${ROOTPWD}"/logs/startup.${file}.log";
+	sed "s~PWD~${startup}~g;\
+	     s~LOG~${log}~g;\
+	     s~USER~${user}~g;\
+	     s~ROOT~${ROOTPWD}~g" $file > ${localStartup}/${file};
+done;
+
+addStartup;
+
+cd $ROOTPWD;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backup/macos/removeStartupScripts.sh	Mon Jun 20 10:29:43 2022 +0300
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+. startupScripts.sh;
+
+cd $localStartup;
+
+for file in *.plist; do
+	sudo rm ${systemStarup}/${file};
+	sudo rm $file;
+done;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backup/macos/startLuanBackup.plist	Mon Jun 20 10:29:43 2022 +0300
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+    <dict>
+        <key>Label</key>
+        <string>com.luan.startLuanBackup</string>
+        <key>ProgramArguments</key>
+        <array>
+            <string>PWD/startLuanBackup.sh</string>
+            <string>ROOT</string>
+        </array>
+        <key>UserName</key>
+        <string>USER</string>
+        <key>RunAtLoad</key>
+        <true/>
+        <key>StandardErrorPath</key>
+        <string>LOG</string>
+        <key>StandardOutPath</key>
+        <string>LOG</string>
+    </dict>
+</plist>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backup/macos/startLuanBackup.sh	Mon Jun 20 10:29:43 2022 +0300
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+set -eu
+
+cd "$1";
+
+#can't determine if network is available at startup
+sleep 60;
+
+./start.sh "launchd";
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backup/macos/startupScripts.sh	Mon Jun 20 10:29:43 2022 +0300
@@ -0,0 +1,16 @@
+cd ..
+ROOTPWD=$(pwd);
+
+user=$(whoami);
+
+systemStarup='/Library/LaunchDaemons';
+localStartup=${ROOTPWD}'/local/startup';
+startup=${ROOTPWD}'/macos';
+
+function addStartup() {
+  cd $localStartup;
+  for file in *.plist; do
+    sudo ln -sf ${localStartup}/${file} ${systemStarup}/${file};
+    sudo chown root:wheel ${localStartup}/${file};
+  done;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backup/restart.sh	Mon Jun 20 10:29:43 2022 +0300
@@ -0,0 +1,2 @@
+./stop.sh
+./start.sh $*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backup/start.sh	Mon Jun 20 10:29:43 2022 +0300
@@ -0,0 +1,11 @@
+#!/bin/bash -e
+
+ROOTPWD=$(pwd);
+logsdir=${ROOTPWD}"/logs";
+servelog=${logsdir}"/server.log";
+
+if [ "$1" == "launchd" ]; then
+    ${ROOTPWD}/luan.sh server.luan $* &2>${servelog}
+else
+    ${ROOTPWD}/luan.sh server.luan $* &2>${servelog}&
+fi;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backup/stop.sh	Mon Jun 20 10:29:43 2022 +0300
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+LUAN_PIDS=$(ps ax | awk '{if($0~"[s]erver.luan"){print $1}}');
+kill -TERM $LUAN_PIDS;
+exit 0;