Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. name=`basename $0`
  4. pid_file="/var/run/$name.pid"
  5. stdout_log="/var/log/$name.log"
  6. stderr_log="/var/log/$name.err"
  7.  
  8. dir="/tmp"
  9. user="root"
  10. device="wlan0"
  11. cmd="/sbin/udhcpc -b -i $device -x hostname:$(/bin/hostname) -p $pid_file >/dev/null"
  12.  
  13. get_pid() {
  14. cat "$pid_file"
  15. }
  16.  
  17. is_running() {
  18. [ -f "$pid_file" ] && kill -0 `get_pid` > /dev/null 2>&1
  19.  
  20. # [ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
  21. }
  22.  
  23. case "$1" in
  24. start)
  25. if is_running; then
  26. echo "Already started"
  27. else
  28. echo "Starting $name"
  29. cd "$dir"
  30. sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log"
  31. fi
  32. ;;
  33. stop)
  34. if is_running; then
  35. echo -n "Stopping $name.."
  36. kill `get_pid`
  37. for i in {1..10}
  38. do
  39. if ! is_running; then
  40. break
  41. fi
  42.  
  43. echo -n "."
  44. sleep 1
  45. done
  46. echo
  47.  
  48. if is_running; then
  49. echo "Not stopped; may still be shutting down or shutdown may have failed"
  50. exit 1
  51. else
  52. echo "Stopped"
  53. if [ -f "$pid_file" ]; then
  54. rm "$pid_file"
  55. fi
  56. fi
  57. else
  58. echo "Not running"
  59. fi
  60. ;;
  61. restart)
  62. $0 stop
  63. if is_running; then
  64. echo "Unable to stop, will not attempt to start"
  65. exit 1
  66. fi
  67. $0 start
  68. ;;
  69. status)
  70. if is_running; then
  71. echo "Running"
  72. else
  73. echo "Stopped"
  74. exit 1
  75. fi
  76. ;;
  77. *)
  78. echo "Usage: $0 {start|stop|restart|status}"
  79. exit 1
  80. ;;
  81. esac
  82.  
  83. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement