2020-08-26 18:01:23 +00:00
|
|
|
#!/bin/sh -e
|
|
|
|
|
2020-09-06 11:44:03 +00:00
|
|
|
# control state
|
|
|
|
state="$(cat "$__object/parameter/state")"
|
2020-08-26 18:01:23 +00:00
|
|
|
|
2020-09-06 11:44:03 +00:00
|
|
|
case "$state" in
|
|
|
|
# install gunicorn
|
|
|
|
enabled|disabled)
|
|
|
|
curr_installed="$(cat "$__object/explorer/installed")"
|
|
|
|
should_installed="$(cat "$__object/explorer/should_installed")"
|
2020-08-26 18:01:23 +00:00
|
|
|
|
2020-09-06 11:44:03 +00:00
|
|
|
# gunicorn version change
|
|
|
|
if [ "$curr_installed" != "$should_installed" ]; then
|
|
|
|
# (re)installing gunicorn
|
|
|
|
echo "/opt/netbox/venv/bin/pip3 install 'gunicorn==$should_installed'"
|
2020-08-26 18:01:23 +00:00
|
|
|
|
2020-09-06 11:44:03 +00:00
|
|
|
if [ "$curr_installed" != "" ]; then
|
|
|
|
printf "updated %s to %s\n" "$curr_installed" "$should_installed" \
|
|
|
|
>> "$__messages_out"
|
|
|
|
else
|
|
|
|
printf "installed\n" >> "$__messages_out"
|
|
|
|
fi
|
|
|
|
do_restart=yes
|
|
|
|
fi
|
2020-08-26 18:01:23 +00:00
|
|
|
|
2020-09-06 11:44:03 +00:00
|
|
|
# configuration changes
|
|
|
|
if grep -q "^__file/opt/netbox/gunicorn.py:" "$__messages_in"; then
|
|
|
|
do_restart=yes
|
|
|
|
printf "configured\n" >> "$__messages_out"
|
|
|
|
fi
|
2020-08-26 18:01:23 +00:00
|
|
|
|
2020-09-06 11:44:03 +00:00
|
|
|
|
|
|
|
# restart gunicorn
|
|
|
|
if [ "$do_restart" ] && [ "$state" != "disabled" ]; then
|
|
|
|
cat << EOF
|
2020-08-26 18:01:23 +00:00
|
|
|
# Restart service
|
2020-09-09 17:08:46 +00:00
|
|
|
systemctl restart gunicorn-netbox
|
2020-08-26 18:01:23 +00:00
|
|
|
EOF
|
2020-09-06 11:44:03 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
# uninstall
|
|
|
|
absent)
|
|
|
|
# check if installed
|
|
|
|
if [ -s "$__object/explorer/installed" ]; then
|
|
|
|
# service already disabled
|
|
|
|
echo "/opt/netbox/venv/bin/pip3 uninstall -y gunicorn"
|
|
|
|
printf "uninstalled\n" >> "$__messages_out"
|
|
|
|
fi
|
|
|
|
esac
|