Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Here is my script in init.d (Debian Linux)

#! /bin/sh
# /etc/init.d/blah
#

# Some things that run always
touch /var/lock/McMyAdmin

# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting McMyAdmin "
screen -dmS Minecraft
sleep 2
screen -S Minecraft -X stuff "bash /opt/McMyAdmin/start.sh"`echo -ne '\015'`
;;
stop)
echo "Stopping McMyAdmin"
screen -S Minecraft -X stuff "\quit"`echo -ne '\015'`
;;
*)
echo "Usage: /etc/init.d/McMyAdmin {start|stop}"
exit 1
;;
esac

exit 0

My problem is that upon starting the screen session, nothing happens. If I type line by line it works fine, but in the script nothing works. It creates the screen session but no commands are sent to it. what am I doing wrong?

share|improve this question

1 Answer 1

You have to cd to the McMyAdmin installation directory before you can run it. You can't run its start.sh script from another directory.

Change:

screen -S Minecraft -X stuff "bash /opt/McMyAdmin/start.sh"`echo -ne '\015'`

to

cd /opt/McMyAdmin/
screen -S Minecraft -X stuff "sh start.sh"`echo -ne '\015'`

Also it's not a brilliant idea to put McMyAdmin in /opt/ and running it as root. Instead you should create a user just for it and use either a @reboot line in that users crontab, or use su in your initscript to change which user is used to run the server.

share|improve this answer
    
That dosen't seem to do it. Its the weirdest thing. It seems like I cannot send a command to the screen inside the script. I cannot send anything. This would work fine outside the script. –  Adam Schiavone Feb 15 '12 at 1:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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