Running script over SSH works. But over xinetd or after switching user it wont work

317 views Asked by At

im running a 7Days to Die server. Usually i connect via ssh with user "linux" and run the command:

/home/linux/start

This works, server is running.

But when i switch user to root (su root) and run:

sudo -u linux /home/linux/start

or

sudo -u linux -i bash -c '/home/linux/start'

the server is shutting down after 5 min and i get this in the logfile:

Failed to create secure directory (/run/user/0/pulse): Permission denied
Failed to create secure directory (/run/user/0/pulse): Permission denied
Failed to create secure directory (/run/user/0/pulse): Permission denied

and after some lines i also get:

2015-06-23T12:12:15 17,008 INF Disconnect
2015-06-23T12:12:15 17,008 INF NET: Stopping server protocols
Platform assembly: /home/linux/7daysded/7DaysToDie_Data/Managed/Mono.Security.dll (this message is harmless)
2015-06-23T12:12:15 17,054 INF NET: Untiy NW server stopped
2015-06-23T12:12:15 17,055 INF [Steamworks.NET] NET: Server stopped
2015-06-23T12:12:15 17,055 INF [NET] ServerShutdown

Same goes for xinetd. When the xinetd server trys to run the script, it crashes too.

I guess when i run it via sudo or xinetd, the User ID is still 0 (root) instead of 1000 (linux). How can i solve the problem?

The Startscript:

#!/bin/bash

if pgrep "7DaysToDie." > /dev/null
then
    exit
else

cd /home/linux
screen -A -m -d -S 7DaysServer /home/linux/7daysded/startserver.sh -configfile=serverconfig.xml
screen -ls
fi

Some info about my System:

Debian Version 8.1

Linux version 3.16.0-4-amd64 ([email protected]) (gcc version 4.8.4 (Debian 4.8.4-1) ) #1 SMP Debian 3.16.7-ckt11-1 (2015-05-24)

Thanks and Regards,

Patrick

UPDATE:

i tried to run as root:

ssh -t linux@localhost -p 1111 "/home/linux/restart"

I hoped it would be the same as doing it over ssh with putty. But it still doesnt work.

1

There are 1 answers

0
umläute On

it seems like your server requires pulseaudio (for sound output? what kind of server is this?)

now when you log in as root, root starts the pulseaudio service, which creates a few files owned by root (e.g. /run/user/0/pulse), and which are unreadable by other users (that's by intention: you don't want to allow everybody who can log into the machine to be eavesdropping the person that sits behind the keyboard, do you?)

in order to prevent this problem, you have several options (best one first; worst one last):

  • don't login as root at all. (automatically) log in as user linux and start the server.

  • disable audio support for the server (does it really need to play back sounds or record from the microphone?)

  • stop the root-owned pulseaudio before running your startup; either manually start a user-owned pulseaudio (or hope that your server will automatically spawn one)

  • configure your soundsystem to allow multiple users to connect to a single session

  • just grant the permissions to read/write the problematic files. something like (as root): chown -R linux /run/user/0/pulse before the sudo-line