nested service stop/start

53 views
Skip to first unread message

Randal L. Schwartz

unread,
Jul 13, 2014, 5:57:37 PM7/13/14
to salt-...@googlegroups.com
I have three services: postgresql, pgpool, and apache.

It's trivial to set up a restart for apache if its conf files or package change.

But when pgpool's conf file or package change, I have to ensure apache is *stopped* before, and *restarted* after, because apache holds persistent connections to pgpool.

Likewise, when postgresql's conf or package change, I need to ensure *both* pgpool *and* apache are stopped and restarted in an outer to inner order.

What's the easiest way to describe this in the SLS?

Dmitry Golubenko

unread,
Jul 14, 2014, 12:09:46 AM7/14/14
to salt-...@googlegroups.com
В Вск, 13/07/2014 в 14:57 -0700, Randal L. Schwartz пишет:
try prereq/prereq_in requisites, docs currently seems broken, but there
are some examples https://github.com/saltstack/salt/issues/5636


> --
> You received this message because you are subscribed to the Google
> Groups "Salt-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to salt-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



Randal L. Schwartz

unread,
Jul 14, 2014, 2:59:26 PM7/14/14
to salt-...@googlegroups.com, dmitry.g...@xiag.ch
After some experimentation, this seems to do the job, although now pgpool is being nasty and not able to do a restart {sigh}.


apache_down_before_pgpool:
  service:
  - name: apache22
  - dead
  - prereq:
    - service: pgpool

pgpool:
  pkg.latest:
    - names:
      - pgpool-II
  service:
    - running
    - enable: True
    - watch:
      - pkg: pgpool

apache_up_after_pgpool:
  service:
  - name: apache22
  - running
  - require:
    - service: pgpool


Randal L. Schwartz

unread,
Jul 14, 2014, 3:51:26 PM7/14/14
to salt-...@googlegroups.com, dmitry.g...@xiag.ch
Any ideas on a cmd.run sequence that runs "service pgpool stop; sleep 5; service pgpool start" that I could use instead of the broken service.watch above?

Randal L. Schwartz

unread,
Jul 14, 2014, 5:07:21 PM7/14/14
to salt-...@googlegroups.com, dmitry.g...@xiag.ch


On Monday, July 14, 2014 12:51:26 PM UTC-7, Randal L. Schwartz wrote:
Any ideas on a cmd.run sequence that runs "service pgpool stop; sleep 5; service pgpool start" that I could use instead of the broken service.watch above?

Aha!  Thanks to "Eureka" on #salt, I was inspired to add some /dev/null redirects to the recipe, and got it to work!


apache_down_before_pgpool:
  service:
  - name: apache22
  - dead
  - prereq:
    - cmd: restart_pgpool

restart_pgpool:
  cmd.wait:
    - name: |
        date
        sleep 3
        service pgpool restart </dev/null >/dev/null 2>&1
        date
    - watch:
      - pkg: pgpool

apache_up_after_pgpool:
  service:
  - name: apache22
  - running
  - require:
    - cmd: restart_pgpool

Les Mikesell

unread,
Jul 14, 2014, 5:44:54 PM7/14/14
to salt-users, dmitry.g...@xiag.ch
On Mon, Jul 14, 2014 at 4:07 PM, Randal L. Schwartz
<merlyn...@stonehenge.com> wrote:
>
>>
>> Any ideas on a cmd.run sequence that runs "service pgpool stop; sleep 5;
>> service pgpool start" that I could use instead of the broken service.watch
>> above?
>
>
> Aha! Thanks to "Eureka" on #salt, I was inspired to add some /dev/null
> redirects to the recipe, and got it to work!

So - next step: figure out how to start your postgresql cluster on
different boxes first. Then write the book for the rest of us.

--
Les Mikesell
lesmi...@gmail.com
Reply all
Reply to author
Forward
0 new messages