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':
#!/bin/sh
#/etc/init.d/gameserver
case "$1" in
-user)
sleep 1
case "$2" in
start)
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
;;
esac
;;
*)
su - user -c "bash -c '/etc/init.d/gameserver -user $1'"
;;
esac
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.