2012-05-18, 07:48
Hello.
I developed service addon for openelec. From this addon I wan't to start deluge daemon, deluge web server and flexget webserver.
All this daemons starts from EASY-INSTALL-ENTRY-SCRIPT like this:
deluged:
Here is my addon script.
flexluge.start:
My addon's default.py:
What problem I have: then I start flexluge.start from console everything is working perfectly, but then I start this addon from XBMC, firstly starts deluged ( I saw it in ps output), then deluged stops, then starts deluge-web, and stops too. Last starts flexget-webui, and stops. What I have in the end - working flexluge.start in background.
What am I doing wrong?
I developed service addon for openelec. From this addon I wan't to start deluge daemon, deluge web server and flexget webserver.
All this daemons starts from EASY-INSTALL-ENTRY-SCRIPT like this:
deluged:
Code:
#!/usr/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'deluge==1.3.5','console_scripts','deluged'
__requires__ = 'deluge==1.3.5'
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
load_entry_point('deluge==1.3.5', 'console_scripts', 'deluged')()
)
Here is my addon script.
flexluge.start:
Code:
#~~~~~~~ VARIABLES ~~~~~~~
### directories ###
ADDON_DIR="$HOME/.xbmc/addons/service.downloadmanager.flexluge"
ADDON_HOME="$HOME/.xbmc/userdata/addon_data/service.downloadmanager.flexluge"
DELUGE_CONFIG_DIR="$HOME/.config/deluge"
FLEXGET_CONFIG_DIR="$HOME/.config/flexget"
LOCKDIR="/var/lock/"
### files ###
ADDON_SETTINGS="$ADDON_HOME/settings.xml"
DEL_CORE_SETS="$DELUGE_CONFIG_DIR/core.conf"
DEL_CORE_SETS_TEMP="/var/config/core.conf.temp"
DEL_WEB_SETS="$DELUGE_CONFIG_DIR/web.conf"
DEL_WEB_SETS_TEMP="/var/config/web.conf.temp"
DEL_CORE_LOG="/var/log/deluge-core.log"
DEL_WEB_LOG="/var/log/deluge-webui.log"
FLEXGET_LOG="/var/log/flexget.log"
AUTH_FILE="$DELUGE_CONFIG_DIR/auth"
AUTH_FILE_TEMP="/var/config/deluge.auth"
LOCKFILE="flexluge.disabled"
#~~~~~~~ INITIALIZE ENVIRONMENT ~~~~~~~
mkdir -p $FLEXGET_CONFIG_DIR
mkdir -p $DELUGE_CONFIG_DIR
mkdir -p $ADDON_HOME
touch $FLEXGET_CONFIG_DIR/config.yml
if [ ! -f "$DEL_CORE_SETS" ]; then
cp $ADDON_DIR/core.conf.default $DEL_CORE_SETS
fi
if [ ! -f "$DEL_WEB_SETS" ]; then
cp $ADDON_DIR/web.conf.default $DEL_WEB_SETS
fi
if [ ! -f "$ADDON_SETTINGS" ]; then
cp $ADDON_DIR/settings.xml $ADDON_SETTINGS
fi
if [ ! -f "$AUTH_FILE" ]; then
cp $ADDON_DIR/auth $AUTH_FILE
fi
#~~~~~~~ PARSING SETTINGS ~~~~~~~
mkdir -p /var/config
cat "$ADDON_DIR/settings.xml" | awk -F\" '{print $2"=\""$4"\""}' | sed '/^=/d' > /var/config/flexluge.conf.default
cat "$ADDON_SETTINGS" | awk -F\" '{print $2"=\""$4"\""}' | sed '/^=/d' > /var/config/flexluge.conf
. /var/config/flexluge.conf.default
. /var/config/flexluge.conf
#~~~~~~~ SAVING SETTINGS ~~~~~~~
### Authorization ###
AUTH_OLD=`grep -v localclient $AUTH_FILE`
if [ ! "$AUTH_OLD" = "$DELUGE_USER:$DELUGE_PASS:10" ]; then
sed -i "s|"$AUTH_OLD"|"$DELUGE_USER:$DELUGE_PASS:10"|g" $AUTH_FILE
fi
### Deluge main settings ###
while [ true ]; do
if [ ! -f "$ADDON_SETTINGS".check ]; then
cp "$ADDON_SETTINGS" "$ADDON_SETTINGS".check
cp $DEL_WEB_SETS $DEL_WEB_SETS_TEMP
cp $DEL_CORE_SETS $DEL_CORE_SETS_TEMP
sed -i "s|.*port.*| \"port\"\: $DEL_WEBUI_PORT,|g" $DEL_WEB_SETS_TEMP
sed -i "s|.*allow_remote.*| \"allow_remote\": "$DEL_ALLOW_REMOTE",|g" $DEL_CORE_SETS_TEMP
sed -i "s|.*daemon_port.*| \"daemon_port\": "$DEL_DAEMON_PORT",|g" $DEL_CORE_SETS_TEMP
if [ "$DEL_SPEED_LIMIT" = "true" ]; then
sed -i "s|.*max_download_speed.*| \"max_download_speed\": "$DEL_MAX_DL_SPEED",|g" $DEL_CORE_SETS_TEMP
sed -i "s|.*max_upload_speed.*| \"max_upload_speed\": "$DEL_MAX_UL_SPEED",|g" $DEL_CORE_SETS_TEMP
else
sed -i "s|.*max_download_speed.*| \"max_download_speed\": -1.0,|g" $DEL_CORE_SETS_TEMP
sed -i "s|.*max_upload_speed.*| \"max_upload_speed\": -1.0,|g" $DEL_CORE_SETS_TEMP
fi
sed -i "s|.*max_active_limit.*| \"max_active_limit\": "$DEL_MAX_ACTIVE",|g" $DEL_CORE_SETS_TEMP
sed -i "s|.*max_active_downloading.*| \"max_active_downloading\": "$DEL_MAX_DOWNL",|g" $DEL_CORE_SETS_TEMP
sed -i "s|.*max_active_seeding.*| \"max_active_seeding\": "$DEL_MAX_UPL",|g" $DEL_CORE_SETS_TEMP
sed -i "s|.*max_connections_global.*| \"max_connections_global\": "$DEL_MAX_CON",|g" $DEL_CORE_SETS_TEMP
sed -i "s|.*dht.*| \"dht\": "$DHT",|g" $DEL_CORE_SETS_TEMP
sed -i "s|.*dont_count_slow_torrents.*| \"dont_count_slow_torrents\": "$DONT_COUNT_SLOW",|g" $DEL_CORE_SETS_TEMP
sed -i "s|.*prioritize_first_last_pieces.*| \"prioritize_first_last_pieces\": "$FIRST_PIECE_PRIOR",|g" $DEL_CORE_SETS_TEMP
sed -i "s|.*download_location.*| \"download_location\": \"$DEL_DL_LOC\",|g" $DEL_CORE_SETS_TEMP
if [ "$DELUGE_MOVEDONE" = "true" ]; then
sed -i "s|.*move_completed_path.*| \"move_completed_path\": "$DELUGE_MOVEDONE_LOC",|g" $DEL_CORE_SETS_TEMP
sed -i "s|.*move_completed.*| \"move_completed\": true,|g" $DEL_CORE_SETS_TEMP
else
sed -i "s|.*move_completed.*| \"move_completed\": false,|g" $DEL_CORE_SETS_TEMP
fi
if [ "$DELUGE_AUTOADD" = "true" ]; then
sed -i "s|.*autoadd_location.*| \"autoadd_location\": \"$DELUGE_AUTOADD_LOC\",|g" $DEL_CORE_SETS_TEMP
sed -i "s|.*autoadd_enable.*| \"autoadd_enable\": true,|g" $DEL_CORE_SETS_TEMP
mkdir -p $DELUGE_AUTOADD_LOC
else
sed -i "s|.*autoadd_enable.*| \"autoadd_enable\": false,|g" $DEL_CORE_SETS_TEMP
fi
mv $DEL_CORE_SETS_TEMP $DEL_CORE_SETS
mv $DEL_WEB_SETS_TEMP $DEL_WEB_SETS
else
if grep -vqf "$ADDON_SETTINGS".check "$ADDON_SETTINGS"; then
rm "$ADDON_SETTINGS".check
else
break
fi
fi
done
DEL_CORE_ARG="-c$DELUGE_CONFIG_DIR"
DEL_WEB_ARG="--fork -c$DELUGE_CONFIG_DIR"
FLEXGET_ARG="-d -c $FLEXGET_CONFIG_DIR/config.yml --port=$FLEXGET_WEBUI_PORT"
if [ "$DEL_LOG" = "true" ]; then
DEL_CORE_ARG="$DEL_CORE_ARG -l$DEL_CORE_LOG -L$DEL_LOG_LEVEL"
DEL_WEB_ARG="$DEL_WEB_ARG -l$DEL_WEB_LOG -L$DEL_LOG_LEVEL"
FLEXGET_ARG="$FLEXGET_ARG --logfile=$FLEXGET_LOG"
fi
if [ "$FLEXGET_AUTH" = "true" ]; then
FLEXGET_ARG="$FLEXGET_ARG --username=$FLEXGET_USER --password=$FLEXGET_PASS"
else
FLEXGET_ARG="$FLEXGET_ARG --no-auth"
fi
#~~~~~~~ STARTING DAEMON ~~~~~~~
if [ -f "$LOCKDIR/$LOCKFILE" ] ; then
rm -rf "$LOCKDIR/$LOCKFILE"
fi
export PYTHONPATH="$ADDON_DIR/lib/:$PYTHONPATH"
export LD_LIBRARY_PATH="$ADDON_DIR/lib:$LD_LIBRARY_PATH"
if [ ! "$(pidof deluged)" ];then
eval deluged $DEL_CORE_ARG
fi
if [ ! "$(pidof deluge-web)" ];then
eval deluge-web $DEL_WEB_ARG
fi
if [ ! "$(pidof flexget-webui)" ];then
rm $FLEXGET_CONFIG_DIR/.config-lock
eval flexget-webui $FLEXGET_ARG
fi
while [ true ]; do
if [ -f "$LOCKDIR/$LOCKFILE" ] ; then
break
fi
sleep 1
done &
### Clean trash ###
rm /var/config/flexluge.conf.default
rm /var/config/flexluge.conf
My addon's default.py:
Code:
import os
import sys
import xbmcaddon
import time
import subprocess
__scriptname__ = "FlexLuge"
__author__ = "dakhar"
__url__ = ""
__settings__ = xbmcaddon.Addon(id='service.downloadmanager.flexluge')
__cwd__ = __settings__.getAddonInfo('path')
__start__ = xbmc.translatePath( os.path.join( __cwd__, 'bin', "flexluge.start") )
__stop__ = xbmc.translatePath( os.path.join( __cwd__, 'bin', "flexluge.stop") )
#make binary files executable in addon bin folder
subprocess.Popen("chmod -R +x " + __cwd__ + "/bin/*" , shell=True, close_fds=True)
subprocess.Popen(__start__, shell=True, close_fds=True)
while (not xbmc.abortRequested):
time.sleep(0.250)
subprocess.Popen(__stop__, shell=True, close_fds=True)
What problem I have: then I start flexluge.start from console everything is working perfectly, but then I start this addon from XBMC, firstly starts deluged ( I saw it in ps output), then deluged stops, then starts deluge-web, and stops too. Last starts flexget-webui, and stops. What I have in the end - working flexluge.start in background.
What am I doing wrong?