# Suggestion for handling a service without init/systemd/upstart ?

**URL:** <https://forum.ansible.com/t/suggestion-for-handling-a-service-without-init-systemd-upstart/12552>\
**Category:** Ansible Project\
**Created:** [March 21, 2013, 5:04pm UTC](https://forum.ansible.com/t/suggestion-for-handling-a-service-without-init-systemd-upstart/12552 "2013-03-21T17:04:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Green](https://avatars.discourse-cdn.com/v4/letter/b/e495f1/32.png) [@Brian\_Green](https://forum.ansible.com/u/Brian_Green)\
**Post date:** [March 21, 2013, 5:04pm UTC](https://forum.ansible.com/t/suggestion-for-handling-a-service-without-init-systemd-upstart/12552/1 "2013-03-21T17:04:50Z")

</div>

I have to manage some systems without root access, and our services are handled with init-style scripts with status/stop/start and so forth, but not managed with any of the common process management systems.

I would like to have Ansible manage these, but the service module currently does not accomodate such a situation. I can’t do anything about ensuring these processes run at boot, but being able to stop/start, ensure running/stopped in some manner would be nice.

I was considering using register variables in the following manner as a bit of a workaround.

```auto
- name: ensure service running
  hosts: all

  tasks:

      - action: script /my/script status
        register: service_status

      - action: script /my/script start
        only_if: "'${service_status.stdout}'.find('stopped') = -1"

```

Better ideas? I’d like to contribute and maybe modify the service module to acommodate scripts/binaries, but my skills are limited in this area.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [March 21, 2013, 5:36pm UTC](https://forum.ansible.com/t/suggestion-for-handling-a-service-without-init-systemd-upstart/12552/2 "2013-03-21T17:36:13Z")

</div>

I'm not sure we'd want to modify the service module to support  
improper services, but I think you could make something like the  
service module called 'bad\_service' that did similar.

I would recommend "when\_string" and "in", BTW:

when\_string: 'stopped' in ${service\_status.stdout}

a bit cleaner!

--Michael

---

<div class="post-metadata">

**Author:** ![Edu\_el\_Ligre](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@Edu\_el\_Ligre](https://forum.ansible.com/u/Edu_el_Ligre)\
**Post date:** [March 23, 2013, 9:22pm UTC](https://forum.ansible.com/t/suggestion-for-handling-a-service-without-init-systemd-upstart/12552/3 "2013-03-23T21:22:15Z")

</div>

Hi there,

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [March 23, 2013, 10:44pm UTC](https://forum.ansible.com/t/suggestion-for-handling-a-service-without-init-systemd-upstart/12552/4 "2013-03-23T22:44:05Z")

</div>

> From where did you get solr?

---

<div class="post-metadata">

**Author:** ![Eduardo\_Esclapes\_Gim](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@Eduardo\_Esclapes\_Gim](https://forum.ansible.com/u/Eduardo_Esclapes_Gim)\
**Post date:** [March 23, 2013, 11:29pm UTC](https://forum.ansible.com/t/suggestion-for-handling-a-service-without-init-systemd-upstart/12552/5 "2013-03-23T23:29:46Z")

</div>

I am currently using the example jetty instance that comes with solr 3.x

And I got the init script[1] that is recommended in solr-jetty docs[2]

[1]: [http://svn.codehaus.org/jetty/jetty/branches/jetty-6.1/bin/jetty.sh](http://svn.codehaus.org/jetty/jetty/branches/jetty-6.1/bin/jetty.sh)  
[2]: [http://wiki.apache.org/solr/SolrJetty#Init\_script\_to\_run\_the\_Solr\_example](http://wiki.apache.org/solr/SolrJetty#Init_script_to_run_the_Solr_example)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [March 24, 2013, 2:20am UTC](https://forum.ansible.com/t/suggestion-for-handling-a-service-without-init-systemd-upstart/12552/6 "2013-03-24T02:20:34Z")

</div>

Ok, this seems to just be an upstream issue then.

If you install SOLR from a distribution the init scripts should pass  
distribution review processes and be good to go.

The command module is really ok, I woudn't worry too much about it  
executing start if it's already started because the init script should  
be handling the idempotency for you.
