Advertisement
kyroskoh

Transmission-Daemon Start Script

Jul 10th, 2014
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # chkconfig: - 16 84
  4. # description: Start up transmission-daemon
  5. #
  6. # processname: transmission-daemon
  7. # config: /etc/sysconfig/transmission
  8.  
  9. # source function library
  10. . /etc/rc.d/init.d/functions
  11.  
  12. # Get network config
  13. . /etc/sysconfig/network
  14.  
  15. [ "${NETWORKING}" = "no" ] && exit 0
  16.  
  17. # Defaults
  18. TRANSMISSION_HOME=/home/torrent
  19.  
  20. DAEMON_USER="torrent"
  21. DAEMON_ARGS="-g $TRANSMISSION_HOME/.config/transmission/"
  22.  
  23. # Daemon
  24. NAME=transmission-daemon
  25.  
  26. DAEMON=$(which $NAME)
  27. DAEMON_PIDFILE=/var/run/$NAME.pid
  28. DAEMON_LOCKFILE=/var/lock/subsys/$NAME
  29. DAEMON_SCRIPTNAME=/etc/init.d/$NAME
  30. DAEMON_LOGFILE=/var/log/$NAME.log
  31.  
  32. [ -x "$DAEMON" ] || exit 0
  33.  
  34. start() {
  35. echo -n $"Starting ${NAME}: "
  36.  
  37. if [ -n "$TRANSMISSION_HOME" ]; then
  38. export TRANSMISSION_HOME
  39. fi
  40.  
  41. su - $DAEMON_USER -c "$DAEMON $DAEMON_ARGS"
  42.  
  43. sleep 2
  44.  
  45. status $NAME &> /dev/null && echo_success || echo_failure
  46. RETVAL=$?
  47.  
  48. if [ $RETVAL -eq 0 ]; then
  49. touch $DAEMON_LOCKFILE
  50. pidof -o %PPID -x $NAME > $DAEMON_PIDFILE
  51. fi
  52.  
  53. echo
  54. }
  55.  
  56. stop() {
  57. echo -n $"Shutting down ${NAME}: "
  58.  
  59. killproc $NAME
  60. RETVAL=$?
  61.  
  62. [ $RETVAL -eq 0 ] && /bin/rm -f $DAEMON_LOCKFILE $DAEMON_PIDFILE
  63.  
  64. echo
  65. }
  66.  
  67. case "$1" in
  68. start)
  69. start
  70. ;;
  71. stop)
  72. stop
  73. ;;
  74. restart)
  75. stop
  76. start
  77. ;;
  78. status)
  79. status $NAME
  80. ;;
  81.  
  82. *)
  83. echo "Usage: $SCRIPTNAME {start|stop|restart|status}" >&2
  84. exit 3
  85. ;;
  86. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement