Chinaunix首页 | 论坛 | 博客
  • 博客访问: 841135
  • 博文数量: 116
  • 博客积分: 1472
  • 博客等级: 上尉
  • 技术积分: 1725
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-06 11:45
文章分类

全部博文(116)

文章存档

2015年(1)

2014年(42)

2013年(5)

2012年(19)

2011年(49)

我的朋友

分类: 其他平台

2014-02-19 11:59:29

这个启动脚本适用于Ubuntu、Debian和其它BSD衍生系统,当transmission-daemon安装包没有提供启动脚本的情况下才使用。

Installtion

对于Debian及其衍生系统(如Ubuntu),启动脚本存放在/etc/init.d/下,假定这个脚本名为transmission-daemon,即/etc/init.d/transmission-daemon
对于其它一些发行版transmission-daemon启动脚本可能位于下面两个位置:
 
/var/lib/transmission-daemon 和 /var/run/transmission.

Make the script executable and make sure the privileges are correctly set:
  1. chmod +x /etc/init.d/transmission-daemon
  2. chown root:root /etc/init.d/transmission-daemon
这个脚本范本中有一个用户名变量USERNAME,且设定其值为transmission。可以根据个人习惯改变这个变量的值。默认情况下,这个脚本以 'transmission'这个用户身份运行transmsision-daemon.(疑问:如果root执行这个脚本,会发生什么情况?)

Configure

官方建议以启动脚本中的这个用户变量所设定的用户来运行Transmission,并且为了安全考虑,创建该用户时不要设置密码,以用户名transmission为例:

  1. $ adduser --disabled-password transmission
或者

  1. $ adduser -D transmission

User

启动

  1. /etc/init.d/transmission-daemon start

停止

  1. /etc/init.d/transmission-daemon stop



