I'm running a gameserver and want to start it on a screen on system start, but screen is user specific, so I have to run the command as 'user'. So I wrote this short service script which starts itself as 'user':


case "$1" in
    sleep 1
    case "$2" in
        echo "Starting server..."
        screen -dmS scr1 /home/user/game/run.sh
        echo "Server started"
      stop) #definitely unfinished 
        echo "Stopping Server..."
        #screen -S scr1 say Server is going down for a halt now!
        #sleep 1
        #screen -S scr1 stop
        echo "Server stopped"
        echo "Usage: /etc/init.d/gameserver {start|stop}"
        exit 1
    su - user  -c "bash -c  '/etc/init.d/gameserver -user $1'"

exit 0

and after sudo update-rc.d gameserver defaults the command sudo service gameserver start runs fine, but sadly the server isnt started on system startup.. I'm running Ubuntu 12.04 x64

edit: I've tried replacing su -c with setuid but still no change.


You need to enable it to be started at boot time

update-rc.d gameserver enable

or if you are doing it manually; you need symlink in most probably (/etc/rc2.d) to /etc/init.d/gameserver

ln -s /etc/init.d/gameserver /etc/rc2.d/S99gameserver

and to stop it at shutdown and reboot these two

ln -s /etc/init.d/gameserver /etc/rc0.d/K99gameserver

ln -s /etc/init.d/gameserver /etc/rc6.d/K99gameserver


explicitly set PATH in your init script; it is likely failing because it cant find where 'screen' 'bash' and 'su' you are trying to run there are

to set path do;

export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin

set this just after #!/bin/bash in your script

| improve this answer | |
  • I forgot to mention the argument 'defaults' on the update-rc.d command, edited the post now. There are all these links already there, except its S/K20.. not S/K99.. – yspreen Nov 9 '14 at 14:58
  • is init script set as executable ? chmod 0755 /etc/init.d/gameserver ? – Hrvoje Špoljar Nov 9 '14 at 15:04
  • I ran a chmod +x on it. Also tried chmod 0755 as you suggested, but it didnt change anything – yspreen Nov 9 '14 at 15:08
  • can you add something like touch /tmp/foo in your init script and check when computer boots if /tmp/foo exists; this will tell you if your init script ran at all... trying to narrow down – Hrvoje Špoljar Nov 9 '14 at 15:25
  • also; try set path; I think path is not set and screen can't be found when you run your script at boot time... whereas when you run it from shell it inherits PATH you currently have set – Hrvoje Špoljar Nov 9 '14 at 15:29

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.