Advertisement
Guest User

Mplayer as daemon

a guest
Oct 7th, 2014
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.87 KB | None | 0 0
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          mplayer
  4. # Required-Start:    $remote_fs $syslog
  5. # Required-Stop:     $remote_fs $syslog
  6. # Default-Start:     2 3 4 5
  7. # Default-Stop:      0 1 6
  8. # Short-Description: Example initscript
  9. # Description:       This file should be used to construct scripts to be
  10. #                    placed in /etc/init.d.
  11. ### END INIT INFO
  12.  
  13. # Author: Foo Bar <foobar@baz.org>
  14. #
  15. # Please remove the "Author" lines above and replace them
  16. # with your own name if you copy and modify this script.
  17.  
  18. # Do NOT "set -e"
  19.  
  20. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  21. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  22. DESC="Music"
  23. DAEMONUSER=uberalles
  24. NAME=mplayer
  25. CONTROLFILE="/tmp/mplayercontrol"
  26. DAEMON=/usr/bin/$NAME
  27. DAEMON_ARGS="-loop 0 -shuffle -playlist /media/nfs_share/playlist"
  28. PIDFILE=/var/run/$NAME.pid
  29. SCRIPTNAME=/etc/init.d/$NAME
  30.  
  31. start() {
  32.     echo "Starting mplayer..."
  33.  
  34.     # Prepare fifo file
  35.     rm -rf $CONTROLFILE
  36.     mkfifo $CONTROLFILE
  37.     chmod a+rw $CONTROLFILE
  38.  
  39.     start-stop-daemon --start --quiet --user $DAEMONUSER    \
  40.             --make-pidfile --pidfile $PIDFILE --background       \
  41.             --exec /bin/bash -- -c "HOME=/home/$DAEMONUSER $DAEMON $DAEMON_ARGS > /tmp/mplayerd.log 2>&1"
  42.  
  43.     echo "Started for user: $DAEMONUSER."
  44. }
  45.  
  46. stop() {
  47.     echo "Stopping mplayer..."
  48.     kill -9 `cat $PIDFILE`
  49.     # Cleanup fifo file
  50.     rm -rf $CONTROLFILE
  51. }
  52.  
  53. status() {
  54.     if [ -z `cat $PIDFILE` ];
  55.     then
  56.         echo "mplayerd: not running."
  57.     else
  58.         echo "mplayerd: running."
  59.     fi
  60. }
  61.  
  62.  
  63. case "$1" in
  64.   start)
  65.     start
  66.     ;;
  67.  
  68.   stop)
  69.     stop
  70.     ;;
  71.  
  72.   restart|reload|force-reload)
  73.     stop
  74.     start
  75.     ;;
  76.  
  77.   status)
  78.     status
  79.     ;;
  80.  
  81.   *)
  82.     echo "Usage: /etc/init.d/mplayerd {start|stop|reload|force-reload|restart|status}"
  83.     exit 1
  84.  
  85. esac
  86.  
  87. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement