set up custom systemd services

24 views
Skip to first unread message

brad.v...@gmail.com

unread,
Aug 10, 2022, 9:43:30 AM8/10/22
to Salt-users
I'm having trouble getting some custom systemd service files installed and running.  My state file is:

'{% if grains['host'].startswith('server1') or grains['host'].startswith('server2') %}
{% set DIR = 'myservicedir/files' %}

ensure_scripts:
  file.directory:
    - name: /root/scripts
    - user: root
    - group: root
    - dir_mode: 700
    - file_mode: 500
    - recurse:
      - user
      - group
      - mode
     
/root/scripts/start-python-flask.sh:
  file.managed:
    - source: salt://{{ DIR }}/start-python-flask.sh
   
/root/scripts/start-nessus-flask.sh:
  file.managed:
    - source: salt://{{ DIR }}/start-nessus-flask.sh
   
python.service:
  file.managed:
    - name: /etc/systemd/system/docker-python.service
    - source: salt://{{ DIR }}/docker-python.service
    - user: root
    - group: root
    - mode: 644
  module.run:
    - name: service.systemctl_reload
    - onchanges:
      - file: python.service

nessus.service:
  file.managed:
    - name: /etc/systemd/system/docker-nessus.service
    - source: salt://{{ DIR }}/docker-nessus.service
    - user: root
    - group: root
    - mode: 644
  module.run:
    - name: service.systemctl_reload
    - onchanges:
      - file: nessus.service

start_python:
  service.running:
    - name: docker-python
    - enable: true
    - watch:
      - module: python.service

start_nessus:
  service.running:
    - name: docker-nessus
    - enable: true
    - watch:
      - module: nessus.service

{% endif %}'

for the module.run, I get "No function provided."  For the start service, I get "One or more requisite failed."  Anyone have an idea what I might have wrong?

Also, how does one post code to the group such that it is highlighted as code?  I can't seem to find that answer.

Dafydd Jones (techneg.it)

unread,
Aug 10, 2022, 11:42:55 AM8/10/22
to salt-...@googlegroups.com
Hi, 

having attempted something like this before, I was pleased to find out that Salt handles the reloading of the systemd daemon itself when
unit file changes are detected.

As for code highlighting you could just use an online code highlighter such as https://highlight.hohli.com/ and copy and paste, i.e.
start_python:
  service.running:
    - name: docker-python
    - enable: true
    - watch:
      - module: python.service

start_nessus:
  service.running:
    - name: docker-nessus
    - enable: true
    - watch:
      - module: nessus.service
HTH,
Dafydd

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/987de26e-b2c2-4400-8079-61443b71f25en%40googlegroups.com.

brad.v...@gmail.com

unread,
Aug 11, 2022, 6:06:18 AM8/11/22
to Salt-users
Thanks.  I'll try removing the daemon-reload and see how it goes.  Thanks also for the highlight reference!  :)
Reply all
Reply to author
Forward
0 new messages