boblightd: convert to systemd service

This commit is contained in:
Stefan Saraev 2013-12-20 16:58:17 +02:00
parent 3ded391359
commit f6e5057df0
7 changed files with 33 additions and 128 deletions

View File

@ -35,7 +35,7 @@ mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/bin
fi
mkdir -p $ADDON_BUILD/$PKG_ADDON_ID/config
cp -R $PKG_DIR/config/boblight.conf.sample $ADDON_BUILD/$PKG_ADDON_ID/config
cp -R $PKG_DIR/config/boblight.conf $ADDON_BUILD/$PKG_ADDON_ID/config
if [ "$DISPLAYSERVER" = "xorg-server" ] ; then
cp -R $PKG_DIR/config/boblight.X11.sample $ADDON_BUILD/$PKG_ADDON_ID/config
fi

View File

@ -29,52 +29,15 @@ ADDON_HOME="$HOME/.xbmc/userdata/addon_data/service.multimedia.boblightd"
mkdir -p $ADDON_HOME
LOG_FILE="$ADDON_HOME/service.log"
chmod a+x $ADDON_DIR/bin/*
# Boblight config file created by user
BOBLIGHT_CONFIG="$ADDON_HOME/boblight.conf"
# Flag file to start boblight-x11 daemon
BOBLIGHT_X11="$ADDON_HOME/boblight.X11"
LOCKDIR="/var/lock/"
LOCKFILE="boblightd.disabled"
LOCKFILE_SLEEP="boblightd.sleep"
export LD_LIBRARY_PATH="$ADDON_DIR/lib:$LD_LIBRARY_PATH"
cp -R $ADDON_DIR/config/*.sample $ADDON_HOME > $LOG_FILE 2>&1
rm -rf "$LOCKDIR/$LOCKFILE_SLEEP" &>/dev/null
boblightd.stop
rm -rf "$LOCKDIR/$LOCKFILE" &>/dev/null
if [ -f "$BOBLIGHT_CONFIG" ] ; then
if [ ! "$(pidof boblightd)" ]; then
while [ true ] ; do
while [ -f "$LOCKDIR/$LOCKFILE_SLEEP" ] ; do
usleep 100000
done
if [ -f "$LOCKDIR/$LOCKFILE" ] ; then
break
fi
# Start the boblight daemon
boblightd -c $BOBLIGHT_CONFIG >> $LOG_FILE 2>&1
done &
fi
if [ -e $BOBLIGHT_X11 ]; then
if [ ! "$(pidof boblight-X11)" ]; then
while [ true ] ; do
while [ -f "$LOCKDIR/$LOCKFILE_SLEEP" ] ; do
usleep 100000
done
if [ -f "$LOCKDIR/$LOCKFILE" ] ; then
break
fi
# Start the boblight daemon
boblight-X11 >> $LOG_FILE 2>&1
done &
fi
fi
cp $ADDON_DIR/config/*.sample $ADDON_HOME
if [ ! -f $ADDON_HOME/boblight.conf ] ; then
cp $ADDON_DIR/config/boblight.conf $ADDON_HOME/boblight.conf
fi
if [ -x $ADDON_DIR/bin/boblight-X11 -a -e $ADDON_HOME/boblight.X11 ] ; then
boblight-X11 -f >/dev/null 2>&1
fi
exec boblightd -c $ADDON_HOME/boblight.conf > $ADDON_HOME/service.log 2>&1

View File

@ -1,45 +0,0 @@
#!/bin/sh
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv)
#
# 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, or (at your option)
# any later version.
#
# 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
# along with OpenELEC.tv; see the file COPYING. If not, write to
# the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
# http://www.gnu.org/copyleft/gpl.html
################################################################################
. /etc/profile
LOCKDIR="/var/lock/"
LOCKFILE="boblightd.disabled"
LOCKFILE_SLEEP="boblightd.sleep"
mkdir -p "$LOCKDIR"
if [ ! -e "$LOCKDIR/$LOCKFILE_SLEEP" ] ; then
touch "$LOCKDIR/$LOCKFILE"
fi
if [ "$(pidof boblightd)" ] ; then
killall -q boblightd
killall -q boblight-X11
for seq in `seq 1 10` ; do
if [ ! "$(pidof boblightd boblight-X11)" ] ; then
break
fi
usleep 200000
done
killall -q -9 boblightd
killall -q -9 boblight-X11
fi

View File

@ -17,27 +17,3 @@
# the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
# http://www.gnu.org/copyleft/gpl.html
################################################################################
import os
import sys
import xbmcaddon
import time
import subprocess
__scriptname__ = "Boblightd"
__author__ = "OpenELEC"
__url__ = "http://www.openelec.tv"
__settings__ = xbmcaddon.Addon(id='service.multimedia.boblightd')
__cwd__ = __settings__.getAddonInfo('path')
__start__ = xbmc.translatePath( os.path.join( __cwd__, 'bin', "boblightd.start") )
__stop__ = xbmc.translatePath( os.path.join( __cwd__, 'bin', "boblightd.stop") )
#make binary files executable in adson 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)

View File

@ -22,20 +22,17 @@
. /etc/profile
LOCKFILE_SLEEP="/var/lock/boblightd.sleep"
SERVICE="service.multimedia.boblightd.service"
case "$1" in
hibernate|suspend|pre)
progress "Shutting down boblightd for suspending..."
touch $LOCKFILE_SLEEP
boblightd.stop
;;
thaw|resume|post)
if [ -f "$LOCKFILE_SLEEP" ] ; then
progress "Restarting boblightd for wakeup..."
rm -rf "$LOCKFILE_SLEEP"
pre)
if systemctl is-active "$SERVICE" &>/dev/null ; then
systemctl stop "$SERVICE"
fi
;;
*) exit $NA
post)
if systemctl is-enabled "$SERVICE" &>/dev/null ; then
systemctl start "$SERVICE"
fi
;;
esac

View File

@ -0,0 +1,14 @@
[Unit]
Description=boblightd
After=graphical.target
[Service]
ExecStart=/bin/sh -c "exec sh /storage/.xbmc/addons/service.multimedia.boblightd/bin/boblightd.start"
ExecStopPost=-/bin/sh -c "pidof boblight-X11 && killall -q -9 boblight-X11"
TimeoutStopSec=1
Restart=always
RestartSec=10
StartLimitInterval=0
[Install]
WantedBy=xbmc.target