Sofus Øvretveit Sofus Øvretveit - 8 months ago 89
Linux Question

Screen not starting from rc.local

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.

exit 0

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


cd /home/spigot1_12


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", 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!

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download