2021-09-25 02:37:35 +02:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
set -o pipefail
|
|
|
|
|
2022-05-20 02:51:27 +02:00
|
|
|
ABS_LOG_DIR="/var/log/audiobookshelf"
|
2022-01-15 17:31:05 +01:00
|
|
|
|
2021-09-25 02:37:35 +02:00
|
|
|
declare -r init_type='auto'
|
|
|
|
declare -ri no_rebuild='0'
|
|
|
|
|
|
|
|
start_service () {
|
|
|
|
: "${1:?'Service name was not defined'}"
|
|
|
|
declare -r service_name="$1"
|
|
|
|
|
|
|
|
if hash systemctl 2> /dev/null; then
|
|
|
|
if [[ "$init_type" == 'auto' || "$init_type" == 'systemd' ]]; then
|
|
|
|
{
|
|
|
|
systemctl enable "$service_name.service" && \
|
|
|
|
systemctl start "$service_name.service"
|
|
|
|
} || echo "$service_name could not be registered or started"
|
|
|
|
fi
|
|
|
|
elif hash service 2> /dev/null; then
|
|
|
|
if [[ "$init_type" == 'auto' || "$init_type" == 'upstart' || "$init_type" == 'sysv' ]]; then
|
|
|
|
service "$service_name" start || echo "$service_name could not be registered or started"
|
|
|
|
fi
|
|
|
|
elif hash start 2> /dev/null; then
|
|
|
|
if [[ "$init_type" == 'auto' || "$init_type" == 'upstart' ]]; then
|
|
|
|
start "$service_name" || echo "$service_name could not be registered or started"
|
|
|
|
fi
|
|
|
|
elif hash update-rc.d 2> /dev/null; then
|
|
|
|
if [[ "$init_type" == 'auto' || "$init_type" == 'sysv' ]]; then
|
|
|
|
{
|
|
|
|
update-rc.d "$service_name" defaults && \
|
|
|
|
"/etc/init.d/$service_name" start
|
|
|
|
} || echo "$service_name could not be registered or started"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo 'Your system does not appear to use systemd, Upstart, or System V, so the service could not be started'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-05-20 02:51:27 +02:00
|
|
|
# Create log directory if not there and set ownership
|
|
|
|
if [ ! -d "$ABS_LOG_DIR" ]; then
|
|
|
|
mkdir -p "$ABS_LOG_DIR"
|
|
|
|
chown -R 'audiobookshelf:audiobookshelf' "$ABS_LOG_DIR"
|
|
|
|
fi
|
2021-09-25 02:37:35 +02:00
|
|
|
|
|
|
|
start_service 'audiobookshelf'
|