Skip to content

[Linux] Autostart into a screen.

Vincs edited this page Mar 4, 2021 · 5 revisions

Requisit

  • nodejs ^14 if your using SSS from source.
    • Warning: it doesn't work well with Node installed by NVM. For this to work, it recommended to install with your package manager.
  • SSS binary
  • screen (install it using your package manager)

Create two script files, one for screen and one for the server

Both in the root of your server, in this example: /home/$USER/minecraft/server

A script to start the screen with the server inside it.

start_screen.sh

#!/bin/bash
folder=$(dirname "$0")
cd  $folder

msg="$(date --iso-8601=seconds) ... Starting screen and server ... $(whoami) -> $(pwd) "
echo $msg
echo $msg >> start_screen.log

screen -S minecraft -d -m $folder/start.sh 

msg="$(date --iso-8601=seconds) ... Done ... "
echo $msg
echo $msg >> start_screen.log

screen -ls

A script to start the server

start.sh

#!/bin/bash
msg="$(date --iso-8601=seconds) ... Starting SleepingServer ... $(whoami) => $(pwd) "
echo $msg >> start.log

npm start

⚠️ Don't forget to make the .sh executable

chmod +x *.sh

Add a start up entry

Add an entry to your startup using crontab

crontab -e

Add a new line pointing to your script file ( & means to detach from the process once started) Don't forget to point to your script / directory.

@reboot /home/$LOGNAME/minecraft/server/start_screen.sh &

You should be able to get back to your screen using

screen -r minecraft

There are other way to start a server like

  • pm2
  • autostart
  • as a service

I let your find your preferred way. Don't hesitate to share your experiences.