-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/UADAF/UADAB-2.0
- Loading branch information
Showing
2 changed files
with
45 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters