Startup with Init.d

From FUPPES

Jump to: navigation, search

Contents

General Linux Startup Instructions

Here are instructions to enable starting fuppes when your system boots on linux.

Distribution Specific

Debian / Ubuntu

To start fuppes during boot on debian-based systems, you'll need to create an init.d script that gets called during system startup.

First lets prepare. We need to copy the existing fuppes configuration files to system folders (such as /etc/fuppes) and the database to another appropriate system folder (such as /var/lib/fuppes):

sudo mkdir /etc/fuppes
sudo mkdir /var/lib/fuppes
sudo cp ~/.fuppes/fuppes.cfg /etc/fuppes
sudo cp ~/.fuppes/vfolder.cfg /etc/fuppes
sudo cp ~/.fuppes/fuppes.db /var/lib/fuppes

Remember that from now on fuppes will be using the system wide configuration and database files (in /etc/fuppes and /var/lib/fuppes), so edit them to make any changes. We do this, of course, so nobody has to be logged on to the computer for fuppes to run.

To avoid running fuppes as root (and the security risks that involves), create a fuppes user and group. The init.d script will then use these to run the fuppes daemon.

sudo adduser --system --home /var/lib/fuppes --shell /bin/sh --group --no-create-home fuppes

The fuppes daemon needs to be able to write its configuration and database files so change the owner of these files to the fuppes user and group.

sudo chown fuppes:fuppes /etc/fuppes/*
sudo chown -R fuppes:fuppes /var/lib/fuppes

Now let's create our init.d script:

sudo gedit /etc/init.d/fuppesd

Copy and paste the following to gedit then save the file:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          fuppesd
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      S 0 1 6
# Short-Description: UPnP Media Server
# Description:       Fuppes UPnP media server.
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DESC="UPnP Media Server"
NAME=fuppesd
DAEMON=`which $NAME`
DAEMON_ARGS="--config-dir /etc/fuppes/ --database-file /var/lib/fuppes/fuppes.db --log-level 1"
SCRIPTNAME=/etc/init.d/$NAME
FUPPES_USER=fuppes
FUPPES_GROUP=fuppes

# Exit if the package is not installed
if [ ! -x "$DAEMON" ]; then
{
        echo "Couldn't find $DAEMON"
        exit 99
}
fi

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
	# Return
	#   0 if daemon has been started
	#   1 if daemon was already running
	#   2 if daemon could not be started
	start-stop-daemon --start --quiet --chuid $FUPPES_USER:$FUPPES_GROUP --exec $DAEMON --test > /dev/null \
		|| return 1
	start-stop-daemon --start --quiet --chuid $FUPPES_USER:$FUPPES_GROUP --exec $DAEMON -- $DAEMON_ARGS \
		|| return 2
}

#
# Function that stops the daemon/service
#
do_stop()
{
	# Return
	#   0 if daemon has been stopped
	#   1 if daemon was already stopped
	#   2 if daemon could not be stopped
	#   other if a failure occurred
	start-stop-daemon --stop --signal 2 --retry 5 --quiet --name $NAME
	RETVAL="$?"
	[ "$RETVAL" = 2 ] && return 2
	return "$RETVAL"
}

case "$1" in
  start)
	log_daemon_msg "Starting $DESC" "$NAME"
	do_start
	case "$?" in
		0|1) log_end_msg 0 ;;
		2) log_end_msg 1 ;;
	esac
	;;
  stop)
	log_daemon_msg "Stopping $DESC" "$NAME"
	do_stop
	case "$?" in
		0|1) log_end_msg 0 ;;
		2) log_end_msg 1 ;;
	esac
	;;
  restart|force-reload)
	log_daemon_msg "Restarting $DESC" "$NAME"
	do_stop
	case "$?" in
	  0|1)
		do_start
		case "$?" in
			0) log_end_msg 0 ;;
			1) log_end_msg 1 ;; # Old process is still running
			*) log_end_msg 1 ;; # Failed to start
		esac
		;;
	  *)
	  	# Failed to stop
		log_end_msg 1
		;;
	esac
	;;
  *)
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
	exit 3
	;;
esac

:


Lets change the permissions on our new fuppes init.d script to be executable:

sudo chmod +x /etc/init.d/fuppesd


Finally, we need to create symlinks to the various runtime init folders, such as rc2.d, etc. An easy way to do this is with the update-rc.d command. We're going to tell the system to automatically startup fuppes in runlevels 2-5 and to stop fuppes at runlevels 0, 1 and 6. We'll start it fairly late in the boot process to make sure all file systems have been mounted, etc:

sudo update-rc.d fuppesd defaults 60


Now reboot your system and make sure fuppes is up and running by viewing its web configuration page.

NOTE: You can always stop and/or start fuppes using the init.d script at any terminal:

sudo /etc/init.d/fuppesd stop
sudo /etc/init.d/fuppesd start

Gentoo

Save the following script into your /etc/init.d directory.

The script makes the following assumptions...

  • A user with the username 'fuppes' exists
  • The following directories exist and are writable by the fuppes user
    • /etc/fuppes
    • /var/lib/fuppes
    • /var/log/fuppes
#!/sbin/runscript
# $Header: $

depend() {
        use net
}

start() {
        ebegin "Starting Fuppes"
        start-stop-daemon --start --quiet --exec /usr/bin/fuppesd \
                --chuid fuppes -- --config-dir /etc/fuppes \
                --database-file /var/lib/fuppes/fuppes.db \
                2>> /var/log/fuppes/fuppes.err \
                >> /var/log/fuppes/fuppes.log
        eend $?
}

stop() {
        ebegin "Stopping Fuppes"
        start-stop-daemon --stop --quiet --exec /usr/bin/fuppesd
        eend $?
}

Fedora

Save the following script into your /etc/init.d directory.

The script makes the following assumptions...

  • A user with the username 'fuppes' exists
  • The following directories exist and are writable by the fuppes user
    • /etc/fuppes
    • /var/lib/fuppes
    • /var/log/fuppes
# Init file for fuppesd server daemon
#
# chkconfig: 2345 81 32
#
# processname: fuppesd
# Short-Description: UPnP Media Server
# Description:       Fuppes UPnP media server.

# source function library
. /etc/rc.d/init.d/functions

RETVAL=0
prog=fuppesd

FUPPESD=/usr/local/bin/$prog
OPTIONS="--config-dir /etc/fuppes/ --database-file /var/lib/fuppes/fuppes.db --log-level 1 --log-file /var/log/fuppes"
runlevel=$(set -- $(runlevel); eval "echo \$$#" )

# Exit if the package is not installed
[ -x "$FUPPESD" ] || exit 0

#
# Function that starts the daemon/service
#
start()
{
        echo -n "Starting $prog: "
        daemon --user fuppes $FUPPESD $OPTIONS && success || failure
        RETVAL=$?
        [ "$RETVAL" = 0 ] && touch /var/lock/subsys/$prog
        echo
}

#
# Function that stops the daemon/service
#
stop()
{
        echo -n $"Stopping $prog: "
        killproc $prog
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog /var/run/fuppesd.pid
        echo
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        start
        ;;
  status)
        status $FUPPESD
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|status}"
        RETVAL=1
esac
exit $RETVAL

Once installed run

sudo chkconfig fuppesd on

Arch Linux

Save the following script into your /etc/rc.d directory.

The script makes the following assumptions...

  • A user with the username 'fuppes' exists
  • The following directories exist and are writable by the fuppes user
    • /etc/fuppes
    • /var/lib/fuppes
    • /var/log/fuppes
#!/bin/bash

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

PID=`cat /var/run/fuppesd.pid 2>/dev/null`
case "$1" in
  start)
    stat_busy "Starting FUPPES"
    [ -z "$PID" ] && su fuppes -c "/usr/bin/fuppesd --config-dir /etc/fuppes \
        --database-file /var/lib/fuppes/fuppes.db \
        2>> /var/log/fuppes/fuppes.err >> /var/log/fuppes/fuppes.log"
    if [ $? -gt 0 ]; then
      stat_fail
    else
      pidof '/usr/bin/fuppesd' > /var/run/fuppesd.pid
      add_daemon fuppesd
      stat_done
    fi
    ;;
  stop)
    stat_busy "Stopping FUPPES"
    [ ! -z "$PID" ]  && kill $PID &> /dev/null
    if [ $? -gt 0 ]; then
      stat_fail
    else
      rm /var/run/fuppesd.pid
      rm_daemon fuppesd
      stat_done
    fi
    ;;
  *)
    echo "usage: $0 {start|stop}"
esac
exit 0
Personal tools