Advertisement
Guest User

Untitled

a guest
Apr 29th, 2018
896
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. cat /etc/init.d/sdmem
  2. #!/bin/sh
  3. ### BEGIN INIT INFO
  4. # Provides: sdmem
  5. # Required-Start: $local_fs
  6. # Required-Stop: $local_fs
  7. # Default-Start: 0 1 6
  8. # Default-Stop:
  9. # Short-Description: Start sdmem daemon at boot time
  10. # Description: Enable service provided by daemon.
  11. ### END INIT INFO
  12.  
  13. dir="/usr/bin"
  14. cmd="sdmem"
  15. user="root"
  16.  
  17. name=`basename $0`
  18. pid_file="/var/run/$name.pid"
  19. stdout_log="/var/log/$name.log"
  20. stderr_log="/var/log/$name.err"
  21.  
  22. get_pid() {
  23. cat "$pid_file"
  24. }
  25.  
  26. is_running() {
  27. [ -f "$pid_file" ] && ps -p `get_pid` > /dev/null 2>&1
  28. }
  29.  
  30. case "$1" in
  31. start)
  32. if is_running; then
  33. echo "Already started"
  34. else
  35. echo "Starting $name"
  36. cd "$dir"
  37. if [ -z "$user" ]; then
  38. sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
  39. else
  40. sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
  41. fi
  42. echo $! > "$pid_file"
  43. if ! is_running; then
  44. echo "Unable to start, see $stdout_log and $stderr_log"
  45. exit 1
  46. fi
  47. fi
  48. ;;
  49. stop)
  50. if is_running; then
  51. echo -n "Stopping $name.."
  52. kill `get_pid`
  53. for i in 1 2 3 4 5 6 7 8 9 10
  54. # for i in `seq 10`
  55. do
  56. if ! is_running; then
  57. break
  58. fi
  59.  
  60. echo -n "."
  61. sleep 1
  62. done
  63. echo
  64.  
  65. if is_running; then
  66. echo "Not stopped; may still be shutting down or shutdown may have failed"
  67. exit 1
  68. else
  69. echo "Stopped"
  70. if [ -f "$pid_file" ]; then
  71. rm "$pid_file"
  72. fi
  73. fi
  74. else
  75. echo "Not running"
  76. fi
  77. ;;
  78. restart)
  79. $0 stop
  80. if is_running; then
  81. echo "Unable to stop, will not attempt to start"
  82. exit 1
  83. fi
  84. $0 start
  85. ;;
  86. status)
  87. if is_running; then
  88. echo "Running"
  89. else
  90. echo "Stopped"
  91. exit 1
  92. fi
  93. ;;
  94. *)
  95. echo "Usage: $0 {start|stop|restart|status}"
  96. exit 1
  97. ;;
  98. esac
  99.  
  100. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement