Last active
October 7, 2016 11:57
-
-
Save j0inty/7a100b7d6e8014142613b78881ec150d to your computer and use it in GitHub Desktop.
Icecast2 Streaming Client init.d for OpenRC
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
#!/sbin/openrc-run | |
# Copyright 1999-2016 Gentoo Foundation | |
# Distributed under the terms of the GNU General Public License v2 | |
# $Id$ | |
RUNAS_USER="${RUNAS_USER:-icecast}" | |
RUNAS_GROUP="${RUNAS_GROUP:-nogroup}" | |
CONFIG_FILE="${CONFIG_FILE:-/etc/icecast2/ezstream.xml}" | |
LOG_FILE="${LOG_FILE:-/var/log/icecast2/ezstream.log}" | |
LOCAL_ICECAST=${LOCAL_ICECAST:-yes} | |
AUTO_GENERATE_PLAYLIST="${AUTO_GENERATE_PLAYLIST:-yes}" | |
PLAYLIST="${PLAYLIST:-/run/icecast2/playlist.m3u}" | |
FORMAT="${FORMAT:-mp3}" | |
pidfile="${PIDFILE:-/run/icecast2/ezstream.pid}" | |
name="Icecast2 Streaming Client" | |
description="Ezstream is a command line source client for Icecast media streaming servers. It began as the successor of the old “shout” utility, and has since gained a lot of useful features." | |
description_reload="Send the SIGHUP to the process to read the ${CONFIG_FILE} again. The process id of running daemon can be found in ${pidfile}" | |
description_next_title="Send the SIGUSR1 to the process to skip the currently playing track and moves on to the next in playlist mode, or restarts the current track when streaming a single file." | |
required_files="${CONFIG_FILE}" | |
command="/usr/bin/ezstream" | |
command_args="-c ${CONFIG_FILE} ${EZSTREAM_OPTS}" | |
command_background="true" | |
start_stop_daemon_args="--stdout ${LOG_FILE} --stderr ${LOG_FILE}" | |
extra_started_commands="reload next_title" | |
depend() { | |
if yesno "${LOCAL_ICECAST}"; then | |
need icecast | |
else | |
need net | |
# We should be after bootmisc so that /run is cleaned before we put our pidfile there. | |
after bootmisc | |
fi | |
} | |
start_pre() { | |
# create directory for pid and autogenerated playlist | |
checkpath --directory --owner ${RUNAS_USER}:${RUNAS_GROUP} --mode 0775 "$(dirname "${pidfile}")" | |
# create directory for LOG_FILE | |
checkpath --directory --owner ${RUNAS_USER}:${RUNAS_GROUP} --mode 0775 "$(dirname "${LOG_FILE}")" | |
if yesno "${AUTO_GENERATE_PLAYLIST}"; then | |
checkpath --file --file-truncate --owner ${RUNAS_USER}:${RUNAS_GROUP} --mode 0664 "${PLAYLIST}" | |
create_playlist "${FILES_DIR}" "${FORMAT}" | |
fi | |
} | |
reload() { | |
ebegin "Reloading ${name} configuration" | |
start-stop-daemon --signal HUP --pidfile "${pidfile}" | |
eend $? | |
} | |
next_title() { | |
ebegin "${name} skip to the next track from playlist ${PLAYLIST}" | |
start-stop-daemon --signal USR1 --pidfile "${pidfile}" | |
eend $? | |
} | |
create_playlist() { | |
local format_files_dir="$1" | |
local format="$2" | |
ebegin "Scanning ${format_files_dir} for files in ${FORMAT} format" | |
if [ ! -d "${format_files_dir}" ]; then | |
eend 1 "${format_files_dir} is not a directory" | |
fi | |
find "${format_files_dir}" -name "*.${FORMAT}" -type f -exec echo {} \; > ${PLAYLIST} | |
einfo "${PLAYLIST} with `wc -l < ${PLAYLIST}` ${FORMAT} titles created" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment