Advertisement
smileface

/etc/init.d/kiwiirc

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