3

I have a problem where I am unable to start a screen session at boot using the rc.local file. The specific screen I am starting is for a spigot minecraft server.

This is my rc.local file:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

/home/pi/Documents/bootlog.sh
/home/spigot1_12/startspigot.sh
exit 0

This is the startspigot.sh script (with chmod u+x):

#!/bin/bash

cd /home/spigot1_12

boot=$(date)

echo "Starting spigot server in screen \"minecraft\" @  $boot " >> /home/pi/Documents/minecraftlog


screen -S minecraft java -Xms512M -Xmx1008M -jar /home/spigot1_12/spigot-1.12.jar nogui

The minecraftlog file does update at each boot, so the script is run.

When I run the command "sudo sh startspigot.sh", everything works perfectly. The screen is started and the minecraftlog file is updated. I can find the screen again with "sudo screen -ls"

At boot, however, both "sudo screen -ls" and "screen -ls" return no sockets.

What can be causing this? The only two users are "pi" and root.

Thanks in advance!

Sofus Øvretveit
  • 323
  • 1
  • 3
  • 10
  • 1
    Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Jun 20 '17 at 18:34

2 Answers2

5

Starting a script in a new detached screen as current user (rc.local = root):

screen -dmS <session name> <command>, example:

screen -dmS screenName bash /home/user/run.sh


Starting a script from rc.local as user:

runuser -l user -c 'screen -dmS screenName bash /home/user/run.sh'

DaWe
  • 1,422
  • 16
  • 26
3

Running screen in detached mode (when you do not have active terminal, like in rc.local or crontab):

screen -dm -S <session name> <command>

-d -m Start screen in "detached" mode

-S When creating a new session, this option can be used to specify a meaningful name for the session.

Community
  • 1
  • 1
Tamar
  • 669
  • 3
  • 9