4

I created upstart config file at: /etc/init/carbon-cache.conf to stop/start/restart carbon-cache process. I can start carbon-cache process using command: start carbon-cache, however, I could not use stop/restart carbon-cache and always gives me errors: "stop: Unknown instance:".

Does anyone know what seem to be the issue? Here is the my upstart config: /etc/init/carbon-cache.conf

description "Daemonized Carbon-Cache"

start on runlevel [2345]
stop on runlevel [016]

setuid www-data
setgid www-data

exec /opt/graphite/bin/carbon-cache.py start

respawn
respawn limit 10 5
Nam Nguyen
  • 5,668
  • 14
  • 56
  • 70
  • 1
    This is probably related on what the process is doing when it starts. If it forks, you should get the pid of the forked process and not the parent. Use ps ax | grep carbon to find out. There's special stanza in upstart - expect - which handles this cases. Read this http://upstart.ubuntu.com/cookbook/#expect – hovanessyan Nov 07 '13 at 08:55
  • I tried following and did not work as well: https://wiki.xkyle.com/Carbon_Collector – Nam Nguyen Nov 14 '13 at 00:51

3 Answers3

4

I suggest using this carbon-cache.conf file: https://gist.github.com/dbeckham/8057390

  • 1
    The money quote from this file's comments: # Fun fact, without --nodaemon, twistd carbon-cache forks five times (5!). # Upstart wasn't designed to handle that level of wtf. – encoded Jan 31 '15 at 00:46
1

i think what's happening is that your upstart is successfully able to exec it, but as soon as it runs, carbon-cache, because of it's daemonic nature detaches itself from upstart. So when upstart tries to kill it, it realizes that carbon-cache is no longer attached.

Upstart expects the command run to stay in the foreground, not fork-off and de-attach.

"Twistd, the utility used to daemonize carbon-cache supports a --nodaemon flag that launches the process in the foreground instead of forking it into the background. At the time this article was posted, the only way to get the --nodaemon flag to twistd was by starting carbon-cache with --debug."

Though, i'd advice against un-daemoning carbon, which is necessary in an upstart implementation.

erbdex
  • 1,899
  • 3
  • 22
  • 40
  • upstart currently support 'expect daemon' but somehow I could not get it to work as expected. I would prefer not to use --debug. – Nam Nguyen Nov 14 '13 at 22:53
0

sudo /opt/graphite/bin/carbon-cache.py start

erbdex
  • 1,899
  • 3
  • 22
  • 40
  • Hi @erbdex, I know I can use carbon-cache.py stop/start the process, however, making upstart to stop/restart is an issue for me that I have to figure it out. – Nam Nguyen Nov 08 '13 at 23:00
  • You are dropping user privileges to 'www-data' user. And hence the carbon-cache initiation is done on that user's behalf. But carbon-cache needs root level access for initiating socket connections and sending men to Mars. Hence, use- """exec sudo /opt/graphite/bin/carbon-cache.py start""" – erbdex Nov 09 '13 at 15:31
  • even use root, it does not help. Notice that I can start but I can not stop/restart upstart. – Nam Nguyen Nov 14 '13 at 03:03
  • i still have a feeling that it is a permission issue. Could you please try replacing "setuid www-data" by "setuid root" and "setgid www-data" by "setgid root" to confirm. (And don't forget to remove "sudo", with root.) – erbdex Nov 14 '13 at 05:11
  • changed to what you suggested, start is ok, stop shows me errors:# stop carbon-cache stop: Unknown instance: – Nam Nguyen Nov 14 '13 at 06:26
  • - # cat /etc/init/carbon-cache.conf description "Daemonized Carbon-Cache" start on runlevel [2345] stop on runlevel [016] setuid root setgid root exec /opt/graphite/bin/carbon-cache.py start respawn respawn limit 10 5 – Nam Nguyen Nov 14 '13 at 06:27
  • woo.. I can't put newline in comment! – Nam Nguyen Nov 14 '13 at 06:27
  • I wrote graphite install script and tested on Ubuntu vmware: https://github.com/gdbtek/setup-graphite . You can try it out and see if your upstart can work. Thanks – Nam Nguyen Nov 14 '13 at 06:31
  • Add these diagnostic details in the question. You can edit questions on SO. – erbdex Nov 14 '13 at 06:48
  • """# ./carbon-cache stop""" What error do you get if you run this, on a carbon-cache that has been initiated via upstart? – erbdex Nov 14 '13 at 06:56
  • # ./carbon-cache.py stop /usr/lib/python2.7/dist-packages/zope/__init__.py:3: UserWarning: Module twisted was already imported from /usr/local/lib/python2.7/dist-packages/twisted/__init__.pyc, but /opt/graphite/lib is being added to sys.path import pkg_resources Sending kill signal to pid 15873 – Nam Nguyen Nov 14 '13 at 07:34
  • I can start/stop using carbon-cache.py directly. However, it's trouble for me when I use upstart to stop/restart – Nam Nguyen Nov 14 '13 at 07:35
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/41159/discussion-between-erbdex-and-nam-nguyen) – erbdex Nov 14 '13 at 07:38