Revision a9f959b7
Added by David Sorber over 7 years ago
| software/hbkcd/conf/systemd/hbkcd.service | ||
|---|---|---|
|
[Unit]
|
||
|
Description=HandBrake Control Daemon service
|
||
|
After=syslog.target
|
||
|
|
||
|
[Service]
|
||
|
Type=simple
|
||
|
User=dsorber
|
||
|
Group=dsorber
|
||
|
#WorkingDirectory=/home/node/Node/
|
||
|
ExecStart=/usr/local/bin/hbkcd
|
||
|
StandardOutput=syslog
|
||
|
StandardError=syslog
|
||
|
|
||
|
[Install]
|
||
|
WantedBy=multi-user.target
|
||
| software/hbkcd/hbkcd.service | ||
|---|---|---|
|
[Unit]
|
||
|
Description=HandBrake Control Daemon service
|
||
|
After=syslog.target
|
||
|
|
||
|
[Service]
|
||
|
Type=simple
|
||
|
User=dsorber
|
||
|
Group=dsorber
|
||
|
#WorkingDirectory=/home/node/Node/
|
||
|
ExecStart=/usr/local/bin/hbkcd
|
||
|
StandardOutput=syslog
|
||
|
StandardError=syslog
|
||
|
|
||
|
[Install]
|
||
|
WantedBy=multi-user.target
|
||
| software/hbkcd/hbkcd/command_server.py | ||
|---|---|---|
|
try:
|
||
|
content_length = int(self.headers['Content-Length'])
|
||
|
raw_content = self.rfile.read(content_length)
|
||
|
# ~ print(type(raw_content))
|
||
|
# ~ print(raw_content)
|
||
|
content = json.loads(raw_content)
|
||
|
|
||
|
# Default to invalid command
|
||
| software/hbkcd/hbkcd/daemon.py | ||
|---|---|---|
|
|
||
|
return True
|
||
|
|
||
|
def datetime_diff(dt_start, dt_end):
|
||
|
""" Helper function to calculate the elapsed time between to datetime
|
||
|
objects and return in a readable "HH::MM:SS" string format.
|
||
|
"""
|
||
|
elapsed = dt_end - dt_sart
|
||
|
hours, remainder = divmod(elapsed.total_seconds(), 3600)
|
||
|
minutes, seconds = divmod(remainder, 60)
|
||
|
elapsed_str = '{:02}:{:02}:{:02}'
|
||
|
elapsed_str = elapsed_str.format(int(hours), int(minutes),
|
||
|
int(seconds))
|
||
|
return elapsed_str
|
||
|
|
||
|
|
||
|
def main():
|
||
|
|
||
| ... | ... | |
|
log_file.write(hbk_proc.stderr.read())
|
||
|
logging.info('Write encode log file: {:s}'.format(log_path))
|
||
|
|
||
|
# Calculate elapsed time
|
||
|
elapsed = item.encode_finished - item.encode_started
|
||
|
hours, remainder = divmod(elapsed.total_seconds(), 3600)
|
||
|
minutes, seconds = divmod(remainder, 60)
|
||
|
elapsed_str = '{:02}:{:02}:{:02}'
|
||
|
elapsed_str = elapsed_str.format(int(hours), int(minutes),
|
||
|
int(seconds))
|
||
|
# Calculate elapsed time of encode
|
||
|
elapsed_str = datetime_diff(item.encode_finished, item.encode_started)
|
||
|
|
||
|
# Calculated queued time
|
||
|
queued_str = datetime_diff(item.encode_finished, item.time_added)
|
||
|
|
||
|
# Print success or failure message to the log depending on the
|
||
|
# HandBrake process's return code
|
||
|
if hbk_proc.returncode == 0:
|
||
|
logging.info('Encode of {:s} completed in {:s}'.format(item.path,
|
||
|
elapsed_str))
|
||
|
fmt_str = 'Encode of {:s} completed in {:s} (queued for: {:s})'
|
||
|
logging.info(fmt_str.format(item.path, elapsed_str, queued_str))
|
||
|
else:
|
||
|
logging.error('Error while encoding {:s}'.format(item.path))
|
||
|
fmt_str = 'Error while encoding {:s} (queued for: {:s})'
|
||
|
logging.error(fmt_str.format(item.path, queued_str))
|
||
|
|
||
|
# Remove the item from the queue
|
||
|
ENCODE_QUEUE.remove(0)
|
||
| software/hbkcd/install.sh | ||
|---|---|---|
|
#!/bin/bash
|
||
|
|
||
|
echo -e "hbkcd Install Script\n"
|
||
|
|
||
|
if [[ $EUID -ne 0 ]]; then
|
||
|
echo "ERROR: This script must be run as root"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# TODO: check and install prereqs if needed
|
||
|
|
||
|
# Install systemd config
|
||
|
cp conf/systemd/hbkcd.service /etc/systemd/system/
|
||
|
systemctl daemon-reload
|
||
|
|
||
|
# Install hbkcd Python module
|
||
|
./setup.py install
|
||
|
|
||
|
# Install scripts
|
||
|
install -m 755 scripts/hbkcd_add.sh /usr/local/bin/hbkcd_add
|
||
|
install -m 755 scripts/hbkcd_queue.sh /usr/local/bin/hbkcd_queue
|
||
|
install -m 755 scripts/hbkcd_remove.sh /usr/local/bin/hbkcd_remove
|
||
|
|
||
|
# Start or restart hbckd
|
||
|
systemctl status hbkcd
|
||
|
result="$?"
|
||
|
if [ "$result" -ne 0 ]; then
|
||
|
echo "Starting hbkcd"
|
||
|
systemctl start hbkcd
|
||
|
else
|
||
|
echo "Restarting hbkcd"
|
||
|
systemctl restart hbkcd
|
||
|
fi
|
||
|
|
||
|
echo -e "\n[complete]\n"
|
||
| software/hbkcd/scripts/hbkcd_add.sh | ||
|---|---|---|
|
command -v curl >/dev/null 2>&1 || { echo >&2 "Please install curl to use this script. Aborting."; exit 1; }
|
||
|
command -v jq >/dev/null 2>&1 || { echo >&2 "Please install jq to use this script. Aborting."; exit 1; }
|
||
|
|
||
|
INPUT_PATH=$(readlink -f $1)
|
||
|
curl -s -X POST -d '{"type": "add", "path": "'$INPUT_PATH'", "output": "'$2'"}' http://$ADDRESS:$PORT/command | jq
|
||
|
INPUT_PATH=$(readlink -f "$1")
|
||
|
#~ echo '{"type": "add", "path": "'"$INPUT_PATH"'", "output": "'"$2"'"}'
|
||
|
|
||
|
curl -s -d '{"type": "add", "path": "'"$INPUT_PATH"'", "output": "'"$2"'"}' -X POST http://$ADDRESS:$PORT/command | jq
|
||
| software/hbkcd/setup.py | ||
|---|---|---|
|
|
||
|
setup(
|
||
|
name = 'hbkcd',
|
||
|
version = '0.1.1',
|
||
|
version = '0.1.2',
|
||
|
description = 'HandBrake Control Daemon',
|
||
|
packages = find_packages(),
|
||
|
python_requires = '>=3.6.0',
|
||
Fixed bug in hbkcd_add.sh script that prevented adding paths with
spaces. Added item queued time to log. Created simple install script.
Version 0.1.2.