Add openrc service script
This commit is contained in:
parent
5eebcb6815
commit
c23314e120
10
builder
10
builder
|
@ -124,7 +124,7 @@ function run() { ## Setup the working directory and make it ready for developmen
|
|||
function rigel() { ## Run the rigel server
|
||||
# shellcheck source=.venv/bin/activate
|
||||
. "$ME/.venv/bin/activate"
|
||||
"$ME/rigel/server.py" "$ME/.env" $1
|
||||
"$ME/rigel/server.py" --env "$ME/.env" $1
|
||||
deactivate
|
||||
}
|
||||
|
||||
|
@ -136,6 +136,14 @@ function help() { ## Print out this help message
|
|||
awk 'BEGIN {FS=":"}; {printf "\033[36m%-30s\033[0m %s\n", $1, $2}'
|
||||
}
|
||||
|
||||
function install-openrc() { ## Install openrc service for Rigel(doesn't enable it)
|
||||
# shellcheck source=.venv/bin/activate
|
||||
cp "$ME/rigel/service/openrc/rigel" /tmp/rigel
|
||||
sed -i "s%<root-project>%$ME%g" /tmp/rigel
|
||||
sudo cp "/tmp/rigel" /etc/init.d/
|
||||
sudo chmod 0755 /etc/init.d/rigel
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Main logic
|
||||
# -----------------------------------------------------------------------------
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
BOT_TOKEN=<telegrom-bot-token>
|
||||
HOST=localhost
|
||||
PORT=6666
|
|
@ -12,7 +12,7 @@ In order to use it, first you need to setup the project which you can just call
|
|||
script like:
|
||||
|
||||
```bash
|
||||
./builder rigel [start|stop|status]
|
||||
./builder rigel
|
||||
```
|
||||
|
||||
Rigel will listen to the tcp port provided by HOST and PORT vars in `.env`(at the root of
|
||||
|
@ -24,3 +24,7 @@ It will reply back with "OK". Also if it get the message "//close" then it will
|
|||
close the connection to that client.
|
||||
|
||||
Have Fun!
|
||||
|
||||
## TODO
|
||||
* Fix the bug when client closes the connect prematurely.
|
||||
* Make Rigel install friendly
|
||||
|
|
|
@ -12,11 +12,12 @@
|
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
# You should have received a copy of the GNU General Public License
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
import signal
|
||||
import asyncio
|
||||
|
||||
|
||||
import daemon
|
||||
import dotenv
|
||||
|
@ -33,28 +34,45 @@ def main(conf):
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
config = dotenv.dotenv_values(sys.argv[1])
|
||||
action = sys.argv[2]
|
||||
pfile = config.get("PID_FILE", "/var/run/rigel.pid")
|
||||
logs = config.get("LOGFILE")
|
||||
logfile = open(logs, 'a+') if logs else sys.stdout
|
||||
parser = argparse.ArgumentParser(description='Rigel, Text to Speech engine.')
|
||||
# parser.add_argument('--daemon', action='store_true',
|
||||
# help='Run Rigel in background')
|
||||
|
||||
pidlock = pidfile.PIDFile(pfile)
|
||||
parser.add_argument('--env',
|
||||
help='The env file to use.')
|
||||
|
||||
if action == "status":
|
||||
print("Running" if pidlock.is_running else "Not running.")
|
||||
elif action == "stop":
|
||||
if pidlock.is_running:
|
||||
print("Terminating...")
|
||||
f = open(pfile, "r")
|
||||
pid = int(f.read())
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
else:
|
||||
print("Not running.")
|
||||
elif action == "start":
|
||||
# parser.add_argument('--log-dir', type=argparse.FileType('r'),
|
||||
# help='The env file to use.')
|
||||
|
||||
with daemon.DaemonContext(stdout=logfile,
|
||||
stderr=logfile,
|
||||
pidfile=pidlock):
|
||||
# parser.add_argument('--pid', type=argparse.FileType('a'),
|
||||
# help='The pid file path to create')
|
||||
|
||||
main(config)
|
||||
args = parser.parse_args()
|
||||
#print(args.pid)
|
||||
|
||||
config = dotenv.dotenv_values(args.env)
|
||||
# action = sys.argv[2]
|
||||
# pfile = config.get("PID_FILE", "/var/run/rigel.pid")
|
||||
# logs = config.get("LOGFILE")
|
||||
# logfile = open(logs, 'a+') if logs else sys.stdout
|
||||
|
||||
# pidlock = pidfile.PIDFile(pfile)
|
||||
|
||||
# if action == "status":
|
||||
# print("Running" if pidlock.is_running else "Not running.")
|
||||
# elif action == "stop":
|
||||
# if pidlock.is_running:
|
||||
# print("Terminating...")
|
||||
# f = open(pfile, "r")
|
||||
# pid = int(f.read())
|
||||
# os.kill(pid, signal.SIGTERM)
|
||||
# else:
|
||||
# print("Not running.")
|
||||
# elif action == "start":
|
||||
|
||||
# with daemon.DaemonContext(stdout=logfile,
|
||||
# stderr=logfile,
|
||||
# pidfile=pidlock):
|
||||
|
||||
# main(config)
|
||||
main(config)
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
#!/sbin/openrc-run
|
||||
#
|
||||
# Orion Rigel --- Text to Speech engine
|
||||
#
|
||||
# Copyright (c) 2022 Sameer Rahmani <lxsameer@gnu.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 2 of the License.
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
# You should have received a copy of the GNU General Public License
|
||||
|
||||
command="<root-project>/.venv/bin/python"
|
||||
command_args="<root-project>/rigel/server.py --env <root-project>/.env"
|
||||
pidfile="/run/${RC_SVCNAME}.pid"
|
||||
command_background=true
|
||||
output_log="/var/log/${RC_SVCNAME}.log"
|
||||
error_log="/var/log/${RC_SVCNAME}.log"
|
Loading…
Reference in New Issue