I recently moved to Raspbian Jessie on my RPi and now I'd like to move all my services from init.d
to systemd
.
aMule daemon it is now working with init.d but I want to move the script to a amule-daemon.service
file, to add some dependencies from other services, like autofs
.
My actual init.d script for aMule is this:
#! /bin/sh
### BEGIN INIT INFO
# Provides: amule-daemon
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Daemonized version of aMule.
# Description: Starts the aMule daemon with the user specified in
# /etc/default/amule-daemon.
### END INIT INFO
PATH=/sbin:/usr/sbin:/bin:/usr/bin
PROGNAME=amuled
DESC="aMule daemon"
PKGNAME="amule-daemon"
DAEMON=/usr/bin/amuled
WEB=/usr/bin/amuleweb
WEB_OPTS="--quiet --config-file=/etc/.aMule/remote.conf"
SCRIPTNAME=/etc/init.d/$PKGNAME
WRAPPER=/usr/share/amule/amuled_home_wrapper.sh
[ -x "$DAEMON" ] || exit 0
[ -r /etc/default/$PKGNAME ] && . /etc/default/$PKGNAME
. /lib/init/vars.sh # has VERBOSE
. /lib/lsb/init-functions
if [ -z "$AMULED_USER" ]; then
log_warning_msg \
"Not starting $DESC, AMULED_USER not set in /etc/default/$PKGNAME."
exit 0
fi
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 --exec $DAEMON --user "$AMULED_USER" --chuid "$AMULED_USER" --test >/dev/null || return 1
start-stop-daemon --start --quiet --exec $WRAPPER --user "$AMULED_USER" --chuid "$AMULED_USER" >/dev/null || return 2
start-stop-daemon --start --quiet --exec $WEB --user "$AMULED_USER" --chuid "$AMULED_USER" -- $WEB_OPTS & >/dev/null
}
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
start-stop-daemon --stop --quiet --retry="TERM/30/KILL/5" --exec $DAEMON --user "$AMULED_USER" --chuid "$AMULED_USER"
start-stop-daemon --stop --quiet --retry="TERM/30/KILL/5" --exec $WEB --user "$AMULED_USER" --chuid "$AMULED_USER"
return "$?"
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$PROGNAME"
do_start
case "$?" in
0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
1) [ "$VERBOSE" != no ] && \
log_progress_msg "(already running)" && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1; exit 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$PROGNAME"
do_stop
case "$?" in
0 | 1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1; exit 1 ;;
esac
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$PROGNAME"
do_stop
case "$?" in
0 | 1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1; exit 1 ;; # Old process is still running
*) log_end_msg 1; exit 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
exit 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
exit 0
As you can see, it is configured to launch aMule daemon with some options:
- run with specific user
amuled
- run web interface
amuleweb
- load web interface options from
remote.conf
- set home directory configuration using
amuled_home_wrapper.sh
and it works perfectly.
How can I move all this options into the .service file?