2

I'm trying to create a simple echo-service using ubuntu upstart.

For some reason upstart behaves really strange. When it starts the echo server first time everything is ok, but when it starts it second, third, etc time it creates two processes.

It's not fork and it's not daemon.

Please have a look at an example below. I have read almost all upstart documentation and don't understand what it means. I would appreciate for any help.

root@z-server:~# cat /etc/init/echoservice.conf
exec ncat -l 7 -k -e "/bin/cat"
root@z-server:~#
root@z-server:~#
root@z-server:~# start echoservice
echoservice start/running, process 1383
root@z-server:~#
root@z-server:~#
root@z-server:~# ps aux | grep -v grep | grep -i ncat
root      1383  0.0  0.0  17348  1328 ?        Ss   22:11   0:00 ncat -l 7 -k -e /bin/cat
root@z-server:~#
root@z-server:~# stop echoservice
echoservice stop/waiting
root@z-server:~#
root@z-server:~# ps aux | grep -v grep | grep -i ncat
root@z-server:~#
root@z-server:~# start echoservice
echoservice start/running, process 1401
root@z-server:~#
root@z-server:~# ps aux | grep -v grep | grep -i ncat
root      1401  0.0  0.0   4440   624 ?        Ss   22:12   0:00 /bin/sh -e -c ncat -l 7 -k -e "/bin/cat" /bin/sh
root      1402  0.0  0.0  17348  1324 ?        S    22:12   0:00 ncat -l 7 -k -e /bin/cat
root@z-server:~#
root@z-server:~#
root@z-server:~# stop echoservice
echoservice stop/waiting
root@z-server:~#
root@z-server:~# ps aux | grep -v grep | grep -i ncat
root@z-server:~#
root@z-server:~# start echoservice
echoservice start/running, process 1411
root@z-server:~#
root@z-server:~#
root@z-server:~# ps aux | grep -v grep | grep -i ncat
root      1411  0.0  0.0   4440   628 ?        Ss   22:12   0:00 /bin/sh -e -c ncat -l 7 -k -e "/bin/cat" /bin/sh
root      1412  0.0  0.0  17348  1324 ?        S    22:12   0:00 ncat -l 7 -k -e /bin/cat
root@z-server:~#
root@z-server:~# kill -9 1411
root@z-server:~#
root@z-server:~# ps aux | grep -v grep | grep -i ncat
root      1412  0.0  0.0  17348  1324 ?        S    22:12   0:00 ncat -l 7 -k -e /bin/cat
root@z-server:~#
root@z-server:~# initctl status echoservice
echoservice stop/waiting
root@z-server:~#
root@z-server:~# start echoservice
echoservice start/running, process 1421
root@z-server:~#
root@z-server:~# ps aux | grep -v grep | grep -i ncat
root      1412  0.0  0.0  17348  1324 ?        S    22:12   0:00 ncat -l 7 -k -e /bin/cat
root@z-server:~#

1 Answer 1

3

Try dropping the quotes around /bin/cat. So do:

exec ncat -l 7 -k -e /bin/cat

The reason I say this is that the documentation says:

Any special characters, e.g. quotes or `$' specified will result in the entire command being passed to a shell for expansion.

In this case there's no need to call the command via the shell, so let's make it simpler so that you don't use the shell.

If you do want to use the shell, then you might explicitly use a script...end script stanza and explicitly use a shell exec command in there instead.

I'm not sure why you're getting your original behaviour, but I think you may be able to fix it by avoiding use of a shell in the first place.

3
  • Thanks a lot, it helped. So do you mean that there is a difference between exec stanza and script stanza? I thought the difference is just one line vs multiline.
    – zeroed
    Jul 14, 2013 at 20:06
  • Can you please explain why I need exec command inside script stanza? Is there a difference between this exec shell command and exec stanza? I see examples with exec inside script section in man 5 init, but they don't explain why I would need it.
    – zeroed
    Jul 14, 2013 at 20:31
  • 1
    The documentation says that the exec upstart stanza uses sh only if it contains separate characters, whereas a script stanza always uses sh. The exec inside a script stanza is a separate shell command which replaces the shell instead of starting a new process by forking. See the exec manpage for details. Jul 15, 2013 at 7:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .