2020-08-26 18:01:23 +00:00
|
|
|
#!/bin/sh -e
|
2020-09-06 11:44:03 +00:00
|
|
|
# __netbox_gunicorn/manifest
|
2020-08-26 18:01:23 +00:00
|
|
|
|
2020-09-06 11:44:03 +00:00
|
|
|
# Check states
|
|
|
|
state=""
|
|
|
|
unit_state=""
|
|
|
|
param_state="$(cat "$__object/parameter/state")"
|
2020-08-26 18:01:23 +00:00
|
|
|
|
2020-09-06 11:44:03 +00:00
|
|
|
case "$param_state" in
|
|
|
|
enabled|disabled)
|
|
|
|
state="present"
|
|
|
|
unit_state="$param_state"
|
|
|
|
;;
|
|
|
|
|
|
|
|
absent)
|
|
|
|
state="absent"
|
|
|
|
unit_state="disabled"
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
# does not exist
|
|
|
|
printf "The state '%s' does not exist, can't continue!\n" "$param_state" >&2
|
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
2020-10-11 14:39:19 +00:00
|
|
|
mkdir "$__object/files"
|
2020-09-06 11:44:03 +00:00
|
|
|
|
2020-10-11 14:39:19 +00:00
|
|
|
if [ "$state" = "present" ]; then
|
2020-09-06 11:44:03 +00:00
|
|
|
# process template
|
|
|
|
"$__type/files/gunicorn.py.sh" > "$__object/files/gunicorn.py"
|
|
|
|
|
|
|
|
# gunicorn config file
|
|
|
|
__file /opt/netbox/gunicorn.py \
|
|
|
|
--mode 644 --owner netbox \
|
|
|
|
--source "$__object/files/gunicorn.py"
|
|
|
|
|
|
|
|
else
|
|
|
|
# absent config file
|
|
|
|
__file /opt/netbox/gunicorn.py --state absent
|
|
|
|
fi
|
2020-08-26 18:01:23 +00:00
|
|
|
|
|
|
|
|
2020-10-11 14:39:19 +00:00
|
|
|
TYPE="Gunicorn"
|
|
|
|
export TYPE
|
|
|
|
|
|
|
|
"$__type/files/netbox.socket.sh" "$__object/parameter/bind-to" \
|
|
|
|
> "$__object/files/netbox.socket"
|
|
|
|
|
|
|
|
# install systemd files
|
|
|
|
__systemd_unit gunicorn-netbox.socket \
|
|
|
|
--state "$state" --enablement-state "$unit_state" \
|
|
|
|
--source "$__object/files/netbox.socket" --restart
|
2020-08-26 18:01:23 +00:00
|
|
|
__systemd_unit gunicorn-netbox.service \
|
2020-09-06 11:44:03 +00:00
|
|
|
--state "$state" --enablement-state "$unit_state" \
|
|
|
|
--source "$__type/files/netbox.service" --restart
|