[05:12] I am trying to start multiple services with another service. However, I am having a hard time of getting it setup. I keep getting unknown job attendance. However, I can start attendance outside of the control no problem. http://pastebin.com/zN9fP0Gr === fedora_newb_ is now known as fedora_newb [09:14] fedora_newb: You should use events to manipulate job start. Never call "initctl start" directly without a good reason. A VERY good reason, and even then - don't. [09:15] If all you need is to change the start parameters of another job, make an .override with desired "start on" clause. === JanC is now known as Guest58470 === JanC_ is now known as JanC [19:30] Hello Upstart peoples [19:30] Is anyone around to assist with a question I have ? [19:30] Regarding script stanzas and exit codes [19:31] The issue I am having is parsing errors from apache startup [20:21] ruptwelve: What specifically you are "parsing" ? [20:21] So [20:21] I have an upstart config [20:21] that runs httpd with some arguments [20:22] when I run initctl start httpd I get the message: httpd start/running PID xxxx [20:22] Want an advice? Ditch as many "arguments" as possible. [20:22] Regardless if the apache server started or not [20:22] right [20:22] so event if I run just /usr/sbin/httpd [20:22] Tell apache to not daemonize. [20:22] Should I get an exit code ? [20:23] You ALWAYS get an exit code, when program exits. [20:23] right [20:23] but I always get a 0 [20:23] even if Apache did not start [20:23] Yes. So, again. [20:24] FFFFFFFFFFFFFFF [20:25] 1. If you are delegating all active scripting to other daemons or running mpm-itk, tell apache to not daemonize. [20:25] 2. If you are using active content filters, then see cookbook, "tracking the wrong PID". [20:26] In either case, do not test it on live system. [20:26] This is not a live system so that is fine [20:26] And always ensure that initctl status reporting "stopped". [20:26] what I am trying to achieve here is to be sure weather apache did start or not [20:27] Before starting the job again. [20:27] Right [20:27] upstart will manage that by itself, once you set up PID tracking correctly. [20:27] I hope you do not use any wrapper scripts? [20:27] Allow me to paint a picture [20:28] Better pastebin your job script :) [20:28] sure one sec [20:28] That would be an image worth 1000 words. [20:31] so [20:31] http://pastebin.com/raw/CUYkRcGX [20:31] that is httpd.conf [20:31] under /etc/init/ [20:31] Use exec. Not script. [20:32] And use upstart to set ulimits. [20:32] And other vars. [20:33] And this is a part of the /etc/init.d/httpd [20:33] http://pastebin.com/raw/ZTCBNNBu [20:33] Which triggers initctl [20:34] If you have init/httpd.conf the init.d/httpd will only be called by idiots and degenerates. [20:35] well [20:35] "service" wrapper will find upstart/systemd scripts before init.d [20:35] right [20:35] but even if just using initctl [20:35] Just make sure you update-rc.d -f apache2 remove [20:36] Ok, to reiterate: [20:36] 1. You're using wrapper script. Thus making the job of finding the right PID to track unnecessarily hard. [20:37] 2. You're using runlevels instead of proper signals. start on local-filesystems and net-device-up IFACE!=lo is usually sufficient. [20:38] Also remove any "respawn" stanzas until your job is tracking the right pid. [20:38] Okay! Thank you for clearing some stuff up AnrDaemon [20:39] But I still don't understand why I cannot just get an exit code other than 0 from the initctl script ? [20:39] Even if I just run exit 1 [20:39] "exec exit 1" [20:40] if I run initctl start httpd [20:40] echo $? [20:40] I will always get 0 [20:41] Because "initctl start ..." sends signal to init daemon, and if signal is sent all proper, the exit code is a success. [20:41] right [20:41] That makes sense [20:41] Also I'm not sure "exit" is an actual binary. :D Try /bin/false [20:41] my bad :) I just ran exec exit 1 and got a 1 [20:41] so I did not test it [20:42] under script tho, it is still 0 [20:42] I'm very suspicious of any scripts in upstart job as of late. [20:42] Yeah, unfortunately due to the /bin/sh -e [20:42] if any of the commands fail, the script exits [20:43] and it just ends there [20:43] no error or nothing :/ [20:48] Plus you have test ${PIPESTATUS[0]} -eq 0 [20:49] yeah that is just to test the output before tee [20:50] but even if I have /usr/sbin/httpd -D FOREGROUND [20:50] i still get the same result [20:51] http://pastebin.com/M6AUXFzy [20:51] Something like that. (untested) [20:52] Err, typo in #14. [20:54] I see :) [20:54] the expect for marks the service as running [20:54] even though it is not [20:55] That's why I said it needs testing and correct handling. [20:55] http://upstart.ubuntu.com/cookbook/#expect [20:56] Well thank AnrDaemon, you were of assitance [20:56] I spent the entire day googling this [20:56] Googling what? :D [20:56] upstart and exit codes :D [20:56] I was hoping that it would return an exit code of the script block [20:56] Sorry, it was on my todo list to make apache2 run from upstart, but I didn't find time to actually port it. [20:57] but I guess it doesn't work [20:57] as I expected [20:57] Well, the thing is it starts [20:57] It works but not the way you expect. [20:57] I can have it run no problem [20:57] I just want to make sure it runs with error handling [20:57] Just ask yourself one question: when the system is booting, where to return the exit codes? [20:57] Hmm, let me explain a bit [20:57] upstart is designed to do precisely that. [20:58] I have this big wrapper application around the server(s) [20:58] that restarts the apache server once you push new data to it [20:58] To not just start the job, but also suprvise its execution. [20:58] new configs / applications / whatever [20:58] That's parallel to init daemon's job. [20:58] and it runs service stop httpd [20:58] copies new stuff [20:58] service start http d [20:59] Well, that's the wrong way to do it… [20:59] and from the applications perspective everything started fine [20:59] You don't need to stop httpd just to upload new data. [20:59] LEarn the power of atomic operations ;) [20:59] as there is no error from initctl regarding starting apache [20:59] ah no :) [20:59] well I can also upload a new version of httpd.conf :) [21:00] Well, then you are probably better off with something like LXD or docker. [21:00] And I can have a user make a mistake in the httpd.conf [21:00] and he wont know why apache did not start [21:00] it will just show as started [21:00] right! :) You have a point, there are so many better ways to do this [21:00] but that is not my call ;) [21:00] I am just trying to find the best solution here [21:01] No, if apache did not start, it will not be shown as started. [21:01] Correct! [21:02] Also, make pre-start script with apachectl -t [21:02] But the actual output of initctl start httpd will be good [21:02] yes I did that :) [21:02] but that just checks the configuration [21:02] I would like to be more resiliant [21:02] Well, it have more options… [21:02] for example if the socket is occupied [21:02] It is as resilient as possible. [21:02] Wish there was a dry-run option for apache :) [21:02] If pre-start script fails, the job will never run in forst place. [21:03] first** [21:03] And thus you can take actions. [21:04] That is fine [21:04] when it comes down to config [21:04] but is there an option to dry-run apache? [21:04] Like a test run, to just make sure it will run - and if so, just continue with upstart [21:07] That's what apachectl do. Else it wouldn't be able to test config. [21:08] Since module-dependent options can only be recognized by the respective modules. [21:08] but what happens if there a port already occupied ? [21:08] that is if the socket is not available [21:08] hmm let me test that :) [21:08] Nothing. (If we talk about test runs.) [21:09] oh nice [21:09] It actually tests that <3 [21:09] THERE IS MY SOLUTION [21:09] You Sir deserve a beer [21:10] Sure. Golden Barrel light 0.5 will suffice. In glass, please. [21:10] I guess Golden Barrel is American? [21:10] Russian! [21:10] hehehe [21:18] I guess it testing if the port is occupied by some other application? [21:18] Correct [21:18] I am just trying to finish up the .conf file [21:18] I will share once I am done :) [21:19] Ahha. 'Cause I've tried to find a way for it to break when it is already running. With no success. [21:20] I've 2 weeks since I moved most of my services into containers. And there's at most 2 services running per each. [21:20] Ok, plus Samba where it is applicable. [21:20] (I.e. MySQL container runs only MySQL with minimum support.)