Advertisement
Guest User

Untitled

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