Minetestserver Deamon

User avatar
JPRuehmann
Member
 
Posts: 334
Joined: Fri Mar 21, 2014 21:40

Minetestserver Deamon

by JPRuehmann » Sat Mar 22, 2014 23:05

Hello

It would be fine if minetestserver could work in the Background without any User loged in (deamon).
As now, the user that has created the server has to be logged in all the time.
The init scripts you find in the net wont work, because minetestserver wont find anything.

Thanks,
JPR
 

User avatar
sfan5
Member
 
Posts: 3636
Joined: Wed Aug 24, 2011 09:44
GitHub: sfan5
IRC: sfan5

by sfan5 » Sun Mar 23, 2014 07:56

Just run minetestserver --world <path to your world> --config <path to minetest.conf> --logfile <path to debug.txt> from the initscripts.
Here's how you would do it for Arch Linux:
1) Create user minetest
2) mkdir -p /home/minetest/world
3) touch /home/minetest/minetest.conf
4) chown -R minetest /home/minetest
5) Write to /etc/systemd/system/minetestserver.service:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
[Unit]
Description=Minetest server
After=network.target

[Service]
Type=simple
User=minetest
ExecStart=/usr/bin/minetestserver --world /home/minetest/world --config /home/minetest/minetest.conf --logfile /home/minetest/debug.txt

[Install]
WantedBy=multi-user.target

6) systemctl enable minetestserver && systemctl start minetestserver
Mods: Mesecons | WorldEdit | Nuke
Minetest builds for Windows (32-bit & 64-bit)
 

User avatar
JPRuehmann
Member
 
Posts: 334
Joined: Fri Mar 21, 2014 21:40

by JPRuehmann » Fri Apr 04, 2014 14:43

Hi
Thanks for your infos
since none of the init scripts on the internet nor your description works complete for me
I will post my way. It is based on all the information i got.

1) sudo adduser -s minetest
2) sudo -u minetest mkdir /home/minetest/.minetest

copy the script to /etc/init.d
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
#! /bin/sh
### BEGIN INIT INFO
# Provides:          minetestserver
# Required-Start:    $remote_fs $syslog $network
# Required-Stop:     $remote_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Minetest server initscript
# Description:       This script starts and stops Minetest server.
#                    Minetest is a free block building game.
### END INIT INFO

# Author: Juhani Numminen <juhaninumminen0@gmail.com>

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
PROGRAMPATH="/usr/local/bin"
DATAPATH="/home/minetest/.minetest"
DESC="Minetest server"
WORLD="$DATAPATH/worlds/World"
CONFIG="$DATAPATH/minetest.conf"
LOG="$DATAPATH/debug.log"
NAME=minetestserver
DAEMON="$PROGRAMPATH/$NAME"
START="--world $WORLD --config $CONFIG --trace --logfile $LOG"
USERNAME=minetest
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

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

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# 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()
{
    DATEI=$(date +debug-%d.%m.%Y-%H:%M:%S.log)
    if [ -f "$LOG" ]
        then 
        mv "$LOG" "$DATAPATH/$DATEI"
    fi
        # 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 --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
            || return 1
        start-stop-daemon --start --chuid $USERNAME --quiet --nicelevel 8 --background --pidfile $PIDFILE --exec "$DAEMON" -- $START \
            || return 2
        # Add code here, if necessary, that waits for the process to be ready
        # to handle requests from services started subsequently which depend
        # on this one.  As a last resort, sleep for some time.i
}

#
# 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 --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
    RETVAL="$?"
    [ "$RETVAL" = 2 ] && return 2
    # Wait for children to finish too if this is a daemon that forks
    # and if the daemon is only ever run from this initscript.
    # If the above conditions are not satisfied then add some other code
    # that waits for the process to drop all resources that could be
    # needed by services started subsequently.  A last resort is to
    # sleep for some time.
    start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
    [ "$?" = 2 ] && return 2
    # Many daemons don't delete their pidfiles when they exit.
    rm -f $PIDFILE
    return "$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
    #
    # If the daemon can reload its configuration without
    # restarting (for example, when it is sent a SIGHUP),
    # then implement that here.
    #
    start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
    return 0
}

case "$1" in
  start)
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
    do_start
    case "$?" in
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  stop)
    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
    do_stop
    case "$?" in
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  status)
       status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
       ;;
  #reload|force-reload)
    #
    # If do_reload() is not implemented then leave this commented out
    # and leave 'force-reload' as an alias for 'restart'.
    #
    #log_daemon_msg "Reloading $DESC" "$NAME"
    #do_reload
    #log_end_msg $?
    #;;
  restart|force-reload)
    #
    # If the "reload" option is implemented then remove the
    # 'force-reload' alias
    #
    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|reload|force-reload}" >&2
    echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
    exit 3
    ;;
esac

:

edit the PROGRAMPATH and DATAPATH as needed
sudo chown root:root /etc/init.d/minetestserver
sudo chmod 775 /etc/init.d/minetestserver
sudo ln /etc/init.d/minetestserver /etc/rc2.d/S21minetestserver
repeat that for rc3, 4, 5.d
sudo ln /etc/init.d/minetestserver /etc/rc0.d/K21minetestserver
repeat that for rc1 and 6.d

that worked for me on Kubunte 12.04 LTS
Thanks,
JPR
 

MagicFab
New member
 
Posts: 8
Joined: Wed May 21, 2014 00:23

Re: Minetestserver Deamon

by MagicFab » Wed May 21, 2014 01:29

@JPRuehmann thank you, I used your example to configure minetestserver for automatic startup at boot in Debian 8 (Jessie/testing). Could you please indicate what licence this piece of code is licensed under? I'd like to submit it for inclusion in the minetest-server package in Debian.

I believe you forgot one last step:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
sudo update-rc.d minetestserver enable


I had to change the heading of the file, I used the example in /etc/init.d/skeleton. I also changed several paths, the minetest-server package in Debian puts it in /usr/games/.

The resulting final file is as follows:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
#!/bin/sh
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
    set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
fi
### BEGIN INIT INFO
# Provides:          minetestserver
# Required-Start:    $remote_fs $syslog $network
# Required-Stop:     $remote_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Minetest server initscript
# Description:       This script starts and stops Minetest server.
#                    Minetest is a free block building game.
### END INIT INFO

# Author: Juhani Numminen <juhaninumminen0@gmail.com>
# Modified for Debian by: Fabian Rodriguez <magicfab+minetestforum@legoutdulibre.com>
# Original discussion at: https://forum.minetest.net/viewtopic.php?p=135918#p135918

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
PROGRAMPATH="/usr/games"
DATAPATH="/home/minetest/.minetest"
DESC="Minetest server"
WORLD="$DATAPATH/worlds/world"
CONFIG="$DATAPATH/minetest.conf"
LOG="$DATAPATH/debug.log"
NAME=minetestserver
DAEMON="$PROGRAMPATH/$NAME"
START="--world $WORLD --config $CONFIG --trace --logfile $LOG"
USERNAME=minetest
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

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

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# 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()
{
DATEI=$(date +debug-%d.%m.%Y-%H:%M:%S.log)
if [ -f "$LOG" ]
    then
    mv "$LOG" "$DATAPATH/$DATEI"
fi
    # 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 --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
   || return 1
    start-stop-daemon --start --chuid $USERNAME --quiet --nicelevel 8 --background --pidfile $PIDFILE --exec "$DAEMON" -- $START \
   || return 2
    # Add code here, if necessary, that waits for the process to be ready
    # to handle requests from services started subsequently which depend
    # on this one.  As a last resort, sleep for some time.i
}

#
# 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 --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently.  A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
}

case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
    0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
    2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
    0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
    2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
   status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
   ;;
#reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
#log_daemon_msg "Reloading $DESC" "$NAME"
#do_reload
#log_end_msg $?
#;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
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|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac

:

 

User avatar
JPRuehmann
Member
 
Posts: 334
Joined: Fri Mar 21, 2014 21:40

Re: Minetestserver Deamon

by JPRuehmann » Wed May 21, 2014 08:09

Hello
It is based itself on Code that I've found on the Net.
Since theyŕe all free.

I think I can put it under the WTFPL.

Have Fun with it.
JPR

P.S. I prefer to create the links in /etc/rc.* myself.
 

MagicFab
New member
 
Posts: 8
Joined: Wed May 21, 2014 00:23

Re: Minetestserver Deamon

by MagicFab » Wed May 21, 2014 13:28

Actually minetest-server is under "LGPLv2.1 and later"
http://metadata.ftp-master.debian.org/c ... _copyright

If you see no objection I'll submit it using that licence instead. There was some discussion about licensing minetest contributions in Debian here:
viewtopic.php?id=7163

I see I could probably do WTF I'd like with it, but as a matter of principle I prefer asking than doing.
 


Return to Minetest Features

Who is online

Users browsing this forum: No registered users and 5 guests

cron