0

The service works perfectely if I am not logged in, but if I connect with ssh and then disconnect the service gets terminated. The service belongs to the user to whom I ssh. This is my current ts3.service file:

[Unit]
Description=TeamSpeak3Server

[Service]
User=user1
Group=staff
Type=forking
WorkingDirectory=/usr/local/bin/teamspeak3-server_linux_amd64
ExecStart=/usr/local/bin/teamspeak3-server_linux_amd64/ts3server_startscript.sh start
ExecStop=/usr/local/bin/teamspeak3-server_linux_amd64/ts3server_startscript.sh stop
PIDFile=/usr/local/bin/teamspeak3-server_linux_amd64/ts3server.pid
RestartSec=5
Restart=always
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

I have already tried changeing ExecStart to

ExecStart=/usr/bin/nohup /usr/local/bin/teamspeak3-server_linux_amd64/ts3server_startscript.sh start

Other services like openvpn survive the ssh logout. After reconnection the status of the systemd process reads:

active (exited)

while the normal status is

active (running)

Could the cause of the problem be that the script which I execute calls another script which gets killed if the shell sends sighup meassages? Thank you for your answers.

Edit:

the important part of ts3server_startscript.sh are as follows:

COMMANDLINE_PARAMETERS="${2}"
D1=$(readlink -f "$0")
BINARYPATH="$(dirname "${D1}")"
cd "${BINARYPATH}"
LIBRARYPATH="$(pwd)"
BINARYNAME="ts3server"

if [ -e "$BINARYNAME" ]; then
  if[ -x "$BINARYNAME" ]; then
  export LD_LIBRARY_PATH="${LIBRARYPATH}:${LD_LIBARY_PATH}"
  "./${BINARYNAME}" ${COMMANDLINE_PARAMETERS} > /dev/null &
  PID=$!
  ps -p ${PID} > /dev/null 2>&1
  if [ "$?" -ne "0" ]; then
      echo "..."
  else
      echo $PID > ts3server.pid
  fi

So if I interpret that correctely the server is started in the console by

     "./${BINARYNAME}" ${COMMANDLINE_PARAMETERS} > /dev/null &
Beny Benz
  • 21
  • 3
  • 1
    Welcome to Unix Stackexchange! You can [take the tour first](http://unix.stackexchange.com/tour) and the learn [How to Ask a good question](http://unix.stackexchange.com/help/how-to-ask). That makes it easier for us to help you. – andcoz Jun 14 '18 at 14:59
  • Is there any command in your interactive session that _uses_ the service? Give us some pointer on the other script you are talking about. – andcoz Jun 14 '18 at 15:02
  • Sorry, I'm not sure what you mean by "command in your interactive session thet uses the service". Do you want to know if I'm modifying the service while beeing logged in with ssh? To provocate a crash the only thing requiered is to login via ssh and then kill the session with "exit". – Beny Benz Jun 14 '18 at 16:26
  • 1
    Instead of `"./${BINARYNAME}" ${COMMANDLINE_PARAMETERS} > /dev/null &` try `"nohup ./${BINARYNAME}" ${COMMANDLINE_PARAMETERS} < /dev/null > /dev/null 2>&1 &`. See also the good answers at "[Best way to make a shell script daemon](https://stackoverflow.com/questions/3430330/best-way-to-make-a-shell-script-daemon)" on Stack Overflow. – AlexP Jun 14 '18 at 16:39
  • when adding nohup the service is unable to start and reports: ts3.service: Unit entered failed state. ts3.service: Failed with result 'Resources' – Beny Benz Jun 14 '18 at 16:52
  • Check carefully if in any of your startup script (e.g. `.tcshrc` or `.bashrc`) there is some command that interacts with your service. – andcoz Jun 15 '18 at 08:23
  • Check you `.logout` file, does it kill some process? – andcoz Jun 15 '18 at 08:24
  • 1
    Please add the result of running `grep 'KillUser' /etc/systemd/logind.conf` to your question, and – roaima Jun 15 '18 at 08:36
  • response from grep: #KillUserProcesses=no – Beny Benz Jun 16 '18 at 18:44
  • I tried (./script.sh start &) &, then the server crashed after ssh logout, but came up again every minute or so. When logging back in the server was unstable and got restarted once a minute. I guess it has something to do with that the service no longer is able to tell if the server is running and tries to restart it. – Beny Benz Jun 16 '18 at 18:47
  • Can find nothing in .bashrc which interacts with my service. I think this would happen to all services running on my user, processes of other users like openvpn remain untouched. – Beny Benz Jun 16 '18 at 18:49
  • .bash_logout only contains a clear_console command – Beny Benz Jun 16 '18 at 18:52

0 Answers0