0

I have a Minecraft server running on OS Ubuntu Server 20.04.3 with systemd.

I need to create a user called shutdown which, on login (even from ssh) should:

  • Run script shutdownAll
  • Log out from session

The shutdownAll script should be the following (or equivalent):

systemctl stop minecraft
shutdown +5 "SERVER SHUTDOWN IN 5 MINUTES"

Any ideas to do it?
EDIT: I've thought about using a command as shell, but how do I execute two commands?

3
  • Did you try putting those commands in the shutdown user's shell's start-up file (like, in ~/.bashrc)? Commented Nov 4, 2021 at 21:24
  • Does the user have the ability to run systemctl with sudoer rights so that it can actually stop the service? Commented Nov 5, 2021 at 0:43
  • @they @Nasir Riley Didn't try using ~/.bashrc, but I had made a script to be run manually. It was in the sudoer file, but didn't recognize systemctl. Used a Cmd_Alias with permission for just /sbin/shutdown and /bin/systemctl Commented Nov 5, 2021 at 6:52

1 Answer 1

0

I've managed to solve this.
I've created a new script (/usr/local/bin/management/shutdownAll), containing

sudo systemctl stop minecraft
sudo shutdown +5 "SERVER SHUTDOWN IN 5 MINUTES"

And made it executable with chmod +x shutdownAll.
Then edited visudoer file adding

shutdown ALL = ALL

And called usermod -s /usr/blocal/bin/management/shutdownAll.
On login, the password is asked twice (but it's ok), once for login and once for sudo, then the server is stopped, poweroff scheduled 5 minutes later and session is closed.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.