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 &
  • 1
    Welcome to Unix Stackexchange! You can take the tour first and the learn How to Ask a good question. 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" on Stack Overflow. – AlexP Jun 14 '18 at 16:39
  • 1
    Please add the result of running grep 'KillUser' /etc/systemd/logind.conf to your question, and – roaima Jun 15 '18 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.