1

i have a short bash script which can run a file. When im trying to start this by "x.sh start", there is appearing a warning 'must be connected to a terminal'. How to start this? I tried some configs of chmods. This script is in /usr/local/bin Im now on root, on my Debian 7 vps.

  #!/bin/bash

server_start() {
screen /usr/share/s/x.sh &
}

server_stop() {
killall x.sh
killall xx
}

server_restart() {
server_stop
sleep 1
server_start
}
case "$1" in
'start')
server_start

;;
'stop')
server_stop
;;
'restart')
server_restart
;;
*)
echo "usage $0 start|stop|restart"
esac
aio
  • 21
  • 1
  • 4
  • Note that your script will leave useless screen sessions open for every stop/restart of your service. Using `nohup` or [`start-stop-daemon`](http://man7.org/linux/man-pages/man8/start-stop-daemon.8.html) instead would be better. – Gerald Schneider Jan 10 '17 at 11:29

4 Answers4

6

screen requires a terminal.

If you want to start a new session in detached mode, then you want to add the -d -m arguments to screen.

Douglas Leeder
  • 2,745
  • 18
  • 15
1

Your screen call is wrong. Screen require $STY environment variable (-m option prevent it.)

You must use -d (start detached session) and -m (prevent $STY environment variable usage) options instead of & to start a daemon screen session.

Check screen documentation for more info.

Slipeer
  • 3,295
  • 2
  • 21
  • 33
0

Start screen in detached mode: screen -dm /usr/share/game/startlss.sh

arekm
  • 131
  • 4
  • But screening in this patch works fine. I'm trying to start a command "lss.sh start" which is in /usr/local/bin – aio Jan 10 '17 at 11:18
0

Thanks everyone, i added -d -m in lss.sh

server_start() {
screen -d -m /usr/share/game/startlss.sh &

Everything works fine now!

aio
  • 21
  • 1
  • 4
  • If one of the answers solved your problem, accept the answer, this will also mark your question as solved. Don't post someone elses solution as your own. – Gerald Schneider Jan 10 '17 at 11:25