diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8d4bfcf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +nohup.out diff --git a/example.sh b/example.sh new file mode 100755 index 0000000..ac8b93c --- /dev/null +++ b/example.sh @@ -0,0 +1,4 @@ +# Example which can check exit code status + +python service.py status +echo $? diff --git a/main.py b/main.py new file mode 100644 index 0000000..6cd753f --- /dev/null +++ b/main.py @@ -0,0 +1,21 @@ +# THIS IS EXAMPLE OF main.py +# EXAMPLE OF SCRIPT WHICH YOU WOULD RUN IN YOUR PROJECT + +# ------------------------------ +# INJECTION: USE IN YOUR PROJECT +# ------------------------------ +import os + +# Process Identification Number (PID in Unix(-like)) +pid = os.getpid() + +with open("pid.txt", "w") as f: + f.write(str(pid)) +# ----------- END -------------- + +# Shit which running forever / stucked / ... +from time import sleep + +while True: + print("I'm still running...") + sleep(0.1) diff --git a/pid.txt b/pid.txt new file mode 100644 index 0000000..e69de29 diff --git a/service.py b/service.py new file mode 100644 index 0000000..e8aad11 --- /dev/null +++ b/service.py @@ -0,0 +1,110 @@ +import os +import signal +import sys +import textwrap +import time +from pathlib import Path + +PID_FILE = Path("pid.txt") +MAIN_SCRIPT = "main.py" +START_DELAY = 0.3 + + +def display_help(): + print( + textwrap.dedent("""\ + Usage: python service.py