]> us-delaporte.pagekite.me Git - dotfiles.git/blobdiff - invoke/luanti-remote/tasks.py
Add screen to luanti remote invoke
[dotfiles.git] / invoke / luanti-remote / tasks.py
index d0d5152a7ec82910336b753377fa7cdbfebeb704..75b7e39a3425961052d53da3d093ebe4c48c211e 100644 (file)
@@ -9,7 +9,7 @@ LOCAL_HOME=os.environ.get('HOME')
 TODAY = dt.now().strftime('%Y.%m.%d')
 
 WORLD='world'
-SERVE=f'{HOME}/luanti/bin/luantiserver --gameid minetest --worldname world'
+SERVE=f'screen -d -m {HOME}/luanti/bin/luantiserver --gameid minetest --worldname world'
 
 SSH=f'ssh {USER}@{IP}'
 SCP=f'scp {USER}@{IP}'
@@ -20,10 +20,6 @@ LOCAL_BACKUPS=f'{LOCAL_HOME}/backup/luanti'
 def browse(c, url):
     c.run(f"librefox {url}")
 
-@task
-def serve(c):
-    print(f"Attempting to connect to {IP}")
-    c.run(f'ssh {USER}@{IP} -C {SERVE}')
 
 @task
 def compress(c):
@@ -31,6 +27,10 @@ def compress(c):
 
 @task(compress)
 def backup(c):
+    stopped = input("Is the server stopped?")
+    if(stopped != 'y'):
+        print("so go stop the server...")
+        exit()
     print(f'Backup {HOME}/{BACKUP_FILE} to {LOCAL_BACKUPS}')
     c.run(f'mkdir -p {LOCAL_BACKUPS}')
     c.run(f'{SCP}:{BACKUP_FILE} {LOCAL_BACKUPS}')
@@ -53,10 +53,18 @@ def verify_backup(c):
     DB_FILE='map.sqlite'
     print(f'Extracting {DB_FILE} from {TAR_FILE}')
     c.run(f'tar --extract --file={LOCAL_BACKUPS}/{BACKUP_FILE} {WORLD}/{DB_FILE}')
-    result = c.run(f'echo "PRAGMA quick_check;" | sqlite3 {DB_FILE})')
-    print(f'Check on {DB_FILE}: {result}')
-    if(result != 'ok'):
-        print("database is corrupt, restore from backup")
+    result = c.run(f'echo "PRAGMA quick_check;" | sqlite3 {DB_FILE}')
+    # print(f'Check on {DB_FILE}: {result}')
+    # print(f'Exit code: {result.exited}')
 
-    
+    if(not 'ok' in result.stdout):
+        print("=========================================")
+        print("database is corrupt, restore from backup!")
+        print("=========================================")
 
+@task(verify_backup)
+def serve(c):
+    print(f"Attempting to connect to {IP}")
+    result = c.run(f'ssh {USER}@{IP} -C {SERVE}')
+    print(f'Server should now be running in a remote screen session.')
+    print(result)