Script "transmission-daemon"

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: transmission-daemon
  4. # Required-Start: networking
  5. # Required-Stop: networking
  6. # Default-Start: 2 3 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Start the transmission BitTorrent daemon client.
  9. ### END INIT INFO

  10. # Original Author: Lennart A. J??tte, based on Rob Howell's script
  11. # Modified by Maarten Van Coile & others (on IRC)

  12. # Do NOT "set -e"

  13. #
  14. # ----- CONFIGURATION -----
  15. #
  16. # For the default location Transmission uses, visit:
  17. # http://trac.transmissionbt.com/wiki/ConfigFiles
  18. # For a guide on how set the preferences, visit:
  19. # http://trac.transmissionbt.com/wiki/EditConfigFiles
  20. # For the available environement variables, visit:
  21. # http://trac.transmissionbt.com/wiki/EnvironmentVariables
  22. #
  23. # The name of the user that should run Transmission.
  24. # It's RECOMENDED to run Transmission in it's own user,
  25. # by default, this is set to 'transmission'.
  26. # For the sake of security you shouldn't set a password
  27. # on this user
  28. USERNAME=transmission


  29. # ----- *ADVANCED* CONFIGURATION -----
  30. # Only change these options if you know what you are
  31. #
  32. # The folder where Transmission stores the config & web files.
  33. # ONLY change this you have it at a non-default location
  34. #TRANSMISSION_HOME="/var/config/transmission-daemon"
  35. #TRANSMISSION_WEB_HOME="/usr/share/transmission/web"
  36. #
  37. # The arguments passed on to transmission-daemon.
  38. # ONLY change this you need to, otherwise use the
  39. # settings file as per above.
  40. #TRANSMISSION_ARGS=""


  41. # ----- END OF CONFIGURATION -----
  42. #
  43. # PATH should only include /usr/* if it runs after the mountnfs.sh script.
  44. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  45. DESC="bittorrent client"
  46. NAME=transmission-daemon
  47. DAEMON=$(which $NAME)
  48. PIDFILE=/var/run/$NAME.pid
  49. SCRIPTNAME=/etc/init.d/$NAME

  50. # Exit if the package is not installed
  51. [ -x "$DAEMON" ] || exit 0

  52. # Read configuration variable file if it is present
  53. [ -r /etc/default/$NAME ] && . /etc/default/$NAME

  54. # Load the VERBOSE setting and other rcS variables
  55. [ -f /etc/default/rcS ] && . /etc/default/rcS

  56. #
  57. # Function that starts the daemon/service
  58. #

  59. do_start()
  60. {
  61.     # Export the configuration/web directory, if set
  62.     if [ -n "$TRANSMISSION_HOME" ]; then
  63.           export TRANSMISSION_HOME
  64.     fi
  65.     if [ -n "$TRANSMISSION_WEB_HOME" ]; then
  66.           export TRANSMISSION_WEB_HOME
  67.     fi

  68.     # Return
  69.     # 0 if daemon has been started
  70.     # 1 if daemon was already running
  71.     # 2 if daemon could not be started
  72.     start-stop-daemon --chuid $USERNAME --start --pidfile $PIDFILE --make-pidfile \
  73.             --exec $DAEMON --background --test -- -f $TRANSMISSION_ARGS > /dev/null \
  74.             || return 1
  75.     start-stop-daemon --chuid $USERNAME --start --pidfile $PIDFILE --make-pidfile \
  76.             --exec $DAEMON --background -- -f $TRANSMISSION_ARGS \
  77.             || return 2
  78. }

  79. #
  80. # Function that stops the daemon/service
  81. #
  82. do_stop()
  83. {
  84.         # Return
  85.         # 0 if daemon has been stopped
  86.         # 1 if daemon was already stopped
  87.         # 2 if daemon could not be stopped
  88.         # other if a failure occurred
  89.         start-stop-daemon --stop --quiet --retry=TERM/10/KILL/5 --pidfile $PIDFILE --exec $DAEMON
  90.         RETVAL="$?"
  91.         [ "$RETVAL" = 2 ] && return 2

  92.         # Wait for children to finish too if this is a daemon that forks
  93.         # and if the daemon is only ever run from this initscript.
  94.         # If the above conditions are not satisfied then add some other code
  95.         # that waits for the process to drop all resources that could be
  96.         # needed by services started subsequently. A last resort is to
  97.         # sleep for some time.

  98.         start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  99.         [ "$?" = 2 ] && return 2

  100.         # Many daemons don't delete their pidfiles when they exit.
  101.         rm -f $PIDFILE

  102.         return "$RETVAL"
  103. }

  104. case "$1" in
  105.   start)
  106.         echo "Starting $DESC" "$NAME..."
  107.         do_start
  108.         case "$?" in
  109.                 0|1) echo " Starting $DESC $NAME succeeded" ;;
  110.                 *) echo " Starting $DESC $NAME failed" ;;
  111.         esac
  112.         ;;
  113.   stop)
  114.         echo "Stopping $DESC $NAME..."
  115.         do_stop
  116.         case "$?" in
  117.                 0|1) echo " Stopping $DESC $NAME succeeded" ;;
  118.                 *) echo " Stopping $DESC $NAME failed" ;;
  119.         esac
  120.         ;;
  121.   restart|force-reload)
  122.         #
  123.         # If the "reload" option is implemented then remove the
  124.         # 'force-reload' alias
  125.         #
  126.         echo "Restarting $DESC $NAME..."
  127.         do_stop
  128.         case "$?" in
  129.           0|1)
  130.                 do_start
  131.                 case "$?" in
  132.                     0|1) echo " Restarting $DESC $NAME succeeded" ;;
  133.                     *) echo " Restarting $DESC $NAME failed: couldn't start $NAME" ;;
  134.                 esac
  135.                 ;;
  136.           *)
  137.                 echo " Restarting $DESC $NAME failed: couldn't stop $NAME" ;;
  138.         esac
  139.         ;;
  140.   *)
  141.         echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  142.         exit 3
  143.         ;;
  144. 参考文件:
阅读(6599) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~