[Cialug] Cialug Digest, Vol 91, Issue 27

Russ Hatch russthehatch at gmail.com
Tue Nov 27 17:04:59 CST 2012


If you are using ubuntu or a system with upstart installed you could use
that to kick off multiple background jobs. New jobs are simple to add and
can be started/stopped when particular upstart events are emitted by the
user/system. It's a nice way to daemonize stuff without a whole lot of
complexity, I've used it in the past to oversee running a few components
while doing dev stuff.

Cheers,

Russ
On Nov 27, 2012 4:23 PM, <cialug-request at cialug.org> wrote:

> Send Cialug mailing list submissions to
>         cialug at cialug.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://cialug.org/mailman/listinfo/cialug
> or, via email, send a message with subject or body 'help' to
>         cialug-request at cialug.org
>
> You can reach the person managing the list at
>         cialug-owner at cialug.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Cialug digest..."
>
>
> Today's Topics:
>
>    1. Starting two jobs at once (Matthew Nuzum)
>    2. Re: Starting two jobs at once (jim kraai)
>    3. Re: Starting two jobs at once (Matthew Nuzum)
>    4. Re: Starting two jobs at once (Zachary Kotlarek)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 27 Nov 2012 14:35:47 -0600
> From: Matthew Nuzum <newz at bearfruit.org>
> To: Central Iowa Linux Users Group <cialug at cialug.org>
> Subject: [Cialug] Starting two jobs at once
> Message-ID: <2CA683A1-578C-4D75-B169-FC7D6DE7B237 at bearfruit.org>
> Content-Type: text/plain; charset="utf-8"
>
> Hi, in order to make development on projects easier I often automate
> common tasks with Makefiles. For example, a common work flow for a Python
> project is:
>
> git clone project
> cd project
> make
> make run
>
> The makefile will generate a virtualenv, install project dependencies and
> create initial configuration files. Make run will start a temporary web
> server and keep it running so that I can work on the code and view the
> project in my browser.
>
> As it turns out, some of my projects are getting more complex because
> instead of just launching a web server they might also need to launch more
> than one process to serve an app.
>
> For example, I might need to run mongodb and the Django development
> server. I don't care about the output of mongodb, but I would like to see
> the output of the Django dev server. Or possibly want to run sass and have
> it watch files, compiling them whenever they change, and also run a nodejs
> app to serve content. Ideally, when I hit ctrl+c everything shuts down
> orderly.
>
> Any suggestions on how to keep things simple and run a couple tasks at
> once?
>
> Here is a simple example of a Makefile I use:
>
> PIP=env/bin/pip
> MANAGE=env/bin/python ./manage.py
>
> all: build syncdb
>
> syncdb:
>         $(MANAGE) syncdb --noinput
>         $(MANAGE) migrate
>
> build:
>         $(PIP) install -r requirements.txt
>
> run:
>         $(MANAGE) runserver 0.0.0.0:8000
>
>
> --
> Matthew Nuzum
> newz2000 on freenode, skype, linkedin and twitter
>
> ? You're never fully dressed without a smile! ?
>
>
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: smime.p7s
> Type: application/pkcs7-signature
> Size: 4136 bytes
> Desc: not available
> URL: <
> http://cialug.org/pipermail/cialug/attachments/20121127/e97167a4/attachment-0001.bin
> >
>
> ------------------------------
>
> Message: 2
> Date: Tue, 27 Nov 2012 15:38:41 -0600
> From: jim kraai <jimgkraai at gmail.com>
> To: Central Iowa Linux Users Group <cialug at cialug.org>
> Subject: Re: [Cialug] Starting two jobs at once
> Message-ID:
>         <CANoA21Bsdt9E=
> xgfTCbpdfdxFttKMF11WKFodO0je477aj0-kQ at mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
>
> node might be a great tool for this
>
> If I were to write this from scratch, and since you're already using
> python, I'd look into twisted reactor and writing/scheduling resource
> watcherdogs.  i'm sure there's much better terminology, but this is one way
> of doing it all in user space.
>
> Of course, it's possible I've completely missed the point of the question.
>  Apologies if that's the case.
>
>
>
> On Tue, Nov 27, 2012 at 2:35 PM, Matthew Nuzum <newz at bearfruit.org> wrote:
>
> > Hi, in order to make development on projects easier I often automate
> > common tasks with Makefiles. For example, a common work flow for a Python
> > project is:
> >
> > git clone project
> > cd project
> > make
> > make run
> >
> > The makefile will generate a virtualenv, install project dependencies and
> > create initial configuration files. Make run will start a temporary web
> > server and keep it running so that I can work on the code and view the
> > project in my browser.
> >
> > As it turns out, some of my projects are getting more complex because
> > instead of just launching a web server they might also need to launch
> more
> > than one process to serve an app.
> >
> > For example, I might need to run mongodb and the Django development
> > server. I don't care about the output of mongodb, but I would like to see
> > the output of the Django dev server. Or possibly want to run sass and
> have
> > it watch files, compiling them whenever they change, and also run a
> nodejs
> > app to serve content. Ideally, when I hit ctrl+c everything shuts down
> > orderly.
> >
> > Any suggestions on how to keep things simple and run a couple tasks at
> > once?
> >
> > Here is a simple example of a Makefile I use:
> >
> > PIP=env/bin/pip
> > MANAGE=env/bin/python ./manage.py
> >
> > all: build syncdb
> >
> > syncdb:
> >         $(MANAGE) syncdb --noinput
> >         $(MANAGE) migrate
> >
> > build:
> >         $(PIP) install -r requirements.txt
> >
> > run:
> >         $(MANAGE) runserver 0.0.0.0:8000
> >
> >
> > --
> > Matthew Nuzum
> > newz2000 on freenode, skype, linkedin and twitter
> >
> > ? You're never fully dressed without a smile! ?
> >
> >
> >
> > _______________________________________________
> > Cialug mailing list
> > Cialug at cialug.org
> > http://cialug.org/mailman/listinfo/cialug
> >
> >
>
>
> ------------------------------
>
> Message: 3
> Date: Tue, 27 Nov 2012 16:08:16 -0600
> From: Matthew Nuzum <newz at bearfruit.org>
> To: Central Iowa Linux Users Group <cialug at cialug.org>
> Subject: Re: [Cialug] Starting two jobs at once
> Message-ID: <3389AE8E-C14F-4B56-B648-CB59943C0BAC at bearfruit.org>
> Content-Type: text/plain; charset="utf-8"
>
> Thanks for the reply. One of my goals is to make it easy for new
> contributors to get started. Right now, they just need a few common
> development tools. In this case, Make and Python.
>
> Two things have come to mind, but I haven't tried them and I think they're
> both flawed:
>
> 1.
> Start a task and background it with &
> Start the foreground task and wait until it completes
> Kill the background task
>
> The prob is I'm not sure really how to kill a background task once it's in
> the background
>
> 2.
> Use tmux or screen
> This adds an extra dependency and it also makes using it a little harder
> for people. For example, some of those I've collaborated with in the past,
> such as designers, are not very comfortable with the terminal. Ctrl+c to
> end it is easy, not sure you can do this with tmux/screen.
>
> In the Python world another tool that is used is fabric, but I don't think
> it ads any flexibility in this regard over make.
>
>
> On Nov 27, 2012, at 3:38 PM, jim kraai <jimgkraai at gmail.com> wrote:
>
> > node might be a great tool for this
> >
> > If I were to write this from scratch, and since you're already using
> > python, I'd look into twisted reactor and writing/scheduling resource
> > watcherdogs.  i'm sure there's much better terminology, but this is one
> way
> > of doing it all in user space.
> >
> > Of course, it's possible I've completely missed the point of the
> question.
> > Apologies if that's the case.
> >
> >
> >
> > On Tue, Nov 27, 2012 at 2:35 PM, Matthew Nuzum <newz at bearfruit.org>
> wrote:
> >
> >> Hi, in order to make development on projects easier I often automate
> >> common tasks with Makefiles. For example, a common work flow for a
> Python
> >> project is:
> >>
> >> git clone project
> >> cd project
> >> make
> >> make run
> >>
> >> The makefile will generate a virtualenv, install project dependencies
> and
> >> create initial configuration files. Make run will start a temporary web
> >> server and keep it running so that I can work on the code and view the
> >> project in my browser.
> >>
> >> As it turns out, some of my projects are getting more complex because
> >> instead of just launching a web server they might also need to launch
> more
> >> than one process to serve an app.
> >>
> >> For example, I might need to run mongodb and the Django development
> >> server. I don't care about the output of mongodb, but I would like to
> see
> >> the output of the Django dev server. Or possibly want to run sass and
> have
> >> it watch files, compiling them whenever they change, and also run a
> nodejs
> >> app to serve content. Ideally, when I hit ctrl+c everything shuts down
> >> orderly.
> >>
> >> Any suggestions on how to keep things simple and run a couple tasks at
> >> once?
> >>
> >> Here is a simple example of a Makefile I use:
> >>
> >> PIP=env/bin/pip
> >> MANAGE=env/bin/python ./manage.py
> >>
> >> all: build syncdb
> >>
> >> syncdb:
> >>        $(MANAGE) syncdb --noinput
> >>        $(MANAGE) migrate
> >>
> >> build:
> >>        $(PIP) install -r requirements.txt
> >>
> >> run:
> >>        $(MANAGE) runserver 0.0.0.0:8000
> >>
> >>
> >> --
> >> Matthew Nuzum
> >> newz2000 on freenode, skype, linkedin and twitter
> >>
> >> ? You're never fully dressed without a smile! ?
> >>
> >>
> >>
> >> _______________________________________________
> >> Cialug mailing list
> >> Cialug at cialug.org
> >> http://cialug.org/mailman/listinfo/cialug
> >>
> >>
> > _______________________________________________
> > Cialug mailing list
> > Cialug at cialug.org
> > http://cialug.org/mailman/listinfo/cialug
>
> --
> Matthew Nuzum
> newz2000 on freenode, skype, linkedin and twitter
>
> ? You're never fully dressed without a smile! ?
>
>
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: smime.p7s
> Type: application/pkcs7-signature
> Size: 4136 bytes
> Desc: not available
> URL: <
> http://cialug.org/pipermail/cialug/attachments/20121127/b9ac643a/attachment-0001.bin
> >
>
> ------------------------------
>
> Message: 4
> Date: Tue, 27 Nov 2012 14:22:34 -0800
> From: Zachary Kotlarek <zach at kotlarek.com>
> To: Central Iowa Linux Users Group <cialug at cialug.org>
> Subject: Re: [Cialug] Starting two jobs at once
> Message-ID: <A1B8F644-0384-4F03-88C9-61911E6F4216 at kotlarek.com>
> Content-Type: text/plain; charset="us-ascii"
>
>
> On Nov 27, 2012, at 2:08 PM, Matthew Nuzum <newz at bearfruit.org> wrote:
>
> > The prob is I'm not sure really how to kill a background task once it's
> in the background
>
>
> Grab the PID and kill it by number.
>
> You can do that pretty easily with a shell script like:
>         echo $$ > /var/tmp/myScript/pid.file
>         exec 'actual daemon'
>
> That will echo the PID of the shell to the specified file, then replace
> the shell (keeping the same PID) with the daemon launched via the exec
> command.
>
> You can then launch that shell entire script in the background (with &)
> and later go read the PID file to find the process number you want to kill.
>
> --
>
> To make things die when you press ctrl-c you'll want to install a signal
> handler for SIGINT and SIGTERM. In bash that would look like this:
>
>         function quit {
>                 kill `cat /var/tmp/myScript/pid.file`
>                 exit 0
>         }
>         trap "quit" SIGINT SIGTERM
>
> --
>
>         Zach
>
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: smime.p7s
> Type: application/pkcs7-signature
> Size: 2746 bytes
> Desc: not available
> URL: <
> http://cialug.org/pipermail/cialug/attachments/20121127/e17a5c47/attachment.bin
> >
>
> ------------------------------
>
> _______________________________________________
> Cialug mailing list
> Cialug at cialug.org
> http://cialug.org/mailman/listinfo/cialug
>
>
> End of Cialug Digest, Vol 91, Issue 27
> **************************************
>


More information about the Cialug mailing list