Upstart service never starts or stops completely

I'm trying to make a simple upstart script for teamspeak server, but can't make it work.

When I say initctl start it just executes but never finishes or even emits any message. Same is happening for stop.

To be sure I am not doing anything wrong, I have copied the cron script and tried to run it, but it happens the same.

what am I doing wrong here?

UPDATE:

here is my script for TS3:

# myservice - myservice job file
description "my service description"
author "Me <[email protected]>"

# Stanzas
#
# Stanzas control when and how a process is started and stopped
# See a list of stanzas here: http://upstart.ubuntu.com/wiki/Stanzas#respawn

# When to start the service
start on runlevel [2345]

# When to stop the service
stop on runlevel [016]

# Automatically restart process if crashed
respawn

# Essentially lets upstart know the process will detach itself to the background
expect fork

# Start the process
script
       emit going into TS3 dir
       chdir /home/danizmax/teamspeak3-server_linux-x86/
       emit starting TS3
       exec su -c "/home/danizmax/teamspeak3-server_linux-x86/ts3server_startscript.sh start" danizmax &
       emit done
end script

I tried even with simplest script, and that also doesn't work:

description     "regular background program processing daemon"

start on runlevel [2345]
stop on runlevel [!2345]

expect fork
respawn

exec echo example
console output

Thank you for your help.


Solution 1:

there are a number of oddities in your upstart job that have me scratching my head.

1) emit isn't a program that I know of, so unless you've added it to the system path, that is probaly causing errors. Did you mean 'echo' ? That may not be helpfull either, since it will go to the system console which may not be visible.

2) Assuming the 'emit' stanza works, you say 'expect fork' but then actually fork twice. Once for the 'script', and then again when the teamspeak script forks to background itself.

3) you "su" to run the script, but start-stop-daemon is actually simpler for most cases:

With 11.10, you don't need to do the chdir in script, not sure if that was added after whatever version of upstart you have. Check man 5 init for the word chdir

start on runlevel [2345]
stop on runlevel [^2345]

respawn

chdir /home/danizmax/teamspeak-server
expect fork

exec start-stop-daemon --start --user danizmax --group danizmax --exec /home/danizmax/teamspeak3-server_linux-x86/ts3server_startscript.sh -- start

Also, errors will likely be reported in /var/log/syslog . You can increase the error level quite a bit by running

initctl log-priority info

man initctl for more log levels.