Created
May 8, 2021 16:17
-
-
Save Nattefrost/14e84e7139f32cd9b1777ed8a5d498b9 to your computer and use it in GitHub Desktop.
bash script for Filebrowser on FreeBSD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bash script for FreeBSD that acts as a daemon supporting | |
# stop/start/restart for the Filebrowser program | |
# - https://github.com/filebrowser/filebrowser | |
# drop in /usr/local/bin/ and chmod +x, then use as filebrowser_service stop|start|restart | |
workdir=/home/nattefrost/ | |
pid_file=/tmp/filebrowser.pid | |
log_file=/tmp/filebrowser.log | |
function start_filebrowser { | |
local new_pid | |
cd "${workdir}" || { echo "Could not cd to ${workdir}"; exit 1; } | |
if [ -z "$(ps aux | awk '$11 ~ /^filebrowser$/')" ] | |
then | |
truncate -s 0 "${log_file}" | |
( filebrowser >> "${log_file}" 2>&1 ) & | |
new_pid="${!}" | |
echo "${new_pid}" > "${pid_file}" | |
echo "Filebrowser started with pid ${new_pid}" | |
else | |
echo "Filebrowser is already running" | |
fi | |
} | |
function stop_filebrowser { | |
local cur_pid | |
test -f ${pid_file} || { echo "pid file not found"; } | |
cur_pid="$(cat ${pid_file})" | |
echo "Attempting to kill process ${cur_pid}" | |
kill -9 "${cur_pid}" | |
if [ "${?}" = 0 ] | |
then | |
echo "Filebrowser service stopped" | |
rm "${pid_file}" | |
fi | |
} | |
function restart_filebrowser { | |
stop_filebrowser | |
start_filebrowser | |
} | |
case "${1}" in | |
"stop") | |
stop_filebrowser | |
;; | |
"start") | |
start_filebrowser | |
;; | |
"restart") | |
restart_filebrowser | |
;; | |
*) | |
echo "Unknown CLI argument: '${1}'" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment