Help needed to daemonize CouchPotato

Hi all,

I am trying to run CouchPotato as a daemon at startup on my openSuSE 12.2 box.

I have put together this script based on what works for sabnzbd and sickbeard, put it in /etc/init.d/couchpotato, chmod 755 and calling it using “/etc/init.d/couchpotato start”

#!/bin/sh
#
### BEGIN INIT INFO
# Provides:             couchpotato
# Required-Start:       $network
# Default-Start:        3 5
# Default-Stop:         0 1 2 6
# Description:          Starts Couch Potato at system startup
### END INIT INFO
#
. /etc/rc.status
rc_reset

case "$1" in
start)
  echo "Starting Couch Potato."
  /usr/bin/sudo -u user -H "/home/user/CouchPotato-ff2b275/CouchPotato.py"
  rc_status -v
;;
stop)
  echo "Shutting down Couch Potato."
  /usr/bin/env wget -q --delete-after "http://localhost:5000/config/exit/"
  rc_status -v
;;
*)
  echo "Usage: $0 {start|stop}"
  exit 1
esac

exit 0

And this is the error I am getting when trying to launch it

downloader:~ # /etc/init.d/couchpotato start
redirecting to systemctl
Job failed. See system journal and 'systemctl status' for details.

System journal has this to say:

Sep 29 11:18:12 downloader[2433]: Failed at step EXEC spawning /etc/init.d/couchpotato: Exec format error
Sep 29 11:18:12 downloader systemd[1]: couchpotato.service: control process exited, code=exited status=203
Sep 29 11:18:12 downloader systemd[1]: Unit couchpotato.service entered failed state.

Any thoughts?

Hi
Use systemd :wink:

Use the file below (you need to be root), save in /lib/systemd/system/
as couchpotato.service you need to change the ‘user’ to your username.


# /lib/systemd/system/couchpotato.service
#

[Unit]
Description=Starts Couch Potato at system startup.

[Service]
Type=simple
User=user
ExecStart=/bin/sh -c "/home/user/CouchPotato-ff2b275/CouchPotato.py"
ExecStop=/bin/sh -c "/usr/bin/wget -q --delete-after \"http://localhost:5000/config/exit/\""
KillSignal=SIGHUP

[Install]
WantedBy=multi-user.target

Now run;


systemctl --system daemon-reload
systemctl enable couchpotato.service
systemctl start couchpotato.service
systemctl status couchpotato.service
systemctl stop couchpotato.service
systemctl status couchpotato.service

If it all starts/stops, restart and your good to go.


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 12.2 (x86_64) Kernel 3.4.6-2.10-desktop
up 4 days 2:15, 5 users, load average: 0.10, 0.09, 0.10
CPU Intel i5 CPU M520@2.40GHz | Intel Arrandale GPU

Works perfectly, thanks a lot!

Can I convert sabnzbd and sickbeard that I was launching using a script in /etc/init.d to systemd? Should I use the example above as a framework and replace paths accordingly?
systemd seems to be more suited to daemonizing programs.

Hi
You should be able to use it as an example, there are many more
options/ways with systemd. If they work, consider pushing them back to
the developers to review/include in their source.


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 12.2 (x86_64) Kernel 3.4.6-2.10-desktop
up 2:05, 3 users, load average: 0.03, 0.16, 0.20
CPU Intel i5 CPU M520@2.40GHz | Intel Arrandale GPU

Fair enough.
Are there any advantages to use systemd over init.d scripts? Should one be preferred to the other?

Hi
openSUSE is moving towards systemd rather than sysVinit there may be
limited support for it in the next release, but current talk on the
development mailing list is for it to be dropped for 12.3.

I would say systemd is preferred :wink:


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 12.2 (x86_64) Kernel 3.4.6-2.10-desktop
up 10:59, 3 users, load average: 0.01, 0.07, 0.06
CPU Intel i5 CPU M520@2.40GHz | Intel Arrandale GPU

Thanks for your help!

Many many thanks from Italy as well!