a "task" in Upstart 0.3.8?

Asked by Alex Nekrasov on 2009-02-13

I want a task behavior for a component - run once and be considered running if returned 0, stop on explicit initctl stop.

Upstart 0.3.8 doesn't seem to support "task" keyword. How can I do it?

Question information

Language:
English Edit question
Status:
Solved
For:
upstart Edit question
Assignee:
No assignee Edit question
Solved by:
Scott James Remnant (Canonical)
Solved:
2009-02-20
Last query:
2009-02-20
Last reply:
2009-02-19

On Fri, 2009-02-13 at 14:58 +0000, Alex Nekrasov wrote:

> I want a task behavior for a component - run once and be considered running if returned 0, stop on explicit initctl stop.
>
> Upstart 0.3.8 doesn't seem to support "task" keyword. How can I do it?
>
Task is the default behaviour.

You need to use "service" to get the 0.5 default behaviour.

Scott
--
Scott James Remnant
<email address hidden>

Alex Nekrasov (ennnot) said : #2

Yes, I tried that:

test1:

script
    echo "test1. I'll do my task here"
end script

> initctl start test1
> initctl status test1
test1 (stop) waiting
>

I would expect it be running until manually stopped. Also, if a test2 is registered to start on started and stop on stopped test1, it gets started and stopped instead of being started and left running.

On Mon, 2009-02-16 at 11:45 +0000, Alex Nekrasov wrote:

> Question #60894 on upstart changed:
> https://answers.launchpad.net/upstart/+question/60894
>
> Status: Answered => Open
>
> Alex Nekrasov is still having a problem:
> Yes, I tried that:
>
> test1:
>
> script
> echo "test1. I'll do my task here"
> end script
>
> > initctl start test1
> > initctl status test1
> test1 (stop) waiting
> >
>
> I would expect it be running until manually stopped.
>
Why?

The echo command takes barely a fraction of a second, and the script
will terminate - meaning the task is stopped.

If you had "sleep inf" in there, it would indeed run until stopped.

> Also, if a test2 is
> registered to start on started and stop on stopped test1, it gets
> started and stopped instead of being started and left running.
>
Exactly; test1 is stopped because the script ended.

Scott
--
Scott James Remnant
<email address hidden>

Alex Nekrasov (ennnot) said : #4

hold on. I thought in 0.5 a task whose executable has finished with a 0 will be considered "running" by Upstart? Or did I read your blog wrong?

On Thu, 2009-02-19 at 11:31 +0000, Alex Nekrasov wrote:

> hold on. I thought in 0.5 a task whose executable has finished with a 0
> will be considered "running" by Upstart? Or did I read your blog wrong?
>
The primary difference between a service and a task is when Upstart
considers the job "complete". This affects the blocking of events and
the "start" command.

If a job is a task, any events or commands are not unblocked until the
process or script specified by exec/script has *finished*, and the
post-stop script has also finished.

If a job is a service, any events or commands are not unblocked until
the process or script specified by exec/script has *started*.

Consider the following job:

 start on starting otherjob
 exec /bin/dosomething

It will be started when "otherjob" begins starting, and "otherjob" will
wait for this job to be "complete".

If this is a service (the default in 0.5.x), then "otherjob" will start
as soon as /bin/dosomething is running.

If this is a task (the default in 0.3.x), then "otherjob" will NOT start
UNTIL /bin/dosomething has *finished*.

The secondary difference between a service and a task affects the exit
code of the process/script, and thus the "respawn" stanza.

Services will be respawned whatever their exit code.

Tasks will only be respawned if their exit code is non-zero.

In 0.3.x, task is the default; you have to mark a service with the
"service" stanza.

In 0.5.x, service is the default; you have to mark a task with the
"task" stanza.

Scott
--
Scott James Remnant
<email address hidden>

Alex Nekrasov (ennnot) said : #6

I see. Thanks Scott.

P.S. would appreciate help with 60891

Alex Nekrasov (ennnot) said : #7

Thanks Scott James Remnant, that solved my question.