Add systemd unit file
diff --git a/aptly/files/aptly-api.service b/aptly/files/aptly-api.service
new file mode 100644
index 0000000..d4476c3
--- /dev/null
+++ b/aptly/files/aptly-api.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=Aptly API server
+Requires=network-online.target
+After=network.target
+
+[Service]
+User=aptly
+EnvironmentFile=/etc/default/aptly-api
+ExecStart=/usr/bin/aptly api serve -listen=${LISTEN_HOST}:${LISTEN_PORT}
+Restart=on-failure
+
+[Install]
+WantedBy=multi-user.target
diff --git a/aptly/server/api.sls b/aptly/server/api.sls
index b7a635f..4cf59ab 100644
--- a/aptly/server/api.sls
+++ b/aptly/server/api.sls
@@ -4,7 +4,17 @@
include:
- aptly.server
-aptly_api_init_script:
+{%- if grains.init == 'systemd' %}
+aptly_api_service_file:
+ file.managed:
+ - name: /etc/systemd/system/aptly-api.service
+ - source: salt://aptly/files/aptly-api.service
+ - user: root
+ - group: root
+ - require:
+ - pkg: aptly_packages
+{%- else %}
+aptly_api_service_file:
file.managed:
- name: /etc/init.d/aptly-api
- source: salt://aptly/files/init.d/aptly-api
@@ -14,6 +24,7 @@
- template: jinja
- require:
- pkg: aptly_packages
+{%- endif %}
aptly_api_config:
file.managed:
@@ -28,7 +39,7 @@
service.running:
- name: aptly-api
- watch:
- - file: aptly_api_init_script
+ - file: aptly_api_service_file
- file: aptly_api_config
- file: aptly_conf
- pkg: aptly_packages