/srv/irclogs.ubuntu.com/2016/05/10/#upstart.txt

=== JanC is now known as Guest22660
=== JanC_ is now known as JanC
frewdoes anyone know if there is a way to detect a restart?  That is, I would like to run a command when a service is restarted automatically, but not when it is started via stop then start17:27
frewI sorta expect the start on reason or something to be in an env var?17:30
chrasfrew: yeah17:32
chrasyou can do this17:32
chrassec, lemme look for my code which does this17:32
frewawesome, thanks17:32
frewoh is it UPSTART_EVENTS ?17:32
* frew *just* found http://upstart.ubuntu.com/cookbook/#standard-environment-variables17:33
* frew would guess a "respawn" in UPSTART_EVENTS means it crashed17:33
chrasyeah you can check on that17:34
chrasso when you do an initctl restart you want another event to fire?17:35
chrasor when you kill the running process, and upstart restarts it automatically17:35
chrasor both?17:35
frewno, really all I want, if possible, is that if it crashes (or if I killed it directly)17:35
frewso the latter (I think)17:35
frewbasically if it restarted due to a crash17:36
chrasright, k, so i have an event which does this17:36
chrassec lemme pastebin it17:36
frewthanks17:36
chrashttps://pastebin.mozilla.org/887050117:37
chrasbut, when i test it, it doesnt trigger on an initctl restart $process17:37
frewwhich is the goal here.17:37
frewhuh, so are scripts bash?17:38
chrasmore or less17:38
chraswith a set -e17:38
frewok17:38
frewI assumed they'd be sh17:38
chraswell my sh is linked to bash17:38
frewmine's dash17:38
chrasi dont use dash17:38
frewgotcha.17:38
chrasdash does ... unexpected things17:38
frewheh17:38
frewso you install this upstart config17:39
frewand it captures basucally all events?17:39
frew(hence the JOB!=self_help, which is what this is)17:40
chrasyeah im having trouble getting it to trigger on a restart though17:41
frewrestart meaning a crash?17:42
chrasmy thing triggers on a crash17:42
chrasjust not an 'initctl restart'17:42
frewok that's how I want it17:42
frewyeah17:42
frewthat's what I want.17:42
frewif someone manually restarts, I think I'm ok with that not being logged especially17:42
frewthough it would be nice to know as well17:42
chrasi made this event back when i had heartbeat dying unexpectedly17:42
chrasand then i had a config file which took actiosn based on what happened17:43
chrasie17:43
chrasheartbeat XCPU echo "nas_self_help: heartbeat died unexpectedly with XCPU Signal, restarting" | wall -n17:43
chrasso heartbeat was getting a XCPU kill flag for whatever reason (ended up being a bug in heartbeat debug)17:43
chrasand then id wall it out for instance17:43
frewright my thought here is to either page or create an issue or osmething17:44
frewnot sure17:44
chrasand it does trigger on a stop / kill / etc17:44
chrasbut not sure about restart atm17:44
frewok well I need to get this installed and I'll see how well it works17:44
frewso GCONFIG and PCONFIG (currently) do nothing17:45
frewso key signal rest is like17:45
frewwho did what17:45
frewwhat they did17:46
frewand other info?17:46
frewor something?17:46
frewoh sorry I am reading this and learning more17:46
frewI hsould talk to my rubber duck before asking here17:46
chraswell thoes are just configs that i use17:47
frewright17:47
chrasi can paste thoes in the thing, sec17:47
frewthanks that'd be helpful17:47
chrashttps://pastebin.mozilla.org/887050317:48
chrasi guess the main thing i wanted you to originally see was the 'start on stopped JOB=${some_job}17:49
chrasand then have a task which does whatever you want in a script stanza17:50
frewright17:50
frewwell and having a single task that does it is very elegant17:50
frewI was gonna have a script I put in all my scripts17:51
chrasfrew: yeah i cant get it working in the context of an 'initctl restart'18:09
chrasas a workaround you could do an initctl emit in your pre-stop18:11
chrasyeah a restart never emits a 'stopping' or 'stopped' event18:27
frewchras: fwiw the z thing is not really needed anymore iirc18:31
chrasfrew: ug. i got it18:31
chrasits definately a bug18:31
frewyeah18:31
chrasif you have a pre-stop script18:31
chrasthen the job goes running -> pre-stop -> start18:32
chrasand never emits a stopping/stopped18:32
frewyou think the maintainers of upstart would fix it?18:32
frewI was telling my boss about this and he was a little hesitant since upstart is destined for the void18:32
frewbut so is everything so I'm gonna keep going18:32
chrasif you DONT have a pre-stop script, then it works as intended18:32
frewinteresting.18:32
chrasit MIGHT be this bug, https://bugs.launchpad.net/upstart/+bug/70380018:32
frewbtw logger ~~ syslog?18:33
frewI'd say even if it is that bug, that bug is 4y old and will probably never get fixed18:33
chrasright18:33
frewI think I'm gonna make an "ANY" job too.18:34
frewat least so I can get started with this reasonably.18:34
chrasanyways, sorry couldnt be more help18:36
frewno way this is great18:37
frewyou 100% solved my issue and added more18:37
chrasgreat18:38
frewchras: actually I guess I maybe misunderstand you; I don't get logging or anything for a respawn (crash and restart)20:15
frewis that what you were saying is broken?20:15
chrashi20:17
chrask the quick summary was20:18
chrasIF you have a pre-stop, then an initctl restart does start -> pre-stop -> start , and skips doing a stopping, or stopped event20:18
frewok that's what I thought you were saying.20:18
frewthis is neither a start, stop, nor restart, but a service that starts and crashes after about 3s, consistently20:19
frewand I get no events20:19
chrasso your event fails to start at all20:20
chrasand thats what you're trying to catch ?20:20
frewwell I mean, it never forks, so as long as upstart knows, it worked correctly for 3s20:21
frewand then crashed20:21
frewbut yes, I'm trying to catch an error causing a respawn, likely a compile error20:21
chrasright. ok, i think i understand20:21
frewthough it could have been running for three hours20:21
chrasso your daemon forks, and upstart isnt detecting that it died?20:21
frewit would still be the same situation20:21
frewno20:21
frewit never forks20:21
frewit just exec's20:21
chrasah20:21
frewhence upstart not knowing it's ready20:22
chrasdoes your upstart throw an error like20:22
chrasmain process ($pid) terminated with status $exit?20:23
frewif it would place an error in the syslog, no20:23
frewnot sure where else to look20:23
chrascheck dmesg20:23
chrasdo you 'console log' ?20:23
frewI don't know?20:24
chrasmind putting your event on pastebin?20:24
frewyeah it's super basic20:24
frewhttps://gist.github.com/frioux/0e4e4c1dc0b02f82a9a1a327ae55c24820:25
chrasright k20:25
chrasi think you want to add a 'console log' to that20:26
chrasso you can get some minimal logging20:26
frewok20:26
frew(fwiw I know why it's crashing, I just want to be able to detect better in the future)20:26
chrasand you're trying to throw another event when that one fails to start?20:27
frewwell, I just want to find out, somehow20:27
freworiginally I was gonna write a pre-start that looked at 20:28
frewUPSTART_EVENTS20:28
frewand if respawn was in there, do a thing20:28
frewbut your solution was a lot more elegan20:28
chrasso, when i do this20:29
chrashttps://pastebin.mozilla.org/887054320:32
chraswhen my main process ends with a non 0 exit code (which i assume is your failureA)20:32
chrasit still triggers my self_help20:32
frewsurely it is20:32
frewalthough... it's probably exiting 25520:33
frewany chance upstart ignores high errors?20:33
chrasshould be anything non-zero20:33
frewok20:33
chrasunless you told it to ignore certain exit codes20:33
frewI don't even know how I'd do that?20:33
frewwhere would that be done20:33
chrasits just a main-config command20:33
chrassec20:34
chraslemme find it20:34
chrashttp://upstart.ubuntu.com/cookbook/#normal-exit20:35
frewwell I showed you the whole file20:35
frewunless you can glboally do it, I didn't do that20:35
chrasyeah so itll be non-zero exit codes20:36
chraswill cause it to fail20:36
chrasso my self_help event isnt triggering on your thing exiting weirdly?20:37
frewcorrect20:38
frewI have to admit though20:38
chrasdoes your reaper fork ?20:38
chrasor is it a foreground process20:38
frewI did clean up your self_help thing to be shorter and simpler20:38
frewno it doesn't fork20:38
frewit's foreground20:38
frewlemme paste the changes I made20:39
chrasdid you run an initctl reload-configuration?20:39
frewthey shouldn't harm anything20:39
chrasto get the new event20:39
frewyes20:39
chrasdoes an initctl start self_help work?20:39
frewwell I get output about other services20:39
frewbut let's see20:39
chrasah interesting so you know it IS working, just not with your reaper?20:39
frewoh wait20:40
frewwtf20:40
frewinitctl: Unknown parameter: JOB20:40
frewdoes that mean antyhing to you?20:40
chrasyeah20:40
chrasinitctl start self_help JOB=test20:40
chrasthats just the instancing stuff triggering20:40
chrasnormally JOB is emitted automatically by other upstart events20:41
frewinitctl: Job failed to start20:41
frewright20:41
frewno obvious reason why it's failing20:41
chrashm, pastebin it ?20:41
frewthe modified self_help or what?20:41
chrasyea20:41
frewk20:41
frewhttps://gist.github.com/frioux/953fe2f4b950c2bef58521f0ca0e0ad920:42
frewshould be effectively the same, but work with any POSIX shell (and only allow one extra config file)20:42
frew(and I renamed it watchdog)20:42
chrasright20:43
chrasyou're using dash right?20:45
frewI wrote it with dash in mind, since we are moving to dash soon, but it's still bash now (12.04)20:45
frewoh no20:46
chrasits just a syntax error for me20:46
frew12.04 is dash20:46
frewoh?20:46
* frew eyeballs20:46
chras./foo.script: 24: ./foo.script: Syntax error: "(" unexpected (expecting "then")20:47
frewI wonder why that's wrong20:47
frewit's supposed to work20:47
frew`(expression)  True if expression is true.` from dash(1)20:47
chrasyeah it looks right20:48
chrassec, seeing if i can fix20:48
frewcan repro fwiw20:48
frewfwiw the ()'s are not needed, since -o binds more tightly than -a20:49
frewbut I thoguht it made it easier to read20:49
frewdash -c '[ ( -f /bin/dash ) ] && echo 1'20:50
frewI think this must be a bug in dash.20:51
chrasdash does unexpected things :P20:52
frewI never claimed it was perfect20:52
frewI jsut can't switch what /bin/sh is20:53
frewok I'll just leave out the () for now20:54
chrasyeah i cant use ()'s in dash for whatever reason20:54
frewoh derp21:06
frewdash -c '[ \( -f /bin/dash \) ] && echo true'21:06
frewgotta escape them for some reason21:07
frewmust be a history expansion or something.21:08
frewnonetheless I do see this: `self_help(pt-heartbeat-update-mysql): caught job[pt-heartbeat-update-mysql] instance[] process[respawn] result[failed] status[] signal[]` in syslog, but nothing about my reaper21:09
chrashm21:20
frewtrying a different route, but 90% sure that upstart is just not creating an event for that21:20
frewI don't see where it would in the lifecycle anyway, fwiw21:20
chrasyou can try bumping the debug up with log-priority debug21:21
chrasand see where its dying21:21
frewhm.21:23
frewI have a theory.21:23
* frew "simplifies"21:23
frewyeah, it catches start and stop, but not respawn21:28
chrasrespawn, when the main process dies?21:29
frewyeah21:29
frewrespawn is an even that's not real, to be clear21:29
frewI thought it might be21:29
frews/even/event21:29
frewI sorta thing consuming events won't work for this, since there isn't one for what I'm thinking of21:30
chraslemme try here21:32
chrask so21:32
chraswe're triggering self_help/watchdog on the upstart event 'stopped'21:33
chrasafter something is completely stopped21:33
chrasfor it to also hit your respawn, you need to change that to be 'start on stopping ...'21:33
chrasi should make that change for my own needs as well i guess21:34
chraswith it only being set to 'stopped'21:37
chrasit will wait for upstart to give up on respawning before its triggered21:38
chraslike i suppose, its the difference between if your job fails 10 times in a row, and upstart gives up on it21:38
chrasgetting 10 emails, or 121:38
chrasif your watchdog sends email out at least.21:38
chrasoo, interesting though21:51
chrasthe respawn attempts have a result[ok] instead of a result[failed]21:52

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!