Move icecast to systemd

This commit is contained in:
Bob Mottram 2017-11-25 21:06:27 +00:00
parent 0ca44f5eab
commit ec184e0c14
1 changed files with 46 additions and 85 deletions

View File

@ -49,89 +49,47 @@ icecast_variables=(MY_USERNAME
DEFAULT_LANGUAGE)
function icecast_update_daemon {
echo '#! /bin/sh' > /etc/init.d/icecast2
echo '#' >> /etc/init.d/icecast2
echo '# icecast2' >> /etc/init.d/icecast2
echo '#' >> /etc/init.d/icecast2
echo '# Written by Miquel van Smoorenburg <miquels@cistron.nl>.' >> /etc/init.d/icecast2
echo '# Modified for Debian' >> /etc/init.d/icecast2
echo '# by Ian Murdock <imurdock@gnu.ai.mit.edu>.' >> /etc/init.d/icecast2
echo '#' >> /etc/init.d/icecast2
echo '# Further modified by Keegan Quinn <ice@thebasement.org>' >> /etc/init.d/icecast2
echo '# for use with Icecast 2' >> /etc/init.d/icecast2
echo '#' >> /etc/init.d/icecast2
echo '' >> /etc/init.d/icecast2
echo 'PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin' >> /etc/init.d/icecast2
echo 'DAEMON=/usr/bin/icecast2' >> /etc/init.d/icecast2
echo 'NAME=icecast2' >> /etc/init.d/icecast2
echo 'DESC=icecast2' >> /etc/init.d/icecast2
echo 'ICES=/usr/bin/ices2' >> /etc/init.d/icecast2
echo 'ICES_CONFIGFILE=/etc/ices2/ices-playlist.xml' >> /etc/init.d/icecast2
echo '' >> /etc/init.d/icecast2
echo 'test -x $DAEMON || exit 0' >> /etc/init.d/icecast2
echo '' >> /etc/init.d/icecast2
echo '# Defaults' >> /etc/init.d/icecast2
echo 'CONFIGFILE="/etc/icecast2/icecast.xml"' >> /etc/init.d/icecast2
echo 'CONFIGDEFAULTFILE="/etc/default/icecast2"' >> /etc/init.d/icecast2
echo 'USERID=icecast2' >> /etc/init.d/icecast2
echo 'GROUPID=icecast' >> /etc/init.d/icecast2
echo 'ENABLE="false"' >> /etc/init.d/icecast2
echo '' >> /etc/init.d/icecast2
echo '# Reads config file (will override defaults above)' >> /etc/init.d/icecast2
echo '[ -r "$CONFIGDEFAULTFILE" ] && . $CONFIGDEFAULTFILE' >> /etc/init.d/icecast2
echo '' >> /etc/init.d/icecast2
echo 'if [ "$ENABLE" != "true" ]; then' >> /etc/init.d/icecast2
echo ' echo "$NAME daemon disabled - read $CONFIGDEFAULTFILE."' >> /etc/init.d/icecast2
echo ' exit 0' >> /etc/init.d/icecast2
echo 'fi' >> /etc/init.d/icecast2
echo '' >> /etc/init.d/icecast2
echo 'set -e' >> /etc/init.d/icecast2
echo '' >> /etc/init.d/icecast2
echo 'case "$1" in' >> /etc/init.d/icecast2
echo ' start)' >> /etc/init.d/icecast2
echo ' echo -n "Starting $DESC: "' >> /etc/init.d/icecast2
echo ' start-stop-daemon --start --quiet --chuid $USERID:$GROUPID \' >> /etc/init.d/icecast2
echo ' --exec $DAEMON -- -b -c $CONFIGFILE' >> /etc/init.d/icecast2
echo ' sleep 3' >> /etc/init.d/icecast2
echo ' start-stop-daemon --start --quiet --exec $ICES $ICES_CONFIGFILE' >> /etc/init.d/icecast2
echo ' echo "$NAME."' >> /etc/init.d/icecast2
echo ' ;;' >> /etc/init.d/icecast2
echo ' stop)' >> /etc/init.d/icecast2
echo ' echo -n "Stopping $DESC: "' >> /etc/init.d/icecast2
echo ' start-stop-daemon --stop --oknodo --quiet --exec $ICES' >> /etc/init.d/icecast2
echo '' >> /etc/init.d/icecast2
echo ' start-stop-daemon --stop --oknodo --quiet --exec $DAEMON' >> /etc/init.d/icecast2
echo ' echo "$NAME."' >> /etc/init.d/icecast2
echo ' ;;' >> /etc/init.d/icecast2
echo ' reload|force-reload)' >> /etc/init.d/icecast2
echo ' echo "Reloading $DESC configuration files."' >> /etc/init.d/icecast2
echo ' start-stop-daemon --stop --oknodo --quiet --exec $ICES' >> /etc/init.d/icecast2
echo ' start-stop-daemon --stop --signal 1 --quiet --exec $DAEMON' >> /etc/init.d/icecast2
echo ' sleep 3' >> /etc/init.d/icecast2
echo ' start-stop-daemon --start --quiet --exec $ICES $ICES_CONFIGFILE' >> /etc/init.d/icecast2
echo ' ;;' >> /etc/init.d/icecast2
echo ' restart)' >> /etc/init.d/icecast2
echo ' echo -n "Restarting $DESC: "' >> /etc/init.d/icecast2
echo ' start-stop-daemon --stop --oknodo --quiet --exec $ICES' >> /etc/init.d/icecast2
echo '' >> /etc/init.d/icecast2
echo ' start-stop-daemon --stop --oknodo --quiet --exec $DAEMON' >> /etc/init.d/icecast2
echo ' sleep 3' >> /etc/init.d/icecast2
echo ' start-stop-daemon --start --quiet --chuid $USERID:$GROUPID \' >> /etc/init.d/icecast2
echo ' --exec $DAEMON -- -b -c $CONFIGFILE' >> /etc/init.d/icecast2
echo ' sleep 3' >> /etc/init.d/icecast2
echo ' start-stop-daemon --start --quiet --exec $ICES $ICES_CONFIGFILE' >> /etc/init.d/icecast2
echo ' echo "$NAME."' >> /etc/init.d/icecast2
echo ' ;;' >> /etc/init.d/icecast2
echo ' *)' >> /etc/init.d/icecast2
echo ' echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2' >> /etc/init.d/icecast2
echo ' exit 1' >> /etc/init.d/icecast2
echo ' ;;' >> /etc/init.d/icecast2
echo 'esac' >> /etc/init.d/icecast2
echo '' >> /etc/init.d/icecast2
echo 'exit 0' >> /etc/init.d/icecast2
systemctl stop icecast2
if [ -f /etc/init.d/icecast2 ]; then
rm /etc/init.d/icecast2
fi
echo '[Unit]' > /etc/systemd/system/icecast2.service
echo 'Description=Icecast' >> /etc/systemd/system/icecast2.service
echo 'After=network.target' >> /etc/systemd/system/icecast2.service
echo 'After=tor.service' >> /etc/systemd/system/icecast2.service
echo '' >> /etc/systemd/system/icecast2.service
echo '[Service]' >> /etc/systemd/system/icecast2.service
echo 'User=icecast2' >> /etc/systemd/system/icecast2.service
echo 'Group=icecast' >> /etc/systemd/system/icecast2.service
echo "ExecStart=/usr/bin/icecast2 -c /etc/icecast2/icecast.xml" >> /etc/systemd/system/icecast2.service
echo 'Restart=on-failure' >> /etc/systemd/system/icecast2.service
echo 'RestartSec=10' >> /etc/systemd/system/icecast2.service
echo '' >> /etc/systemd/system/icecast2.service
echo '[Install]' >> /etc/systemd/system/icecast2.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/icecast2.service
echo '[Unit]' > /etc/systemd/system/ices2.service
echo 'Description=Icecast' >> /etc/systemd/system/ices2.service
echo 'After=network.target' >> /etc/systemd/system/ices2.service
echo 'After=tor.service' >> /etc/systemd/system/ices2.service
echo 'After=icecast2.service' >> /etc/systemd/system/ices2.service
echo '' >> /etc/systemd/system/ices2.service
echo '[Service]' >> /etc/systemd/system/ices2.service
echo 'User=icecast2' >> /etc/systemd/system/ices2.service
echo 'Group=icecast' >> /etc/systemd/system/ices2.service
echo "ExecStart=/usr/bin/ices2 /etc/ices2/ices-playlist.xml" >> /etc/systemd/system/ices2.service
echo 'Restart=on-failure' >> /etc/systemd/system/ices2.service
echo 'RestartSec=10' >> /etc/systemd/system/ices2.service
echo '' >> /etc/systemd/system/ices2.service
echo '[Install]' >> /etc/systemd/system/ices2.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ices2.service
systemctl daemon-reload
systemctl enable icecast2
systemctl enable ices2
systemctl restart icecast2
systemctl restart ices2
}
function change_password_icecast {
@ -169,7 +127,7 @@ function icecast_convert_files {
echo $'Converting any mp4 files to ogv format'
find . -type f -name '*.mp4' -exec bash -c 'ffmpeg -i "$0" -c:a libvorbis -q:a 4 "${f/%mp4/ogv}' '{}' \;
chown -R icecast2:icecast2 $ICECAST_DIR
chown -R icecast2:icecast $ICECAST_DIR
}
function icecast_add_file_to_playlist {
@ -192,7 +150,7 @@ function icecast_add_file_to_playlist {
fi
done
chown icecast2:icecast2 $ICECAST_PLAYLIST_FILE
chown icecast2:icecast $ICECAST_PLAYLIST_FILE
systemctl restart icecast2
}
@ -426,7 +384,7 @@ function restore_local_icecast {
fi
cp $ICECAST_DIR/.icepasswd /etc/nginx/.icepasswd
rm $ICECAST_DIR/.icepasswd
chown -R icecast2:icecast2 $ICECAST_DIR
chown -R icecast2:icecast $ICECAST_DIR
systemctl start icecast2
rm -rf $temp_restore_dir
@ -462,7 +420,7 @@ function restore_remote_icecast {
fi
cp $ICECAST_DIR/.icepasswd /etc/nginx/.icepasswd
rm $ICECAST_DIR/.icepasswd
chown -R icecast2:icecast2 $ICECAST_DIR
chown -R icecast2:icecast $ICECAST_DIR
systemctl start icecast2
rm -rf $temp_restore_dir
@ -646,7 +604,7 @@ function install_icecast {
if [ ! -d $ICECAST_DIR ]; then
mkdir $ICECAST_DIR
fi
chown -R icecast2:icecast2 $ICECAST_DIR
chown -R icecast2:icecast $ICECAST_DIR
# create a password for users
@ -663,6 +621,9 @@ function install_icecast {
${PROJECT_NAME}-pass -u $MY_USERNAME -a icecast -p "$ICECAST_PASSWORD"
${PROJECT_NAME}-pass -u $MY_USERNAME -a icecastuser -p "$ICECAST_USER_PASSWORD"
groupadd icecast
useradd -c "Icecast system account" -d /etc/icecast2 -m -r -g icecast icecast2
icecast_update_daemon
nginx_ensite icecast
systemctl restart nginx