You are not logged in.

#1 2012-11-27 09:39:56

wdirksen
Member
From: New Zealand
Registered: 2012-02-23
Posts: 105

Getting sasc-ng to work properly with systemd service files [SOLVED]

This thread is intended for getting the following AUR packages to work with each other with systemd service scripts:

https://aur.archlinux.org/packages/open-sasc-ng-dkms/
https://aur.archlinux.org/packages/open-sasc-ng/
https://aur.archlinux.org/packages/oscam-svn/   (this is a related package as it must properly execute prior to sasc-ng)

So my server is now on a fresh Arch install with systemd. All is well (& very fast) except I cannot get sasc-ng to function with systemd service init files. Prior to systemd the system worked fine with the rc initscripts & was very stable with the following setup:

rc.local

/etc/rc.d/oscam start
sleep 15
/etc/rc.d/sasc-ng start
sleep 4
/etc/rc.d/mythbackend start

/etc/conf.d/sasc-ng.conf

SASCNG_ARGS="-j 0:3 -j 1:4 -j 2:5" -b 16M --sid-allpid --sid-nocache --cam-budget"
DVBLOOPBACK_ARGS="num_adapters=3"
LOGDIR="/home/mythtv/logs/"
CAMDIR="/etc/camdir"

/etc/camdir/cardclient.conf

camd35:localhost:15050:1/0000/0000:mythtv:mythtv

I'll leave out the oscam stuff as that loads fine and doesn't appear to be a part of the problem

I've tried this with the systemd service file that comes with the open-sasc-ng-dkms package and when it was not sucessful I tried a bunch of variants including using "Type=simple" ect. "Type=Forked" seems to be only option that actually tries to start the processes. I also "hardcoded" the service files for the 2 sasc-ng components to find a few issues with the EnvironmentFile variables. The log variable has been removed for now as this seems to cause a fatal error but the rest of the variables load fine now. I also tested spliting up the DVB loopback module from the sasc-ng binary but this also gives similar results as the following script stands now. Running them manually with systemctl start commands doesn't make a difference but that is not surprising. The service file I'm fiddling with now which I feel has the best potential become working is:

sasc-ng.service

[Unit]
Description=Sasc-ng
After=oscam.service

[Service]
Type=forking
EnvironmentFile=/etc/conf.d/sasc-ng
ExecStartPre=/sbin/modprobe dvbloopback $DVBLOOPBACK_ARGS
TimeoutSec=2
ExecStart=/usr/sbin/sasc-ng -D $SASCNG_ARGS --cam-dir=$CAMDIR
TimeoutSec=4

[Install]
WantedBy=multi-user.target

Mythbackend always runs fine (even without DTV via sasc-ng) with the following mythbackend.service:

[Unit]
Description=MythTV_backend
After=sasc-ng.service

[Service]
Type=simple
Environment=MYTHCONFDIR=/etc/conf.d/mythbackend
Environment=HOME=/usr/share/mythtv
User=mythtv
ExecStart=/usr/bin/mythbackend --logpath /var/log/mythtv

[Install]
WantedBy=multi-user.target

oscam.service taken mostly from AUR package also seems fine. I added the TimeoutSec=15 to give time for oscam to load the SC and client protocol before moving on or else sasc-ng fails

Unit]
Description=An Open Source Conditional Access Module software
After=network.target

[Service]
Type=forking
EnvironmentFile=/etc/conf.d/oscam
ExecStart=/usr/bin/oscam $OSCAM_ARGS
TimeoutSec=15

[Install]
WantedBy=multi-user.target

Below is the output of the systemctl status commands. Despite the noise in the sasc-ng binary status, it is the loopback module that is " inactive (dead)" and there are no virtual DVB devices being created:

[mythtv@server ~]$ sudo systemctl status oscam.service
oscam.service - An Open Source Conditional Access Module software
	  Loaded: loaded (/usr/lib/systemd/system/oscam.service; enabled)
	  Active: active (running) since Tue, 2012-11-27 21:10:17 CET; 1min 7s ago
	 Process: 338 ExecStart=/usr/bin/oscam $OSCAM_ARGS (code=exited, status=0/SUCCESS)
	Main PID: 377 (oscam)
	  CGroup: name=systemd:/system/oscam.service
		  ├ 377 /usr/bin/oscam -b -c /etc/oscam
		  └ 378 /usr/bin/oscam -b -c /etc/oscam

Nov 27 21:10:17 server systemd[1]: Started An Open Source Conditional Acces...e.
[mythtv@server ~]$ sudo systemctl status loopback.service
loopback.service - Sasc-ng DVB Loopback Module
	  Loaded: loaded (/etc/systemd/system/loopback.service; enabled)
	  Active: inactive (dead) since Tue, 2012-11-27 21:10:28 CET; 1min 27s ago
	 Process: 907 ExecStart=/sbin/modprobe dvbloopback num_adapters=3 (code=exited, status=0/SUCCESS)
	  CGroup: name=systemd:/system/loopback.service

Nov 27 21:10:28 server systemd[1]: Started Sasc-ng DVB Loopback Module.
[mythtv@server ~]$ sudo systemctl status sasc-ng.service
sasc-ng.service - Sasc-ng
	  Loaded: loaded (/etc/systemd/system/sasc-ng.service; enabled)
	  Active: failed (Result: exit-code) since Tue, 2012-11-27 21:10:47 CET; 1min 45s ago
	 Process: 913 ExecStart=/usr/sbin/sasc-ng -D -j 0:3 -j 1:4 -j 2:5" -b 16M --sid-allpid --sid-nocache --cam-budget --cam-dir=/etc/camdir -l /home/mythtv/logs/sasc-ng.log (code=exited, status=0/SUCCESS)
	Main PID: 921 (code=exited, status=255)
	  CGroup: name=systemd:/system/sasc-ng.service

Nov 27 21:10:39 server sasc-ng[921]: [921] [general.error] failed open /etc...ry
Nov 27 21:10:40 server sasc-ng[921]: [921] [general.error] failed open /etc...ry
Nov 27 21:10:40 server sasc-ng[921]: [921] [general.error] failed open /etc...ry
Nov 27 21:10:40 server sasc-ng[921]: [921] [general.info] loading cardclien...nf
Nov 27 21:10:42 server sasc-ng[921]: [1062] Netwatcher thread started (pid=...6)
Nov 27 21:10:42 server sasc-ng[921]: [921] [general.error] no keys loaded f...m!
Nov 27 21:10:46 server sasc-ng[921]: [1098] SC housekeeper thread started (...2)
Nov 27 21:10:47 server sasc-ng[921]: [1062] Netwatcher thread ended (pid=92...6)
Nov 27 21:10:47 server systemd[1]: sasc-ng.service: main process exited, co.../a
Nov 27 21:10:47 server systemd[1]: Unit sasc-ng.service entered failed state
[mythtv@server ~]$ sudo systemctl status sasc-ng.service
sasc-ng.service - Sasc-ng
	  Loaded: loaded (/etc/systemd/system/sasc-ng.service; enabled)
	  Active: failed (Result: exit-code) since Tue, 2012-11-27 21:10:47 CET; 2min 9s ago
	 Process: 913 ExecStart=/usr/sbin/sasc-ng -D -j 0:3 -j 1:4 -j 2:5" -b 16M --sid-allpid --sid-nocache --cam-budget --cam-dir=/etc/camdir -l /home/mythtv/logs/sasc-ng.log (code=exited, status=0/SUCCESS)
	Main PID: 921 (code=exited, status=255)
	  CGroup: name=systemd:/system/sasc-ng.service

Nov 27 21:10:39 server sasc-ng[921]: [921] [general.error] failed open /etc/camdir/smartcard.conf: No such file or directory
Nov 27 21:10:40 server sasc-ng[921]: [921] [general.error] failed open /etc/camdir/cardslot.conf: No such file or directory
Nov 27 21:10:40 server sasc-ng[921]: [921] [general.error] failed open /etc/camdir/SoftCam.Key: No such file or directory
Nov 27 21:10:40 server sasc-ng[921]: [921] [general.info] loading cardclient config from /etc/camdir/cardclient.conf
Nov 27 21:10:42 server sasc-ng[921]: [1062] Netwatcher thread started (pid=921, tid=140074379712256)
Nov 27 21:10:42 server sasc-ng[921]: [921] [general.error] no keys loaded for softcam!
Nov 27 21:10:46 server sasc-ng[921]: [1098] SC housekeeper thread started (pid=921, tid=140074371319552)
Nov 27 21:10:47 server sasc-ng[921]: [1062] Netwatcher thread ended (pid=921, tid=140074379712256)
Nov 27 21:10:47 server systemd[1]: sasc-ng.service: main process exited, code=exited, status=255/n/a
Nov 27 21:10:47 server systemd[1]: Unit sasc-ng.service entered failed state
[mythtv@server ~]$ 

Any ideas?

Last edited by wdirksen (2012-12-10 19:54:43)


Research | Trial | Make Mistakes | Ask questions | Learn | Repeat

Offline

#2 2012-11-27 09:50:05

eworm
Package Maintainer (PM)
From: Oberhausen, Germany
Registered: 2010-01-30
Posts: 105
Website

Re: Getting sasc-ng to work properly with systemd service files [SOLVED]

Perhaps you should get complete and detailed information before crying in AUR comments...


ArchLinux - make it simple & lightweight

Offline

#3 2012-11-27 11:50:12

wdirksen
Member
From: New Zealand
Registered: 2012-02-23
Posts: 105

Re: Getting sasc-ng to work properly with systemd service files [SOLVED]

eworm wrote:

Perhaps you should get complete and detailed information before crying in AUR comments...

Eworm, yo peace man. I'm grateful for your contribution of a new dkms package for sasc-ng and the inclusion of a systemd service file. Your AUR package does work fine but I cannot get it to run with systemd service files. I purposely did not want to "cry" on the AUR so that is exactly why I left a single and very short one-liner link to this thread.

Would you, or your friend you build this package for, be willing to verify if your sasc-ng.service gets the loopback module loaded under systemd? I'm pretty sure if it's not loading for me there also will be others who will have problems using the sasc-ng.service as it stands now. That is also why I'm typing in a forum post right now and not in the comments in your AUR package.

Last edited by wdirksen (2012-11-28 15:46:16)


Research | Trial | Make Mistakes | Ask questions | Learn | Repeat

Offline

#4 2012-11-28 10:40:43

wdirksen
Member
From: New Zealand
Registered: 2012-02-23
Posts: 105

Re: Getting sasc-ng to work properly with systemd service files [SOLVED]

This may be obvious but for now one can still keep sasc-ng alive within systemd by using rc initscripts. If on a new install, install initscripts as it's no longer installed by default but still in the repo's for now.

Then use rc.local to load /etc/rc.d scripts like before. See above for example.
There must be a /etc/rc.conf present even if it's blank.

BTW: the /etc/rc.d/oscam package that comes with the current oscam-svn AUR package doesn't work for me. This one does work:

#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions
. /etc/conf.d/oscam

PID=$(pidof -o %PPID /usr/bin/oscam)

case $1 in
  start)
    stat_busy "Starting oscam"

    if [[ -z $PID ]] && /usr/bin/oscam $OSCAM_ARGS; then
        add_daemon oscam
        stat_done
    else
        stat_fail
        exit 1
    fi
    ;;
  stop)
    stat_busy "Stopping oscam"
    if [[ ! -z $PID ]]  && killall /usr/bin/oscam &> /dev/null; then
        rm_daemon oscam
        stat_done
    else
        stat_fail
        exit 1
    fi
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac

Last edited by wdirksen (2012-12-10 19:14:15)


Research | Trial | Make Mistakes | Ask questions | Learn | Repeat

Offline

#5 2012-12-10 19:51:43

wdirksen
Member
From: New Zealand
Registered: 2012-02-23
Posts: 105

Re: Getting sasc-ng to work properly with systemd service files [SOLVED]

After some head scratching it seems to be all good now. Considering there have been no replies to this I've come to wonder if I might be the only one with this issue. I could get it working somewhat using service files but never ideal, ex. sasc-ng only using a few of the entitlements from oscam because it started too quick etc. Anyway this might help a few and I'm hoping the linux savvy who find what I'm writing here painfully newbie like or flawed will reply and educate me a bit if what's provided here needs some sharpening up:

1) Systemd was confusing the sasc-ng binary shorthand arguments with Linux init arguments and a few were misinterpreted if they were not nested into the environment specifiers. So the -l (log) was causing problems and -b (buffer) wasn't loading. To be safe I'm using only the sasc-ng longhand specifiers from now on (two "--" and more verbose) so that they can never be confused even if safely nested in an environment parameter. That means that /etc/conf.d/sasc-ng will also need to be changed to reflect this. I also decided to simplify the LOGFILE parameter to include the whole argument syntax.

2) Oscam.service needs to be initiated with oneshot and RemainAfterExit=yes to make sure the delay (15 seconds in my config) gets counted out before sasc-ng initiates.

[EDIT 12/12/2012: Initially I had a second TimeoutSec=2 after ExecStart in sasc-ng.service but this had no function. Turns out that it almost always does work without this delay but not always with my setup. Adding TimeoutSec=2 to mythbackend.service prior to ExecStart command does function and makes things init more consistant]

sasc-ng.service

[Unit]
Description=Sasc-ng
After=oscam.service

[Service]
Type=simple
EnvironmentFile=/etc/conf.d/sasc-ng
ExecStartPre=/sbin/modprobe dvbloopback $DVBLOOPBACK_ARGS
TimeoutSec=2
ExecStart=/usr/sbin/sasc-ng $SASCNG_ARGS --cam-dir $CAMDIR --log $LOGFILE

[Install]
WantedBy=multi-user.target

/etc/conf.d/sasc-ng

SASCNG_ARGS="--join 0:3 --join 1:4 --join 2:5 --buffer 16M --sid-allpid --sid-nocache --cam-budget"
DVBLOOPBACK_ARGS="num_adapters=3"
LOGFILE="/home/mythtv/logs/sasc-ng.log"
CAMDIR="/etc/camdir"

oscam.service

[Unit]
Description=An Open Source Conditional Access Module software
After=network.target

[Service]
Type=oneshot
EnvironmentFile=/etc/conf.d/oscam
ExecStart=/usr/bin/oscam $OSCAM_ARGS
TimeoutSec=15
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

mythbackend.service

[Unit]
Description=MythTV_backend
After=sasc-ng.service

[Service]
Type=simple
TimeoutSec=2
Environment=MYTHCONFDIR=/etc/conf.d/mythbackend
Environment=HOME=/usr/share/mythtv
User=mythtv
ExecStart=/usr/bin/mythbackend --logpath /var/log/mythtv

[Install]
WantedBy=multi-user.target

I will make the related changes to the open-sasc-ng AUR package which I currently maintain

Last edited by wdirksen (2012-12-23 14:40:43)


Research | Trial | Make Mistakes | Ask questions | Learn | Repeat

Offline

#6 2012-12-12 09:07:29

Lusher
Member
Registered: 2012-12-06
Posts: 4

Re: Getting sasc-ng to work properly with systemd service files [SOLVED]

wdirksen wrote:

After some head scratching it seems to be all good now. Considering there have been no replies to this I've come to wonder if I might be the only one with this issue.

[...]

I will make the related changes to the open-sasc-ng AUR package which I currently maintain

I'd just like to thank you for the effort, and once I get mythtv and sasc to talk to each other I will look at your work for guidance. ;-)

Offline

#7 2013-04-12 15:46:47

wdirksen
Member
From: New Zealand
Registered: 2012-02-23
Posts: 105

Re: Getting sasc-ng to work properly with systemd service files [SOLVED]

Re-edit 27-03-2014. Sasc-ng is now ffdecsawrapper. This is a living update to help if someone comes here from a search. The settings provided here are rock solid now. All are now setup for running as daemons. . .

a consistant systemd launch setup for: oscam -> ffdecsawrapper -> mythbackend:

oscam.service (borrowed from oscam-svn AUR)

[Unit]
Description=OSCAM - Open Source Conditional Access Module
After=network.target

[Service]
Type=forking
User=root
Group=network
Nice=-4
PIDFile=/run/oscam.pid
ExecStart=/usr/bin/oscam -b -B /run/oscam.pid -c /etc/oscam

[Install]
WantedBy=multi-user.target

ffdecsawrapper.service

[Unit]
Description=FFdecsawrapper - FFdecsa Empowered Softcam
After=oscam.service 
Requires=oscam.service

[Service]
Type=forking
Nice=-10
User=root
Group=video
PIDFile=/run/ffdecsawrapper.pid
EnvironmentFile=/etc/conf.d/ffdecsawrapper
ExecStartPre=/usr/bin/modprobe dvbloopback $DVBLOOPBACK_ARGS
TimeoutSec=2
ExecStart=/usr/bin/ffdecsawrapper $FFDECSAWRAPPER_ARGS --daemon --pidfile /run/ffdecsawrapper.pid --cam-dir $CAMDIR --log $LOGFILE

[Install]
WantedBy=multi-user.target

mythbackend.service

[Unit]
Description=MythTV Backend
After=ffdecsawrapper.service
Requires=ffdecsawrapper.service mysqld.service

[Service]
Type=forking
User=root
Group=video
PIDFile=/run/mythbackend.pid
Environment=HOME=/usr/share/mythtv
Nice=-4
ExecStart=/usr/bin/mythbackend --daemon --pidfile /run/mythbackend.pid --logpath /home/server/logs/mythtv --loglevel emerg
StandardOutput=null

[Install]
WantedBy=multi-user.target

Still need to edit /etc/conf.d/mythbackend (this is no longer the case in ARCH, keeping for reference)

MBE_USER='root'

The mythbackend.service was made with reference to here:
http://www.mythtv.org/wiki/Systemd_myth … figuration
I don't need a mythbackend log so the "StandardOutput=null" is there. Comment this out if you want logging for mythbackend and change ExecStart to:

ExecStart=/usr/bin/mythbackend --logpath /your/log/pathway --loglevel crit

Last edited by wdirksen (2014-03-27 08:07:17)


Research | Trial | Make Mistakes | Ask questions | Learn | Repeat

Offline

Board footer

Powered by FluxBB