Skip to content

Manage one or more Kodi headless docker instances #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions kodi-headless.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
INSTANCES="default"
KODI_USER="xbmc"
KODI_PASSWORD="xbmc"
174 changes: 174 additions & 0 deletions kodi-headless.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#!/bin/bash
#
# Kodi Headless
#
# Control one or more Kodi Headless docker instances.
#
# The MIT License (MIT)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

source $(dirname $0)/kodi-headless.conf

function usage()
{
cat <<EOF
usage: $(basename $0) list | run|start|stop|kill|rm|update|clean [container] | shell <container>

list : show list of created containers
* : * all or one container
shell : start shell into container. Kodi userdata in:
/opt/kodi-server/share/kodi/portable_data/userdata/

update : update database with new episodes/movies
clean : cleanup database by removing non-existant episodes/movies
version: API version

run = create
rm = remove

Script to create, start, stop list multiple Kodi docker instances. Comes
in handy in multi-profile environments where each user has its own Kodi
database which needs to be updated. Allows sending database clean/update
signal to each Kodi docker instance. Comes in handy also when just using
one Kodi docker instance. Add instances to 'kodi-homes' by creating new
directories and copy the default xbmcdata/userdata directory in it. For
exampe see kodi-homes/default. Add instance to kodi-headless.conf. Manage
the instances using kodi-headless.sh. Require docker and curl.

Example usage:

1) ./kodi-headless.sh run default - Create and start docker container for
default instance.
2) ./kodi-headless.sh list - List all docker container instances and
check up status of each Kodi headless instance running in the container
3) ./kodi-headless.sh stop - Stop *ALL* docker container instances

EOF
exit 1
}

function dcr()
{
local action=${1}
local container=${2}
local list=
local dir=$(readlink -f $(dirname $0))

if [ -n "${container}" ]
then
list=${container}
else
list=${INSTANCES}
fi

for instance in ${list}
do
case ${action} in
run) docker run -d \
--name ${instance} \
--net=host \
--privileged \
-v ${dir}/kodi-homes/${instance}:/opt/kodi-server/share/kodi/portable_data \
wernerb/docker-xbmc-server;;
*) docker ${action} ${instance} ;;
esac
done
}

function shell()
{
local container=${1}

if [ -z ${container} ]
then
usage
fi

docker exec -it ${container} /bin/bash
}

function list()
{
local dir=$(readlink -f $(dirname $0))

for instance in ${INSTANCES}
do
port=$(grep webserverport ${dir}/kodi-homes/${instance}/userdata/advancedsettings.xml | sed 's/[^0-9]//g')
rpc version ${instance} 2>/dev/null| grep -q '{"version":'
if [ $? -eq 0 ]
then
up="yes"
else
up="no"
fi
echo "${instance}> up: ${up}, URL: http://$(hostname -f):${port}/"
done

echo

docker ps -a
}

function rpc()
{
local action=${1}
local container=${2}
local list=
local dir=$(readlink -f $(dirname $0))

if [ -n "${container}" ]
then
list=${container}
else
list=${INSTANCES}
fi

method=
case ${action} in
update) method="VideoLibrary.Scan";;
clean) method="VideoLibrary.Clean";;
version) method="JSONRPC.Version";;
*) usage;;
esac

for instance in ${list}
do
echo -n "${instance}: "
port=$(grep webserverport ${dir}/kodi-homes/${instance}/userdata/advancedsettings.xml | sed 's/[^0-9]//g')
url="http://$(hostname -f):${port}/jsonrpc"

curl --user "${KODI_USER}:${KODI_PASSWORD}" \
--header 'Content-Type: application/json' \
--data-binary '{"jsonrpc":"2.0","method":"'${method}'","id":"1"}' ${url}

echo
done
}

action=${1}
container=${2}
case ${action} in
list) list;;
run|start|stop|kill|rm) dcr ${action} ${container};;
update|clean|version) rpc ${action} ${container};;
shell) shell ${container};;
*) usage;;
esac

80 changes: 80 additions & 0 deletions kodi-homes/default/userdata/advancedsettings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<advancedsettings>
<videolibrary>
<actorthumbs>false</actorthumbs>
<importwatchedstate>true</importwatchedstate>
<dateadded>0</dateadded>
<backgroundupdate>true</backgroundupdate>
<updateonstartup>true</updateonstartup>
</videolibrary>
<musiclibrary>
<backgroundupdate>true</backgroundupdate>
</musiclibrary>
<videodatabase>
<type>mysql</type>
<host>192.168.1.50</host>
<port>3306</port>
<user>xbmc</user>
<pass>xbmc</pass>
</videodatabase>
<musicdatabase>
<type>mysql</type>
<host>192.168.1.50</host>
<port>3306</port>
<user>xbmc</user>
<pass>xbmc</pass>
</musicdatabase>
<videoscanner>
<ignoreerrors>true</ignoreerrors> <!-- Set to true to silently ignore errors while scanning videos. This prevents the error dialogue box, so you don't have to keep hitting "yes" to keep scanning.-->
</videoscanner>
<splash>false</splash>
<bginfoloadermaxthreads>2</bginfoloadermaxthreads>
<myvideos>
<extractflags>false</extractflags>
<extractthumb>false</extractthumb>
</myvideos>
<lookandfeel>
<enablerssfeeds>false</enablerssfeeds>
</lookandfeel>
<audiooutput>
<guisoundmode>0</guisoundmode>
<ac3passthrough>false</ac3passthrough>
<dtspassthrough>false</dtspassthrough>
<multichannellpcm>false</multichannellpcm>
<truehdpassthrough>false></truehdpassthrough>
<dtshdpassthrough>false</dtshdpassthrough>
<mode>2</mode>
</audiooutput>
<videoscreen>
<vsync>2</vsync>
</videoscreen>
<input>
<enablemouse>false</enablemouse>
<remoteaskeyboard>false</remoteaskeyboard>
</input>
<general>
<addonnotifications>false</addonnotifications>
</general>
<services>
<devicename>XBMC Server</devicename>
<esallinterfaces>false</esallinterfaces>
<escontinuousdelay>25</escontinuousdelay>
<esenabled>true</esenabled>
<esinitialdelay>750</esinitialdelay>
<esmaxclients>20</esmaxclients>
<esport>9777</esport>
<esportrange>10</esportrange>
<upnpannounce>true</upnpannounce>
<upnprenderer>false</upnprenderer>
<upnpserver>true</upnpserver>
<webserver>true</webserver>
<webserverpassword>xbmc</webserverpassword>
<webserverport>8089</webserverport>
<webserverusername>xbmc</webserverusername>
<webskin>webinterface.default</webskin>
<zeroconf>true</zeroconf>
</services>
<skinsettings>
<setting type="bool" name="skin.confluence.FirstTimeRun">false</setting>
</skinsettings>

</advancedsettings>