From stuart at stuartk.com  Sat Feb  1 01:38:42 2014
From: stuart at stuartk.com (Stuart Knightley)
Date: Fri, 31 Jan 2014 17:38:42 -0800
Subject: setuid, pre-start and stop 
Message-ID: <201deae0-5226-4265-9790-2f2fe3457f34@email.android.com>

Hi all, 

I have an upstart script with setuid, and a pre-start script that I wish to call `stop` in. However the user I've changed to does not have permission to call stop. I realise that I can exit with a non-zero status but the previous thread on this mailing list indicates this is not best practice. 

Does anyone have any suggestions? 

Thanks, 
Stuart 



From steve.langasek at canonical.com  Sat Feb  1 21:17:20 2014
From: steve.langasek at canonical.com (Steve Langasek)
Date: Sat, 1 Feb 2014 16:17:20 -0500
Subject: setuid, pre-start and stop
In-Reply-To: <201deae0-5226-4265-9790-2f2fe3457f34@email.android.com>
References: <201deae0-5226-4265-9790-2f2fe3457f34@email.android.com>
Message-ID: <20140201211720.GB14289@virgil.dodds.net>

Hi Stuart,

On Fri, Jan 31, 2014 at 05:38:42PM -0800, Stuart Knightley wrote:

> I have an upstart script with setuid, and a pre-start script that I wish
> to call `stop` in.  However the user I've changed to does not have
> permission to call stop.  I realise that I can exit with a non-zero status
> but the previous thread on this mailing list indicates this is not best
> practice.

> Does anyone have any suggestions? 

In general, anything you can do in a {pre,post}-{start,stop} script, you can
also do in a separate job with a 'start on {start,stopp}{ed,ing}' rule.  And
in a case such as this where you are running the main job under some sort of
access controls, this is what you need to do.

Something like the following should work:

start on starting main_job
script
    if $condition; then
        stop main_job
    fi
end script

Hope that helps,
-- 
Steve Langasek                   Give me a lever long enough and a Free OS
Debian Developer                   to set it on, and I can move the world.
Ubuntu Developer                                    http://www.debian.org/
slangasek at ubuntu.com                                     vorlon at debian.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140201/c6b416d9/attachment.pgp>

From stuart at stuartk.com  Tue Feb  4 06:21:25 2014
From: stuart at stuartk.com (Stuart Knightley)
Date: Mon, 3 Feb 2014 22:21:25 -0800
Subject: setuid, pre-start and stop
In-Reply-To: <20140201211720.GB14289@virgil.dodds.net>
References: <201deae0-5226-4265-9790-2f2fe3457f34@email.android.com>
 <20140201211720.GB14289@virgil.dodds.net>
Message-ID: <5442E4FC73B64789A2F8565D707095FB@stuartk.com>

On Saturday, February 1, 2014 at 1:17 PM, Steve Langasek wrote:
> In general, anything you can do in a {pre,post}-{start,stop} script, you can
> also do in a separate job with a 'start on {start,stopp}{ed,ing}' rule. And
> in a case such as this where you are running the main job under some sort of
> access controls, this is what you need to do.
> 
> Something like the following should work:
> 
> start on starting main_job
> script
> if $condition; then
> stop main_job
> fi
> end script
> 
> Hope that helps,
Ah yes, hadn't thought of that approach, that helps a lot! Thanks very much.

Stuart
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140203/85b22c17/attachment.html>

From noreply at launchpad.net  Tue Feb  4 11:33:22 2014
From: noreply at launchpad.net (noreply at launchpad.net)
Date: Tue, 04 Feb 2014 11:33:22 -0000
Subject: [Branch ~upstart-devel/upstart/trunk] Rev 1593: *
 extra/man/socket-event.7: Environment variable is UPSTART_EVENTS, not
Message-ID: <20140204113322.12596.84623.launchpad@ackee.canonical.com>

------------------------------------------------------------
revno: 1593
fixes bug: https://launchpad.net/bugs/1275308
committer: James Hunt <james.hunt at ubuntu.com>
branch nick: upstart
timestamp: Tue 2014-02-04 11:32:56 +0000
message:
  * extra/man/socket-event.7: Environment variable is UPSTART_EVENTS, not
    UPSTART_JOB (LP: #1275308).
modified:
  ChangeLog
  extra/man/socket-event.7


--
lp:upstart
https://code.launchpad.net/~upstart-devel/upstart/trunk

Your team Upstart Reviewers is subscribed to branch lp:upstart.
To unsubscribe from this branch go to https://code.launchpad.net/~upstart-devel/upstart/trunk/+edit-subscription
-------------- next part --------------
A non-text attachment was scrubbed...
Name: revision-diff.txt
Type: text/x-diff
Size: 858 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140204/97fcb4f5/attachment.diff>

From james.hunt at canonical.com  Tue Feb  4 15:31:32 2014
From: james.hunt at canonical.com (James Hunt)
Date: Tue, 04 Feb 2014 15:31:32 -0000
Subject: [Merge] lp:~cameronnemo/upstart/ipv6 into lp:upstart
In-Reply-To: <20140204040723.13972.15231.launchpad@ackee.canonical.com>
Message-ID: <20140204153132.1530.78821.codereview@soybean.canonical.com>

Review: Needs Fixing

Hi Cameron,

Thanks to you and Kai for undertaking this new feature!

A few comments:

* extra/upstart-socket-bridge.c:
  - epoll_watcher():
    - 'break' has been lost from end of the AF_INET block.
    - buffer should not use nih_local (as that is only for allocated storage) and should really be at the
      top of the 'for' block.
    - AF_INET6 block missing a 'break' at the end.
  - job_add_socket(): '! strcmp (*env, "ADDR")' needs to be updated for IPv6 (using inet_pton() rather than
    inet_aton() maybe?).

I tried testing this using the new IPv6 example from socket-event.7, but I think the last comment above is causing the job to be rejected.


-- 
https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599
Your team Upstart Reviewers is subscribed to branch lp:upstart.


From camerontnorman at gmail.com  Tue Feb  4 04:07:24 2014
From: camerontnorman at gmail.com (Cameron Norman)
Date: Tue, 04 Feb 2014 04:07:24 -0000
Subject: [Merge] lp:~cameronnemo/upstart/ipv6 into lp:upstart
Message-ID: <20140204040723.13972.15231.launchpad@ackee.canonical.com>

Cameron Norman has proposed merging lp:~cameronnemo/upstart/ipv6 into lp:upstart.

Requested reviews:
  Upstart Reviewers (upstart-reviewers)
Related bugs:
  Bug #942955 in upstart : "upstart-socket-bridge doesn't support ipv6 sockets"
  https://bugs.launchpad.net/upstart/+bug/942955

For more details, see:
https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599

Adds the inet6 option for the socket event parameter PROTO and the corresponding man page examples.
-- 
https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599
Your team Upstart Reviewers is requested to review the proposed merge of lp:~cameronnemo/upstart/ipv6 into lp:upstart.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: review-diff.txt
Type: text/x-diff
Size: 5104 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140204/9bc59e3a/attachment.diff>

From james.hunt at canonical.com  Wed Feb  5 11:03:41 2014
From: james.hunt at canonical.com (James Hunt)
Date: Wed, 05 Feb 2014 11:03:41 -0000
Subject: [Merge] lp:~cameronnemo/upstart/ipv6 into lp:upstart
In-Reply-To: <20140204040723.13972.15231.launchpad@ackee.canonical.com>
Message-ID: <20140205110340.1699.2845.codereview@gac.canonical.com>

Review: Needs Fixing

Hi Cameron,

Thanks for updating. There is still a problem with inet_pton(): the test should error if the value returned != 1 since currently all valid IPv6 addresses are rejected. Please could you fix that up and test.

I'm testing this with a job that specifies:

start on socket PROTO=inet6 PORT=80 ADDR=::1
script
echo ok
set
end script

Then running the event monitor:

$ upstart-monitor &

Then, running the bridge in debug mode in the foreground:

$ sudo ./upstart-socket-bridge --debug

And finally connecting to port 80 via IPv6:

$ echo foo | socat 'tcp6-connect:[::1]:80' -

Thanks!

-- 
https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599
Your team Upstart Reviewers is subscribed to branch lp:upstart.


From gonzalez.mariano.gabriel at gmail.com  Wed Feb  5 17:55:59 2014
From: gonzalez.mariano.gabriel at gmail.com (=?ISO-8859-1?Q?Mariano_Gonz=E1lez?=)
Date: Wed, 5 Feb 2014 15:55:59 -0200
Subject: Need help to write upstart script for newrelic plugin
Message-ID: <CAHknVTWvoOmhF-oJ1ApssQ49GwL37D_8vtOQtt-HzA=DQ-xYHw@mail.gmail.com>

Hi there.

I'm trying to monitor a newrelic plugin service with upstart in CentOS 6.x.

Here's newrelic plugin script: https://gist.github.com/Mariano-gon/8829482

Here's my upstart script: https://gist.github.com/Mariano-gon/8827034

When I try to restart it, it'll respawn x times and then stops itself.

Here're the log lines: https://gist.github.com/Mariano-gon/8829533

Any advice? thanks!!



-- 
Mariano Gabriel Gonz?lez
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140205/673c14f2/attachment.html>

From clint at ubuntu.com  Thu Feb  6 06:26:07 2014
From: clint at ubuntu.com (Clint Byrum)
Date: Wed, 05 Feb 2014 22:26:07 -0800
Subject: Need help to write upstart script for newrelic plugin
In-Reply-To: <CAHknVTWvoOmhF-oJ1ApssQ49GwL37D_8vtOQtt-HzA=DQ-xYHw@mail.gmail.com>
References: <CAHknVTWvoOmhF-oJ1ApssQ49GwL37D_8vtOQtt-HzA=DQ-xYHw@mail.gmail.com>
Message-ID: <1391667747-sup-130@fewbar.com>

Excerpts from Mariano Gonz?lez's message of 2014-02-05 09:55:59 -0800:
> Hi there.
> 
> I'm trying to monitor a newrelic plugin service with upstart in CentOS 6.x.
> 
> Here's newrelic plugin script: https://gist.github.com/Mariano-gon/8829482
> 
> Here's my upstart script: https://gist.github.com/Mariano-gon/8827034
> 
> When I try to restart it, it'll respawn x times and then stops itself.
> 
> Here're the log lines: https://gist.github.com/Mariano-gon/8829533
> 

https://gist.github.com/Mariano-gon/8827034#file-newrelic_rs-conf-L7

exec means you will never reach the next line. There is a declarative
way to change dirs, so you don't need the script stanza at all:

---
respawn
chdir /path/to/plugin_installation
exec bundle exec ./bin/newrelic_rs
---

Note that if you want it to start at boot, don't use any of the weird
compound start ons you see:

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

Those two should be fine.


From gonzalez.mariano.gabriel at gmail.com  Thu Feb  6 12:12:03 2014
From: gonzalez.mariano.gabriel at gmail.com (=?ISO-8859-1?Q?Mariano_Gonz=E1lez?=)
Date: Thu, 6 Feb 2014 10:12:03 -0200
Subject: Need help to write upstart script for newrelic plugin
In-Reply-To: <1391667747-sup-130@fewbar.com>
References: <CAHknVTWvoOmhF-oJ1ApssQ49GwL37D_8vtOQtt-HzA=DQ-xYHw@mail.gmail.com>
 <1391667747-sup-130@fewbar.com>
Message-ID: <CAHknVTXU_JzJM-SuB50zjCje+ed1u6v+TaU3m7YfhEvwiNa=Lw@mail.gmail.com>

Thanks Clint!

I've edited the .conf file to: https://gist.github.com/Mariano-gon/8842908

>From messages.log: https://gist.github.com/Mariano-gon/8842922

And newrelic agent never starts.
This plugin/agent needs to be run (bundle exec ./bin/newrelic_rs) inside
/path_installation/newrelic_rs_dfw/ (I think that's because it is where the
right gem is installed). So, my guess would be that initctl is not
relocating itself in /path_installation/newrelic_rs_dfw/ to run the budle
exec and that's why it's falling to start. Could it be?

Thanks!




On 6 February 2014 03:26, Clint Byrum <clint at ubuntu.com> wrote:

> Excerpts from Mariano Gonz?lez's message of 2014-02-05 09:55:59 -0800:
> > Hi there.
> >
> > I'm trying to monitor a newrelic plugin service with upstart in CentOS
> 6.x.
> >
> > Here's newrelic plugin script:
> https://gist.github.com/Mariano-gon/8829482
> >
> > Here's my upstart script: https://gist.github.com/Mariano-gon/8827034
> >
> > When I try to restart it, it'll respawn x times and then stops itself.
> >
> > Here're the log lines: https://gist.github.com/Mariano-gon/8829533
> >
>
> https://gist.github.com/Mariano-gon/8827034#file-newrelic_rs-conf-L7
>
> exec means you will never reach the next line. There is a declarative
> way to change dirs, so you don't need the script stanza at all:
>
> ---
> respawn
> chdir /path/to/plugin_installation
> exec bundle exec ./bin/newrelic_rs
> ---
>
> Note that if you want it to start at boot, don't use any of the weird
> compound start ons you see:
>
> start on runlevel [2345]
> stop on runlevel [016]
>
> Those two should be fine.
>
> --
> upstart-devel mailing list
> upstart-devel at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/upstart-devel
>



-- 
Mariano Gabriel Gonz?lez
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140206/194f1c60/attachment.html>

From james.hunt at ubuntu.com  Thu Feb  6 13:21:53 2014
From: james.hunt at ubuntu.com (James Hunt)
Date: Thu, 06 Feb 2014 13:21:53 +0000
Subject: Need help to write upstart script for newrelic plugin
In-Reply-To: <CAHknVTXU_JzJM-SuB50zjCje+ed1u6v+TaU3m7YfhEvwiNa=Lw@mail.gmail.com>
References: <CAHknVTWvoOmhF-oJ1ApssQ49GwL37D_8vtOQtt-HzA=DQ-xYHw@mail.gmail.com>
 <1391667747-sup-130@fewbar.com>
 <CAHknVTXU_JzJM-SuB50zjCje+ed1u6v+TaU3m7YfhEvwiNa=Lw@mail.gmail.com>
Message-ID: <52F38C71.8000903@ubuntu.com>

On 06/02/14 12:12, Mariano Gonz?lez wrote:
> Thanks Clint! 
> 
> I've edited the .conf file to: https://gist.github.com/Mariano-gon/8842908
> 
> From messages.log: https://gist.github.com/Mariano-gon/8842922
> 
> And newrelic agent never starts. 
Firstly, http://upstart.ubuntu.com/cookbook/#respawn - my advice would be to
drop respawn until you have the job atleast starting and stopping normally.

Has any output been logged to /var/log/upstart/newrelic.log?

> This plugin/agent needs to be run (bundle exec ./bin/newrelic_rs) inside
> /path_installation/newrelic_rs_dfw/ (I think that's because it is where the
> right gem is installed). So, my guess would be that initctl is not relocating
> itself in /path_installation/newrelic_rs_dfw/ to run the budle exec and that's
> why it's falling to start. Could it be?
The most likely problem is that newrelic needs certain environment variables set
that are not set by default; in terms of standard environment variables, Upstart
will only set TERM and PATH. If you want to set others, use the env stanza:

http://upstart.ubuntu.com/cookbook/#env

To help track down why your service is not starting:

http://upstart.ubuntu.com/cookbook/#see-the-environment-a-job-runs-in
http://upstart.ubuntu.com/cookbook/#checking-how-a-service-might-react-when-run-as-a-job

This link shows you how to diff the environment that newrelic *does* run in
versus the environment provided by upstart:

http://upstart.ubuntu.com/cookbook/#determining-why-your-service-fails-to-start

If you use procenv, look at the 'current directory (cwd):' output too which will
correspond to what you specified for the chdir stanza in the job configuration.

> 
> Thanks!
> 
> 
> 
> 
> On 6 February 2014 03:26, Clint Byrum <clint at ubuntu.com
> <mailto:clint at ubuntu.com>> wrote:
> 
>     Excerpts from Mariano Gonz?lez's message of 2014-02-05 09:55:59 -0800:
>     > Hi there.
>     >
>     > I'm trying to monitor a newrelic plugin service with upstart in CentOS 6.x.
>     >
>     > Here's newrelic plugin script: https://gist.github.com/Mariano-gon/8829482
>     >
>     > Here's my upstart script: https://gist.github.com/Mariano-gon/8827034
>     >
>     > When I try to restart it, it'll respawn x times and then stops itself.
>     >
>     > Here're the log lines: https://gist.github.com/Mariano-gon/8829533
>     >
> 
>     https://gist.github.com/Mariano-gon/8827034#file-newrelic_rs-conf-L7
> 
>     exec means you will never reach the next line. There is a declarative
>     way to change dirs, so you don't need the script stanza at all:
> 
>     ---
>     respawn
>     chdir /path/to/plugin_installation
>     exec bundle exec ./bin/newrelic_rs
>     ---
> 
>     Note that if you want it to start at boot, don't use any of the weird
>     compound start ons you see:
> 
>     start on runlevel [2345]
>     stop on runlevel [016]
> 
>     Those two should be fine.
> 
>     --
>     upstart-devel mailing list
>     upstart-devel at lists.ubuntu.com <mailto:upstart-devel at lists.ubuntu.com>
>     Modify settings or unsubscribe at:
>     https://lists.ubuntu.com/mailman/listinfo/upstart-devel
> 
> 
> 
> 
> -- 
> Mariano Gabriel Gonz?lez
> 
> 

Kind regards,

James.
--
James Hunt
____________________________________
#upstart on freenode
http://upstart.ubuntu.com/cookbook
https://lists.ubuntu.com/mailman/listinfo/upstart-devel


From gonzalez.mariano.gabriel at gmail.com  Thu Feb  6 13:52:18 2014
From: gonzalez.mariano.gabriel at gmail.com (=?ISO-8859-1?Q?Mariano_Gonz=E1lez?=)
Date: Thu, 6 Feb 2014 11:52:18 -0200
Subject: Need help to write upstart script for newrelic plugin
In-Reply-To: <52F38C71.8000903@ubuntu.com>
References: <CAHknVTWvoOmhF-oJ1ApssQ49GwL37D_8vtOQtt-HzA=DQ-xYHw@mail.gmail.com>
 <1391667747-sup-130@fewbar.com>
 <CAHknVTXU_JzJM-SuB50zjCje+ed1u6v+TaU3m7YfhEvwiNa=Lw@mail.gmail.com>
 <52F38C71.8000903@ubuntu.com>
Message-ID: <CAHknVTUSazh8a2--jshwFy6cmXuXHRtWNT6PLxXJV=bTYjp6og@mail.gmail.com>

James, I've tried to insert debug and procenv in my pre-start script, none
of them created any .log file in /tmp/

First:

start on..
stop on..

script

echo "DEBUG: `set`" >> /tmp/myjob.log

end script

respawn
chdir /opt/turner/services/newrelic/newrelic_rs_dfw
exec bundle exec ./bin/newrelic_rs

The service respawned 10 times and then got killed.

Second:

start on..
stop on..

script
exec procenv --file=/tmp/procenv-job.log --exec -- bundle exec
./bin/newrelic_rs
end script

respawn
chdir /opt/turner/services/newrelic/newrelic_rs_dfw
exec bundle exec ./bin/newrelic_rs

Again got respawned and killed. No .log file in /tmp.

I think I'm doing something wrong but cannot find it out.

Thanks and sorry for the dumbness, I'm just starting with upstart scripts.




On 6 February 2014 10:21, James Hunt <james.hunt at ubuntu.com> wrote:

> On 06/02/14 12:12, Mariano Gonz?lez wrote:
> > Thanks Clint!
> >
> > I've edited the .conf file to:
> https://gist.github.com/Mariano-gon/8842908
> >
> > From messages.log: https://gist.github.com/Mariano-gon/8842922
> >
> > And newrelic agent never starts.
> Firstly, http://upstart.ubuntu.com/cookbook/#respawn - my advice would be
> to
> drop respawn until you have the job atleast starting and stopping normally.
>
> Has any output been logged to /var/log/upstart/newrelic.log?
>
> > This plugin/agent needs to be run (bundle exec ./bin/newrelic_rs) inside
> > /path_installation/newrelic_rs_dfw/ (I think that's because it is where
> the
> > right gem is installed). So, my guess would be that initctl is not
> relocating
> > itself in /path_installation/newrelic_rs_dfw/ to run the budle exec and
> that's
> > why it's falling to start. Could it be?
> The most likely problem is that newrelic needs certain environment
> variables set
> that are not set by default; in terms of standard environment variables,
> Upstart
> will only set TERM and PATH. If you want to set others, use the env stanza:
>
> http://upstart.ubuntu.com/cookbook/#env
>
> To help track down why your service is not starting:
>
> http://upstart.ubuntu.com/cookbook/#see-the-environment-a-job-runs-in
>
> http://upstart.ubuntu.com/cookbook/#checking-how-a-service-might-react-when-run-as-a-job
>
> This link shows you how to diff the environment that newrelic *does* run in
> versus the environment provided by upstart:
>
>
> http://upstart.ubuntu.com/cookbook/#determining-why-your-service-fails-to-start
>
> If you use procenv, look at the 'current directory (cwd):' output too
> which will
> correspond to what you specified for the chdir stanza in the job
> configuration.
>
> >
> > Thanks!
> >
> >
> >
> >
> > On 6 February 2014 03:26, Clint Byrum <clint at ubuntu.com
> > <mailto:clint at ubuntu.com>> wrote:
> >
> >     Excerpts from Mariano Gonz?lez's message of 2014-02-05 09:55:59
> -0800:
> >     > Hi there.
> >     >
> >     > I'm trying to monitor a newrelic plugin service with upstart in
> CentOS 6.x.
> >     >
> >     > Here's newrelic plugin script:
> https://gist.github.com/Mariano-gon/8829482
> >     >
> >     > Here's my upstart script:
> https://gist.github.com/Mariano-gon/8827034
> >     >
> >     > When I try to restart it, it'll respawn x times and then stops
> itself.
> >     >
> >     > Here're the log lines: https://gist.github.com/Mariano-gon/8829533
> >     >
> >
> >     https://gist.github.com/Mariano-gon/8827034#file-newrelic_rs-conf-L7
> >
> >     exec means you will never reach the next line. There is a declarative
> >     way to change dirs, so you don't need the script stanza at all:
> >
> >     ---
> >     respawn
> >     chdir /path/to/plugin_installation
> >     exec bundle exec ./bin/newrelic_rs
> >     ---
> >
> >     Note that if you want it to start at boot, don't use any of the weird
> >     compound start ons you see:
> >
> >     start on runlevel [2345]
> >     stop on runlevel [016]
> >
> >     Those two should be fine.
> >
> >     --
> >     upstart-devel mailing list
> >     upstart-devel at lists.ubuntu.com <mailto:
> upstart-devel at lists.ubuntu.com>
> >     Modify settings or unsubscribe at:
> >     https://lists.ubuntu.com/mailman/listinfo/upstart-devel
> >
> >
> >
> >
> > --
> > Mariano Gabriel Gonz?lez
> >
> >
>
> Kind regards,
>
> James.
> --
> James Hunt
> ____________________________________
> #upstart on freenode
> http://upstart.ubuntu.com/cookbook
> https://lists.ubuntu.com/mailman/listinfo/upstart-devel
>



-- 
Mariano Gabriel Gonz?lez
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140206/27316470/attachment-0001.html>

From james.hunt at ubuntu.com  Thu Feb  6 14:21:33 2014
From: james.hunt at ubuntu.com (James Hunt)
Date: Thu, 06 Feb 2014 14:21:33 +0000
Subject: Need help to write upstart script for newrelic plugin
In-Reply-To: <CAHknVTUSazh8a2--jshwFy6cmXuXHRtWNT6PLxXJV=bTYjp6og@mail.gmail.com>
References: <CAHknVTWvoOmhF-oJ1ApssQ49GwL37D_8vtOQtt-HzA=DQ-xYHw@mail.gmail.com>
 <1391667747-sup-130@fewbar.com>
 <CAHknVTXU_JzJM-SuB50zjCje+ed1u6v+TaU3m7YfhEvwiNa=Lw@mail.gmail.com>
 <52F38C71.8000903@ubuntu.com>
 <CAHknVTUSazh8a2--jshwFy6cmXuXHRtWNT6PLxXJV=bTYjp6og@mail.gmail.com>
Message-ID: <52F39A6D.5000504@ubuntu.com>

On 06/02/14 13:52, Mariano Gonz?lez wrote:
> James, I've tried to insert debug and procenv in my pre-start script, none of
> them created any .log file in /tmp/
> 
> First: 
> 
> start on..
> stop on..
> 
> script
> 
> echo "DEBUG: `set`" >> /tmp/myjob.log
> 
> end script
> 
> respawn
> chdir /opt/turner/services/newrelic/newrelic_rs_dfw
> exec bundle exec ./bin/newrelic_rs
> 
> The service respawned 10 times and then got killed.
> 
> Second:
> 
> start on..
> stop on..
> 
> script
> exec procenv --file=/tmp/procenv-job.log --exec -- bundle exec ./bin/newrelic_rs
> end script
You don't need the script/end script stanzas - just specify the following in the
job:

exec procenv --file=/tmp/procenv-job.log --exec -- bundle exec ./bin/newrelic_rs

Please check that your job is valid using:

$ init-checkconf /etc/init/newrelic.conf

... then start the job manually and look for the logs:

$ sudo start newrelic

If no joy, feel free to join the #upstart irc channel on freenode to discuss
further.

> 
> respawn
> chdir /opt/turner/services/newrelic/newrelic_rs_dfw
> exec bundle exec ./bin/newrelic_rs
> 
> Again got respawned and killed. No .log file in /tmp.
> 
> I think I'm doing something wrong but cannot find it out.
> 
> Thanks and sorry for the dumbness, I'm just starting with upstart scripts.
> 
> 
> 
> 
> On 6 February 2014 10:21, James Hunt <james.hunt at ubuntu.com
> <mailto:james.hunt at ubuntu.com>> wrote:
> 
>     On 06/02/14 12:12, Mariano Gonz?lez wrote:
>     > Thanks Clint!
>     >
>     > I've edited the .conf file to: https://gist.github.com/Mariano-gon/8842908
>     >
>     > From messages.log: https://gist.github.com/Mariano-gon/8842922
>     >
>     > And newrelic agent never starts.
>     Firstly, http://upstart.ubuntu.com/cookbook/#respawn - my advice would be to
>     drop respawn until you have the job atleast starting and stopping normally.
> 
>     Has any output been logged to /var/log/upstart/newrelic.log?
> 
>     > This plugin/agent needs to be run (bundle exec ./bin/newrelic_rs) inside
>     > /path_installation/newrelic_rs_dfw/ (I think that's because it is where the
>     > right gem is installed). So, my guess would be that initctl is not relocating
>     > itself in /path_installation/newrelic_rs_dfw/ to run the budle exec and that's
>     > why it's falling to start. Could it be?
>     The most likely problem is that newrelic needs certain environment variables set
>     that are not set by default; in terms of standard environment variables, Upstart
>     will only set TERM and PATH. If you want to set others, use the env stanza:
> 
>     http://upstart.ubuntu.com/cookbook/#env
> 
>     To help track down why your service is not starting:
> 
>     http://upstart.ubuntu.com/cookbook/#see-the-environment-a-job-runs-in
>     http://upstart.ubuntu.com/cookbook/#checking-how-a-service-might-react-when-run-as-a-job
> 
>     This link shows you how to diff the environment that newrelic *does* run in
>     versus the environment provided by upstart:
> 
>     http://upstart.ubuntu.com/cookbook/#determining-why-your-service-fails-to-start
> 
>     If you use procenv, look at the 'current directory (cwd):' output too which will
>     correspond to what you specified for the chdir stanza in the job configuration.
> 
>     >
>     > Thanks!
>     >
>     >
>     >
>     >
>     > On 6 February 2014 03:26, Clint Byrum <clint at ubuntu.com
>     <mailto:clint at ubuntu.com>
>     > <mailto:clint at ubuntu.com <mailto:clint at ubuntu.com>>> wrote:
>     >
>     >     Excerpts from Mariano Gonz?lez's message of 2014-02-05 09:55:59 -0800:
>     >     > Hi there.
>     >     >
>     >     > I'm trying to monitor a newrelic plugin service with upstart in
>     CentOS 6.x.
>     >     >
>     >     > Here's newrelic plugin script:
>     https://gist.github.com/Mariano-gon/8829482
>     >     >
>     >     > Here's my upstart script: https://gist.github.com/Mariano-gon/8827034
>     >     >
>     >     > When I try to restart it, it'll respawn x times and then stops itself.
>     >     >
>     >     > Here're the log lines: https://gist.github.com/Mariano-gon/8829533
>     >     >
>     >
>     >     https://gist.github.com/Mariano-gon/8827034#file-newrelic_rs-conf-L7
>     >
>     >     exec means you will never reach the next line. There is a declarative
>     >     way to change dirs, so you don't need the script stanza at all:
>     >
>     >     ---
>     >     respawn
>     >     chdir /path/to/plugin_installation
>     >     exec bundle exec ./bin/newrelic_rs
>     >     ---
>     >
>     >     Note that if you want it to start at boot, don't use any of the weird
>     >     compound start ons you see:
>     >
>     >     start on runlevel [2345]
>     >     stop on runlevel [016]
>     >
>     >     Those two should be fine.
>     >
>     >     --
>     >     upstart-devel mailing list
>     >     upstart-devel at lists.ubuntu.com <mailto:upstart-devel at lists.ubuntu.com>
>     <mailto:upstart-devel at lists.ubuntu.com <mailto:upstart-devel at lists.ubuntu.com>>
>     >     Modify settings or unsubscribe at:
>     >     https://lists.ubuntu.com/mailman/listinfo/upstart-devel
>     >
>     >
>     >
>     >
>     > --
>     > Mariano Gabriel Gonz?lez
>     >
>     >
> 
>     Kind regards,
> 
>     James.
>     --
>     James Hunt
>     ____________________________________
>     #upstart on freenode
>     http://upstart.ubuntu.com/cookbook
>     https://lists.ubuntu.com/mailman/listinfo/upstart-devel
> 
> 
> 
> 
> -- 
> Mariano Gabriel Gonz?lez
> 
> 


-- 
Kind regards,

James.
--
James Hunt
____________________________________
#upstart on freenode
http://upstart.ubuntu.com/cookbook
https://lists.ubuntu.com/mailman/listinfo/upstart-devel


From james.hunt at canonical.com  Thu Feb  6 14:48:03 2014
From: james.hunt at canonical.com (James Hunt)
Date: Thu, 06 Feb 2014 14:48:03 -0000
Subject: [Merge] lp:~cameronnemo/upstart/ipv6 into lp:upstart
In-Reply-To: <20140204040723.13972.15231.launchpad@ackee.canonical.com>
Message-ID: <20140206144802.2050.57878.codereview@chaenomeles.canonical.com>

Hi Cameron - no problem. Feel free to join #upstart on freenode if you have questions.
-- 
https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599
Your team Upstart Reviewers is subscribed to branch lp:upstart.


From camerontnorman at gmail.com  Thu Feb  6 04:28:35 2014
From: camerontnorman at gmail.com (Cameron Norman)
Date: Thu, 06 Feb 2014 04:28:35 -0000
Subject: [Merge] lp:~cameronnemo/upstart/ipv6 into lp:upstart
In-Reply-To: <20140204040723.13972.15231.launchpad@ackee.canonical.com>
Message-ID: <20140206042834.2341.43799.codereview@wampee.canonical.com>

Thanks for the help and patience James. I am going to try to work on this tonight and tommorow, and will comment here if I reach success, or if I need any help (if that is alright).
-- 
https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599
Your team Upstart Reviewers is subscribed to branch lp:upstart.


From james.hunt at canonical.com  Mon Feb 10 16:00:06 2014
From: james.hunt at canonical.com (James Hunt)
Date: Mon, 10 Feb 2014 16:00:06 -0000
Subject: [Merge] lp:~cameronnemo/upstart/ipv6 into lp:upstart
In-Reply-To: <20140204040723.13972.15231.launchpad@ackee.canonical.com>
Message-ID: <20140210160004.1495.48924.codereview@soybean.canonical.com>

Review: Needs Fixing

Hi Cameron,

Thanks for updating. I've found another issue though: if there are 2 jobs that specify 'start on socket', one for IPv4 the other for IPv6, the bridge will be unable to call bind(2) for each protocol version currently:

$ cat <<EOT | sudo tee /etc/init/test-socket-bridge-ipv4.confj
start on socket PROTO=inet PORT=80 ADDR=127.0.0.1
exec echo ipv4
EOT

$ cat <<EOT | sudo tee /etc/init/test-socket-bridge-ipv6.conf
start on socket PROTO=inet6 PORT=80 ADDR=::1
exec echo ipv6
EOT

$ sudo extra/upstart-socket-bridge --debug
job_add_socket: Found socket
upstart_job_added: Job got added /com/ubuntu/Upstart/jobs/test_2dsocket_2dbridge_2dipv6
job_add_socket: Found socket
upstart-socket-bridge: Failed to bind socket in /com/ubuntu/Upstart/jobs/test_2dsocket_2dbridge_2dipv4: Address already in use


I think we may need some IPV6_V6ONLY setsockopt(2) magic to resolve this?
-- 
https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599
Your team Upstart Reviewers is subscribed to branch lp:upstart.


From camerontnorman at gmail.com  Sun Feb  9 17:39:10 2014
From: camerontnorman at gmail.com (Cameron Norman)
Date: Sun, 09 Feb 2014 17:39:10 -0000
Subject: [Merge] lp:~cameronnemo/upstart/ipv6 into lp:upstart
In-Reply-To: <20140204040723.13972.15231.launchpad@ackee.canonical.com>
Message-ID: <20140209173909.1483.87336.codereview@wampee.canonical.com>

So I tested it on a Saucy machine and it seems to be working. Would you like to re-review it?
-- 
https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599
Your team Upstart Reviewers is subscribed to branch lp:upstart.


From camerontnorman at gmail.com  Mon Feb 10 20:15:05 2014
From: camerontnorman at gmail.com (Cameron Norman)
Date: Mon, 10 Feb 2014 20:15:05 -0000
Subject: [Merge] lp:~cameronnemo/upstart/ipv6 into lp:upstart
In-Reply-To: <20140204040723.13972.15231.launchpad@ackee.canonical.com>
Message-ID: <20140210201503.2015.94779.codereview@chaenomeles.canonical.com>

I have a question about that. Should we not instead do IPv4 mapped IPv6?
-- 
https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599
Your team Upstart Reviewers is subscribed to branch lp:upstart.


From camerontnorman at gmail.com  Mon Feb 10 20:58:22 2014
From: camerontnorman at gmail.com (Cameron Norman)
Date: Mon, 10 Feb 2014 20:58:22 -0000
Subject: [Merge] lp:~cameronnemo/upstart/ipv6 into lp:upstart
In-Reply-To: <20140204040723.13972.15231.launchpad@ackee.canonical.com>
Message-ID: <20140210205821.1539.63692.codereview@chaenomeles.canonical.com>

But you would still have to use IPV6_V6ONLY in that scenario. And even then with IPV4 mapped IPv6 you would need to give the job two fd's, which we cannot do with the current socket activation protocol (correct?).
-- 
https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599
Your team Upstart Reviewers is subscribed to branch lp:upstart.


From camerontnorman at gmail.com  Wed Feb 12 02:35:53 2014
From: camerontnorman at gmail.com (Cameron Norman)
Date: Wed, 12 Feb 2014 02:35:53 -0000
Subject: [Merge] lp:~cameronnemo/upstart/ipv6 into lp:upstart
In-Reply-To: <20140204040723.13972.15231.launchpad@ackee.canonical.com>
Message-ID: <20140212023552.1799.65588.codereview@wampee.canonical.com>

Ok, so I got it working and tested it with the following job:

start on socket PROTO=inet6 PORT=80 ADDR=::1

exec socat fd:"$UPSTART_FDS" -
-- 
https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599
Your team Upstart Reviewers is subscribed to branch lp:upstart.


From brian.campbell at editshare.com  Wed Feb 12 19:13:55 2014
From: brian.campbell at editshare.com (Brian Campbell)
Date: Wed, 12 Feb 2014 14:13:55 -0500
Subject: Wedged state while trying to write upstart jobs
Message-ID: <CAC0BMDwTe-v9d2dpvfCQZ0LCXMGt+KfoQw8hVSowCDD2vii3TQ@mail.gmail.com>

Hi, I'm trying to write a few upstart jobs to handle an inoticoming
queue for a reprepro repository. In particular, I want to start up a
GPG agent to handle signing the release based on incoming packages,
then once that's started start up a few inoticoming jobs.

In the process of trying to get this set up, I seem to have created a
wedged, unkillable job, despite the fact that the underlying process
is no longer present.

I have the following reprepro-gpg.conf:

--- snip ---
description "GPG agent for reprepro signing"

start on runlevel [2345]

setuid repomgr

expect daemon

script
     gpg-agent --daemon                                        \
               --homedir /home/repomgr                         \
               --write-env-file /home/repomgr/.gpg-agent-info  \
               --allow-preset-passphrase                       \
               --verbose                                       \
               --log-file /home/repomgr/gpg-agent-verbose.log
end script

post-start exec /home/repomgr/preset-passhprase.sh
--- snip ---


After having started this once, and tried to stop it, the "sudo stop
reprepro-gpg" hung. I hit Control-C and manually killed the gpg-agent
process with "sudo killall gpg-agent". But now I'm in a state where I
can't start it or stop it; no matter what I do, I can't seem to get
this job unwedged:

$ initctl list | grep reprepro-gpg
reprepro-gpg start/killed, process 13361
$ ps auwx | grep 13361
lambda   13941  0.0  0.0    488     4 pts/0    R+   18:52   0:00 grep
--color=auto 13361
$ sudo stop reprepro-gpg
<hangs>
^C
$ sudo start reprepro-gpg
<hangs>
^C
$ sudo restart reprepro-gpg
<hangs>
^C
$ sudo stop --no-wait reprepro-gpg
stop: Job has already been stopped: reprepro-gpg
$ sudo start --no-wait reprepro-gpg
reprepro-gpg start/killed, process 13361
$ sudo restart --no-wait reprepro-gpg
reprepro-gpg start/killed, process 13361

Any ideas about how I might get out of this state, or debug it? I'm
using Upstart 1.5 on Ubuntu 12.04.4.

-- Brian


From gonzalez.mariano.gabriel at gmail.com  Mon Feb 17 14:43:16 2014
From: gonzalez.mariano.gabriel at gmail.com (=?ISO-8859-1?Q?Mariano_Gonz=E1lez?=)
Date: Mon, 17 Feb 2014 11:43:16 -0300
Subject: Trying to write an upstart script for a newrelic agent
Message-ID: <CAHknVTUWCZ68fe3Nj8DFowcYKfS0QT-ha=SRpajggHJosB2kaA@mail.gmail.com>

Hi guys.
I'm asking for help to write a script to monitor a newrelic agent.
Here's what I have now: https://gist.github.com/marianogg9/9002995
As you may see, the service won't start and will respawn 10 times. I think
this is an env issue, but I tried with export and env stanzas without
success.
Any comments will be really appreciated.
Thanks!

-- 
Mariano Gabriel Gonz?lez
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140217/2490f815/attachment.html>

From steve.langasek at ubuntu.com  Mon Feb 17 23:19:41 2014
From: steve.langasek at ubuntu.com (Steve Langasek)
Date: Mon, 17 Feb 2014 15:19:41 -0800
Subject: Trying to write an upstart script for a newrelic agent
In-Reply-To: <CAHknVTUWCZ68fe3Nj8DFowcYKfS0QT-ha=SRpajggHJosB2kaA@mail.gmail.com>
References: <CAHknVTUWCZ68fe3Nj8DFowcYKfS0QT-ha=SRpajggHJosB2kaA@mail.gmail.com>
Message-ID: <20140217231941.GA4993@virgil.dodds.net>

Hi Mariano,

On Mon, Feb 17, 2014 at 11:43:16AM -0300, Mariano Gonz?lez wrote:
> Hi guys.
> I'm asking for help to write a script to monitor a newrelic agent.
> Here's what I have now: https://gist.github.com/marianogg9/9002995
> As you may see, the service won't start and will respawn 10 times. I think
> this is an env issue, but I tried with export and env stanzas without
> success.
> Any comments will be really appreciated.
> Thanks!

Your upstart job does:

  exec sudo -u root 'bundle exec /path_to_plugin/newrelic/newrelic_rs_dfw/bin/newrelic_rs' 

The obvious issue here is that this is the wrong syntax.  Quoting the string
'bundle exec [...]' causes sudo to try to find a program named 'bundle exec
[...]', instead of executing the program 'bundle' with arguments 'exec',
[...].

Note that it's recommended to not use sudo for upstart jobs, in general, as
sudo spawns an associated PAM session which is normally not what you want.
And if all you care about is the user id, then 'sudo -u root' is redundant
since all system jobs run as root by default.

Finally, if you have any further problems with this job, try looking in
/var/log/upstart/newrelic.log.  Assuming you're running a new enough
upstart, you will have logs there (including the error output of your failed
sudo commands).

Hope that helps,
-- 
Steve Langasek                   Give me a lever long enough and a Free OS
Debian Developer                   to set it on, and I can move the world.
Ubuntu Developer                                    http://www.debian.org/
slangasek at ubuntu.com                                     vorlon at debian.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140217/81cce595/attachment.pgp>

From clint at fewbar.com  Mon Feb 17 15:40:14 2014
From: clint at fewbar.com (Clint Byrum)
Date: Mon, 17 Feb 2014 07:40:14 -0800
Subject: Trying to write an upstart script for a newrelic agent
In-Reply-To: <CAHknVTUWCZ68fe3Nj8DFowcYKfS0QT-ha=SRpajggHJosB2kaA@mail.gmail.com>
References: <CAHknVTUWCZ68fe3Nj8DFowcYKfS0QT-ha=SRpajggHJosB2kaA@mail.gmail.com>
Message-ID: <1392648574-sup-7722@fewbar.com>

Excerpts from Mariano Gonz?lez's message of 2014-02-17 06:43:16 -0800:
> Hi guys.
> I'm asking for help to write a script to monitor a newrelic agent.
> Here's what I have now: https://gist.github.com/marianogg9/9002995
> As you may see, the service won't start and will respawn 10 times. I think
> this is an env issue, but I tried with export and env stanzas without
> success.
> Any comments will be really appreciated.
> Thanks!
> 

If you are running it as root, why not have it as a system job from
/etc/init/something.conf ? Then you can drop sudo.

Also you should have logs in ~/.cache/upstart if it is a user job, or
/var/log/upstart if it is a system job. Those should give a clue as to
why your command is failing.


From james.hunt at canonical.com  Tue Feb 18 09:17:31 2014
From: james.hunt at canonical.com (James Hunt)
Date: Tue, 18 Feb 2014 09:17:31 -0000
Subject: [Merge] lp:~cameronnemo/upstart/ipv6 into lp:upstart
In-Reply-To: <20140204040723.13972.15231.launchpad@ackee.canonical.com>
Message-ID: <20140218091730.1563.49067.codereview@gac.canonical.com>

Hi Cameron,

Yes, this does seem to be working, but if you run 'sudo upstart-socket-bridge --debug' with the 2 test jobs above, an error is raised on the 2nd bind:

$ sudo extra/upstart-socket-bridge --debug
job_add_socket: Found socket
upstart_job_added: Job got added /com/ubuntu/Upstart/jobs/test_2dsocket_2dbridge_2dipv6
job_add_socket: Found socket
upstart-socket-bridge: Failed to bind socket in /com/ubuntu/Upstart/jobs/test_2dsocket_2dbridge_2dipv4: Address already in use

-- 
https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599
Your team Upstart Reviewers is subscribed to branch lp:upstart.


From gonzalez.mariano.gabriel at gmail.com  Tue Feb 18 11:56:37 2014
From: gonzalez.mariano.gabriel at gmail.com (=?ISO-8859-1?Q?Mariano_Gonz=E1lez?=)
Date: Tue, 18 Feb 2014 08:56:37 -0300
Subject: Trying to write an upstart script for a newrelic agent
In-Reply-To: <1392648574-sup-7722@fewbar.com>
References: <CAHknVTUWCZ68fe3Nj8DFowcYKfS0QT-ha=SRpajggHJosB2kaA@mail.gmail.com>
 <1392648574-sup-7722@fewbar.com>
Message-ID: <CAHknVTU7f=bBQVWh14khiGFxrOghiu=ToyPnMOdaxRm6asO9_A@mail.gmail.com>

Hi Steve and Clint. Thanks for your comments.

@Steve

You're totally right, it's not necessary to write sudo -u root as it's the
same as writing sudo. My fault there.
But, the command to run the agent is the following:

$ cd /path/newrelic_rs_dfw/
$ bundle exec ./bin/newrelic_rs

As bundle exec is a ruby gem located in /path/newrelic_rs_dfw/. So, to this
script to function it'd need to locate in /path/newrelic_rs_dfw/ first and
then run the bundle exec. Which it doesn't do if I write down those two
previous steps in a script. Neither it does if I specify an env variable or
source stanza. That's why I think this is an env issue.

@Clint

I'm trying to run this agent as an Upstart job, that's why I'm writing an
/etc/init/newrelic.conf script. Sorry if I missunderstood your comments if
it's not what you meant.

Finally, there's no trace of newrelic logs in /var/log/ besides /newrelic/
folder where OTHER newrelic agents does write their logs in this vm.

The only logs I have are the ones written in /messages.log

Thanks again!


On 17 February 2014 12:40, Clint Byrum <clint at fewbar.com> wrote:

> Excerpts from Mariano Gonz?lez's message of 2014-02-17 06:43:16 -0800:
> > Hi guys.
> > I'm asking for help to write a script to monitor a newrelic agent.
> > Here's what I have now: https://gist.github.com/marianogg9/9002995
> > As you may see, the service won't start and will respawn 10 times. I
> think
> > this is an env issue, but I tried with export and env stanzas without
> > success.
> > Any comments will be really appreciated.
> > Thanks!
> >
>
> If you are running it as root, why not have it as a system job from
> /etc/init/something.conf ? Then you can drop sudo.
>
> Also you should have logs in ~/.cache/upstart if it is a user job, or
> /var/log/upstart if it is a system job. Those should give a clue as to
> why your command is failing.
>
> --
> upstart-devel mailing list
> upstart-devel at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/upstart-devel
>



-- 
Mariano Gabriel Gonz?lez
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140218/d2824b91/attachment.html>

From gonzalez.mariano.gabriel at gmail.com  Tue Feb 18 14:51:31 2014
From: gonzalez.mariano.gabriel at gmail.com (=?ISO-8859-1?Q?Mariano_Gonz=E1lez?=)
Date: Tue, 18 Feb 2014 11:51:31 -0300
Subject: Trying to write an upstart script for a newrelic agent
In-Reply-To: <CAHknVTU7f=bBQVWh14khiGFxrOghiu=ToyPnMOdaxRm6asO9_A@mail.gmail.com>
References: <CAHknVTUWCZ68fe3Nj8DFowcYKfS0QT-ha=SRpajggHJosB2kaA@mail.gmail.com>
 <1392648574-sup-7722@fewbar.com>
 <CAHknVTU7f=bBQVWh14khiGFxrOghiu=ToyPnMOdaxRm6asO9_A@mail.gmail.com>
Message-ID: <CAHknVTWRLuhkwYpVGwCfKL-Q_gqYbg3hr+mZJm3kw6+XWWA-cg@mail.gmail.com>

Heh guys. Here's the agent script:
https://gist.github.com/marianogg9/9072387, from
https://github.com/newrelic-platform/newrelic_rackspace_load_balancers_plugin

And this got my attention:

unless $:.include?(File.dirname(__FILE__) + '/../lib/')
  $: << File.dirname(__FILE__) + '/../lib'
end

Isn't it an env path definition? keep in mind you need to be pwd in
/path/newrelic_rs_dfw/ to run bundle exec bin/newrelic_rs.rb

Thanks.


On 18 February 2014 08:56, Mariano Gonz?lez <
gonzalez.mariano.gabriel at gmail.com> wrote:

> Hi Steve and Clint. Thanks for your comments.
>
> @Steve
>
> You're totally right, it's not necessary to write sudo -u root as it's the
> same as writing sudo. My fault there.
> But, the command to run the agent is the following:
>
> $ cd /path/newrelic_rs_dfw/
> $ bundle exec ./bin/newrelic_rs
>
> As bundle exec is a ruby gem located in /path/newrelic_rs_dfw/. So, to
> this script to function it'd need to locate in /path/newrelic_rs_dfw/ first
> and then run the bundle exec. Which it doesn't do if I write down those two
> previous steps in a script. Neither it does if I specify an env variable or
> source stanza. That's why I think this is an env issue.
>
> @Clint
>
> I'm trying to run this agent as an Upstart job, that's why I'm writing an
> /etc/init/newrelic.conf script. Sorry if I missunderstood your comments if
> it's not what you meant.
>
> Finally, there's no trace of newrelic logs in /var/log/ besides /newrelic/
> folder where OTHER newrelic agents does write their logs in this vm.
>
> The only logs I have are the ones written in /messages.log
>
> Thanks again!
>
>
> On 17 February 2014 12:40, Clint Byrum <clint at fewbar.com> wrote:
>
>> Excerpts from Mariano Gonz?lez's message of 2014-02-17 06:43:16 -0800:
>> > Hi guys.
>> > I'm asking for help to write a script to monitor a newrelic agent.
>> > Here's what I have now: https://gist.github.com/marianogg9/9002995
>> > As you may see, the service won't start and will respawn 10 times. I
>> think
>> > this is an env issue, but I tried with export and env stanzas without
>> > success.
>> > Any comments will be really appreciated.
>> > Thanks!
>> >
>>
>> If you are running it as root, why not have it as a system job from
>> /etc/init/something.conf ? Then you can drop sudo.
>>
>> Also you should have logs in ~/.cache/upstart if it is a user job, or
>> /var/log/upstart if it is a system job. Those should give a clue as to
>> why your command is failing.
>>
>> --
>> upstart-devel mailing list
>> upstart-devel at lists.ubuntu.com
>> Modify settings or unsubscribe at:
>> https://lists.ubuntu.com/mailman/listinfo/upstart-devel
>>
>
>
>
> --
> Mariano Gabriel Gonz?lez
>



-- 
Mariano Gabriel Gonz?lez
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140218/312c333f/attachment-0001.html>

From steve.langasek at ubuntu.com  Tue Feb 18 19:01:36 2014
From: steve.langasek at ubuntu.com (Steve Langasek)
Date: Tue, 18 Feb 2014 11:01:36 -0800
Subject: Trying to write an upstart script for a newrelic agent
In-Reply-To: <CAHknVTWRLuhkwYpVGwCfKL-Q_gqYbg3hr+mZJm3kw6+XWWA-cg@mail.gmail.com>
 <CAHknVTU7f=bBQVWh14khiGFxrOghiu=ToyPnMOdaxRm6asO9_A@mail.gmail.com>
Message-ID: <20140218190136.GA16499@virgil.dodds.net>

On Tue, Feb 18, 2014 at 08:56:37AM -0300, Mariano Gonz?lez wrote:
> Hi Steve and Clint. Thanks for your comments.

> You're totally right, it's not necessary to write sudo -u root as it's the
> same as writing sudo. My fault there.
> But, the command to run the agent is the following:

> $ cd /path/newrelic_rs_dfw/
> $ bundle exec ./bin/newrelic_rs

upstart has a 'chdir' primitive you can use for this.

chdir /path/newrelic_rs_dfw
exec ./bundle exec ./bin/newrelic_rs

(I'm assuming that 'bundle' is in the local directory, and not something on
the system path.)

> As bundle exec is a ruby gem located in /path/newrelic_rs_dfw/. So, to this
> script to function it'd need to locate in /path/newrelic_rs_dfw/ first and
> then run the bundle exec. Which it doesn't do if I write down those two
> previous steps in a script. Neither it does if I specify an env variable or
> source stanza. That's why I think this is an env issue.

What env variable would you expect to be setting here?  That's the wrong
tool for changing the directory.

> Finally, there's no trace of newrelic logs in /var/log/ besides /newrelic/
> folder where OTHER newrelic agents does write their logs in this vm.

What version of upstart are you using?


-- 
Steve Langasek                   Give me a lever long enough and a Free OS
Debian Developer                   to set it on, and I can move the world.
Ubuntu Developer                                    http://www.debian.org/
slangasek at ubuntu.com                                     vorlon at debian.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140218/9a373e58/attachment-0001.pgp>

From gonzalez.mariano.gabriel at gmail.com  Tue Feb 18 19:17:16 2014
From: gonzalez.mariano.gabriel at gmail.com (=?ISO-8859-1?Q?Mariano_Gonz=E1lez?=)
Date: Tue, 18 Feb 2014 16:17:16 -0300
Subject: Trying to write an upstart script for a newrelic agent
In-Reply-To: <20140218190136.GA16499@virgil.dodds.net>
References: <CAHknVTWRLuhkwYpVGwCfKL-Q_gqYbg3hr+mZJm3kw6+XWWA-cg@mail.gmail.com>
 <CAHknVTU7f=bBQVWh14khiGFxrOghiu=ToyPnMOdaxRm6asO9_A@mail.gmail.com>
 <20140218190136.GA16499@virgil.dodds.net>
Message-ID: <CAHknVTULGgQUESo6UOu=yoJyyZrvMm8w4j3BuZf8TW6Qh7QxAg@mail.gmail.com>

Steve

Tried what you suggested, newrelic_rs_dfw_test.conf:

# Upstart script

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

respawn

chdir /opt/turner/services/newrelic/newrelic_rs_dfw/

exec bundle exec bin/newrelic_rs

----

/var/log/messages

Feb 18 19:07:50  init: newrelic_rs_dfw_test main process (5149) terminated
with status 1
Feb 18 19:07:50  init: newrelic_rs_dfw_test respawning too fast, stopped
Feb 18 19:07:50  init: newrelic_rs_dfw_test goal changed from start to stop
Feb 18 19:07:50  init: newrelic_rs_dfw_test state changed from running to
stopping
Feb 18 19:07:50  init: Handling stopping event
Feb 18 19:07:50  init: newrelic_rs_dfw_test state changed from stopping to
killed
Feb 18 19:07:50  init: newrelic_rs_dfw_test state changed from killed to
post-stop
Feb 18 19:07:50  init: newrelic_rs_dfw_test state changed from post-stop to
waiting
Feb 18 19:07:50  init: Handling stopped event

----

init (upstart 0.6.5)

----

Run the bundle from the right folder:

[root at server newrelic_rs_dfw]# pwd
/path/newrelic/newrelic_rs_dfw
[root at server newrelic_rs_dfw]# bundle exec ./bin/newrelic_rs
[Tue Feb 18 19:13:23 UTC 2014] WARN: SSL is disabled by default when using
Ruby 1.8.x

And started normally.

----

Tried not being root, and got a gem error:

-sh-4.1$ bundle exec ./bin/newrelic_rs
Could not find rake-10.1.1 in any of the sources
Run `bundle install` to install missing gems.

It does work with sudo.
--





On 18 February 2014 16:01, Steve Langasek <steve.langasek at ubuntu.com> wrote:

> On Tue, Feb 18, 2014 at 08:56:37AM -0300, Mariano Gonz?lez wrote:
> > Hi Steve and Clint. Thanks for your comments.
>
> > You're totally right, it's not necessary to write sudo -u root as it's
> the
> > same as writing sudo. My fault there.
> > But, the command to run the agent is the following:
>
> > $ cd /path/newrelic_rs_dfw/
> > $ bundle exec ./bin/newrelic_rs
>
> upstart has a 'chdir' primitive you can use for this.
>
> chdir /path/newrelic_rs_dfw
> exec ./bundle exec ./bin/newrelic_rs
>
> (I'm assuming that 'bundle' is in the local directory, and not something on
> the system path.)
>
> > As bundle exec is a ruby gem located in /path/newrelic_rs_dfw/. So, to
> this
> > script to function it'd need to locate in /path/newrelic_rs_dfw/ first
> and
> > then run the bundle exec. Which it doesn't do if I write down those two
> > previous steps in a script. Neither it does if I specify an env variable
> or
> > source stanza. That's why I think this is an env issue.
>
> What env variable would you expect to be setting here?  That's the wrong
> tool for changing the directory.
>
> > Finally, there's no trace of newrelic logs in /var/log/ besides
> /newrelic/
> > folder where OTHER newrelic agents does write their logs in this vm.
>
> What version of upstart are you using?
>
>
> --
> Steve Langasek                   Give me a lever long enough and a Free OS
> Debian Developer                   to set it on, and I can move the world.
> Ubuntu Developer                                    http://www.debian.org/
> slangasek at ubuntu.com                                     vorlon at debian.org
>



-- 
Mariano Gabriel Gonz?lez
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140218/8fbcee47/attachment-0001.html>

From steve.langasek at ubuntu.com  Tue Feb 18 19:36:59 2014
From: steve.langasek at ubuntu.com (Steve Langasek)
Date: Tue, 18 Feb 2014 11:36:59 -0800
Subject: Trying to write an upstart script for a newrelic agent
In-Reply-To: <CAHknVTULGgQUESo6UOu=yoJyyZrvMm8w4j3BuZf8TW6Qh7QxAg@mail.gmail.com>
References: <CAHknVTWRLuhkwYpVGwCfKL-Q_gqYbg3hr+mZJm3kw6+XWWA-cg@mail.gmail.com>
 <CAHknVTU7f=bBQVWh14khiGFxrOghiu=ToyPnMOdaxRm6asO9_A@mail.gmail.com>
 <20140218190136.GA16499@virgil.dodds.net>
 <CAHknVTULGgQUESo6UOu=yoJyyZrvMm8w4j3BuZf8TW6Qh7QxAg@mail.gmail.com>
Message-ID: <20140218193659.GB16499@virgil.dodds.net>

On Tue, Feb 18, 2014 at 04:17:16PM -0300, Mariano Gonz?lez wrote:
> Steve

> Tried what you suggested, newrelic_rs_dfw_test.conf:

> # Upstart script

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

> respawn

> chdir /opt/turner/services/newrelic/newrelic_rs_dfw/

> exec bundle exec bin/newrelic_rs

That's not what I suggested.  I wrote:

  exec ./bundle exec bin/newrelic_rs

I don't think this 'bundle' command is on the system path.

> init (upstart 0.6.5)

Ok.  You're quite a few upstart revisions - and almost two Ubuntu LTSes -
behind.  I would certainly recommend upgrading to Ubuntu 12.04 if you can,
which would give you the upstart job logging support.

> Run the bundle from the right folder:

> [root at server newrelic_rs_dfw]# pwd
> /path/newrelic/newrelic_rs_dfw
> [root at server newrelic_rs_dfw]# bundle exec ./bin/newrelic_rs
> [Tue Feb 18 19:13:23 UTC 2014] WARN: SSL is disabled by default when using
> Ruby 1.8.x

> And started normally.

Yes, which probably means that 'bundle' is a command that's on the path when
you run a login shell, but is not on the default path used by upstart.  You
can verify the location of the bundle command by running 'which bundle'.

-- 
Steve Langasek                   Give me a lever long enough and a Free OS
Debian Developer                   to set it on, and I can move the world.
Ubuntu Developer                                    http://www.debian.org/
slangasek at ubuntu.com                                     vorlon at debian.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140218/50af4f15/attachment.pgp>

From gonzalez.mariano.gabriel at gmail.com  Tue Feb 18 19:45:54 2014
From: gonzalez.mariano.gabriel at gmail.com (=?ISO-8859-1?Q?Mariano_Gonz=E1lez?=)
Date: Tue, 18 Feb 2014 16:45:54 -0300
Subject: Trying to write an upstart script for a newrelic agent
In-Reply-To: <20140218193659.GB16499@virgil.dodds.net>
References: <CAHknVTWRLuhkwYpVGwCfKL-Q_gqYbg3hr+mZJm3kw6+XWWA-cg@mail.gmail.com>
 <CAHknVTU7f=bBQVWh14khiGFxrOghiu=ToyPnMOdaxRm6asO9_A@mail.gmail.com>
 <20140218190136.GA16499@virgil.dodds.net>
 <CAHknVTULGgQUESo6UOu=yoJyyZrvMm8w4j3BuZf8TW6Qh7QxAg@mail.gmail.com>
 <20140218193659.GB16499@virgil.dodds.net>
Message-ID: <CAHknVTU5+FaevzGN7MOUgmQw0o6asfoA5B93NqtYE5tveiTXzw@mail.gmail.com>

Steve, again you're right.

The bundle isn't in /path/newrelic/. It's in /usr/bin/ (run which bundle
and got that).

Edited my upstart job to:

..
chdir path/newrelic
exec /usr/bin/bundle exec ./bin/newrelic_rs
..

Started the job and it's working!

Sorry about the dumb question, I'm just a newbie with Upstart. I'm running
CentOS 6.3 that's why (I think) don't have the latest version of Upstart.
Anyway, it's working and thanks again!




On 18 February 2014 16:36, Steve Langasek <steve.langasek at ubuntu.com> wrote:

> On Tue, Feb 18, 2014 at 04:17:16PM -0300, Mariano Gonz?lez wrote:
> > Steve
>
> > Tried what you suggested, newrelic_rs_dfw_test.conf:
>
> > # Upstart script
>
> > start on runlevel [2345]
> > stop on runlevel [016]
>
> > respawn
>
> > chdir /opt/turner/services/newrelic/newrelic_rs_dfw/
>
> > exec bundle exec bin/newrelic_rs
>
> That's not what I suggested.  I wrote:
>
>   exec ./bundle exec bin/newrelic_rs
>
> I don't think this 'bundle' command is on the system path.
>
> > init (upstart 0.6.5)
>
> Ok.  You're quite a few upstart revisions - and almost two Ubuntu LTSes -
> behind.  I would certainly recommend upgrading to Ubuntu 12.04 if you can,
> which would give you the upstart job logging support.
>
> > Run the bundle from the right folder:
>
> > [root at server newrelic_rs_dfw]# pwd
> > /path/newrelic/newrelic_rs_dfw
> > [root at server newrelic_rs_dfw]# bundle exec ./bin/newrelic_rs
> > [Tue Feb 18 19:13:23 UTC 2014] WARN: SSL is disabled by default when
> using
> > Ruby 1.8.x
>
> > And started normally.
>
> Yes, which probably means that 'bundle' is a command that's on the path
> when
> you run a login shell, but is not on the default path used by upstart.  You
> can verify the location of the bundle command by running 'which bundle'.
>
> --
> Steve Langasek                   Give me a lever long enough and a Free OS
> Debian Developer                   to set it on, and I can move the world.
> Ubuntu Developer                                    http://www.debian.org/
> slangasek at ubuntu.com                                     vorlon at debian.org
>



-- 
Mariano Gabriel Gonz?lez
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140218/914072c7/attachment.html>

From camerontnorman at gmail.com  Wed Feb 19 00:33:00 2014
From: camerontnorman at gmail.com (Cameron Norman)
Date: Wed, 19 Feb 2014 00:33:00 -0000
Subject: [Merge] lp:~cameronnemo/upstart/ipv6 into lp:upstart
In-Reply-To: <20140204040723.13972.15231.launchpad@ackee.canonical.com>
Message-ID: <20140219003300.20691.98704.codereview@chaenomeles.canonical.com>

That is strange, because I am not seeing the failure. Are you sure you are using r1602?
-- 
https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599
Your team Upstart Reviewers is subscribed to branch lp:upstart.


From camerontnorman at gmail.com  Wed Feb 19 00:35:54 2014
From: camerontnorman at gmail.com (Cameron Norman)
Date: Wed, 19 Feb 2014 00:35:54 -0000
Subject: [Merge] lp:~cameronnemo/upstart/ipv6 into lp:upstart
In-Reply-To: <20140204040723.13972.15231.launchpad@ackee.canonical.com>
Message-ID: <20140219003553.1495.4852.codereview@soybean.canonical.com>

Wait, I think I may understand why. Is the system upstart-socket-bridge creating the socket for test-socket-bridge-ipv4.conf at boot? That would explain why the ipv6 one is not binding: the socket bridge you run at boot can not bind to the ipv6 socket. Other than that, I am at a loss as to why it works here, but not there.
-- 
https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599
Your team Upstart Reviewers is subscribed to branch lp:upstart.


From camerontnorman at gmail.com  Wed Feb 19 00:43:03 2014
From: camerontnorman at gmail.com (Cameron Norman)
Date: Wed, 19 Feb 2014 00:43:03 -0000
Subject: [Merge] lp:~cameronnemo/upstart/ipv6 into lp:upstart
In-Reply-To: <20140204040723.13972.15231.launchpad@ackee.canonical.com>
Message-ID: <20140219004302.1594.33698.codereview@gac.canonical.com>

why the ipv6 one is not binding
                    ^^^

I meant that it is binding, sorry.
-- 
https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599
Your team Upstart Reviewers is subscribed to branch lp:upstart.


From noreply at launchpad.net  Wed Feb 19 09:08:22 2014
From: noreply at launchpad.net (noreply at launchpad.net)
Date: Wed, 19 Feb 2014 09:08:22 -0000
Subject: [Merge] lp:~cameronnemo/upstart/ipv6 into lp:upstart
In-Reply-To: <20140204040723.13972.15231.launchpad@ackee.canonical.com>
Message-ID: <20140219090821.24963.96771.launchpad@ackee.canonical.com>

The proposal to merge lp:~cameronnemo/upstart/ipv6 into lp:upstart has been updated.

    Status: Needs review => Merged

For more details, see:
https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599
-- 
https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599
Your team Upstart Reviewers is subscribed to branch lp:upstart.


From noreply at launchpad.net  Wed Feb 19 09:08:30 2014
From: noreply at launchpad.net (noreply at launchpad.net)
Date: Wed, 19 Feb 2014 09:08:30 -0000
Subject: [Branch ~upstart-devel/upstart/trunk] Rev 1594: * Merged
 lp:~cameronnemo/upstart/ipv6.
Message-ID: <20140219090830.19188.50678.launchpad@ackee.canonical.com>

Merge authors:
  Cameron Norman (cameronnemo)
  Kai Mast (kai-mast)
Related merge proposals:
  https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599
  proposed by: Cameron Norman (cameronnemo)
  review: Needs Fixing - James Hunt (jamesodhunt)
------------------------------------------------------------
revno: 1594 [merge]
fixes bug: https://launchpad.net/bugs/942955
committer: James Hunt <james.hunt at ubuntu.com>
branch nick: upstart
timestamp: Wed 2014-02-19 09:07:56 +0000
message:
  * Merged lp:~cameronnemo/upstart/ipv6.
modified:
  ChangeLog
  extra/man/socket-event.7
  extra/upstart-socket-bridge.c


--
lp:upstart
https://code.launchpad.net/~upstart-devel/upstart/trunk

Your team Upstart Reviewers is subscribed to branch lp:upstart.
To unsubscribe from this branch go to https://code.launchpad.net/~upstart-devel/upstart/trunk/+edit-subscription
-------------- next part --------------
A non-text attachment was scrubbed...
Name: revision-diff.txt
Type: text/x-diff
Size: 6227 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140219/166345f2/attachment-0001.diff>

From james.hunt at canonical.com  Wed Feb 19 09:09:03 2014
From: james.hunt at canonical.com (James Hunt)
Date: Wed, 19 Feb 2014 09:09:03 -0000
Subject: [Merge] lp:~cameronnemo/upstart/ipv6 into lp:upstart
In-Reply-To: <20140204040723.13972.15231.launchpad@ackee.canonical.com>
Message-ID: <20140219090902.1820.50920.codereview@gac.canonical.com>

Review: Approve

Hi Cameron - yes, you were right :-)

Merged - thanks again for your and Kai's work on this!
-- 
https://code.launchpad.net/~cameronnemo/upstart/ipv6/+merge/204599
Your team Upstart Reviewers is subscribed to branch lp:upstart.


