Skip to content

Commit

Permalink
add bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEvilRoot committed Aug 7, 2020
1 parent efc1bd8 commit 54743bf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3

import os
import sys
import subprocess

from sys import argv
from os.path import exists

def write_pid_file(pid):
with open("pidfile", "w+") as pidfile:
pidfile.write(str(pid))

def remove_pid_file():
if exists("pidfile"):
os.remove("pidfile")

if len(argv) < 2:
print("Not enough arguments. You need to specify bot location")
sys.exit(1)

if not exists(argv[1]):
print(f"File {argv[1]} does not exists")
sys.exit(2)

bot = argv[1]
with open("bot.log", "w+b") as bot_out:
with subprocess.Popen(["java", "-jar", bot], stdout=bot_out, stderr=bot_out) as process:
print("process started with pid", process.pid)
write_pid_file(process.pid)
try:
process.wait()
except KeyboardInterrupt:
print("bootstrap has been killed by keyboard interrupt, stopping bot...")
print("process has been terminated with code", process.returncode)
remove_pid_file()
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "com.gt22"
version = "2.1"
version = "2.2"

repositories {
mavenCentral()
Expand Down

0 comments on commit 54743bf

Please sign in to comment.