Guest User

dnscrypt-proxy service

a guest
Apr 3rd, 2018
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.31 KB | None | 0 0
  1. #!/bin/sh
  2. # For RedHat and cousins:
  3. # chkconfig: - 99 01
  4. # description: Encrypted/authenticated DNS proxy
  5. # processname: /opt/dnscrypt-proxy/dnscrypt-proxy
  6.  
  7. ### BEGIN INIT INFO
  8. # Provides:          /opt/dnscrypt-proxy/dnscrypt-proxy
  9. # Required-Start:
  10. # Required-Stop:
  11. # Default-Start:     2 3 4 5
  12. # Default-Stop:      0 1 6
  13. # Short-Description: DNSCrypt client proxy
  14. # Description:       Encrypted/authenticated DNS proxy
  15. ### END INIT INFO
  16.  
  17. cmd="/opt/dnscrypt-proxy/dnscrypt-proxy"
  18.  
  19. name=$(basename $(readlink -f $0))
  20. pid_file="/var/run/$name.pid"
  21. stdout_log="/var/log/$name.log"
  22. stderr_log="/var/log/$name.err"
  23.  
  24. [ -e /etc/sysconfig/$name ] && . /etc/sysconfig/$name
  25.  
  26. get_pid() {
  27.     cat "$pid_file"
  28. }
  29.  
  30. is_running() {
  31.     [ -f "$pid_file" ] && ps $(get_pid) > /dev/null 2>&1
  32. }
  33.  
  34. case "$1" in
  35.     start)
  36.         if is_running; then
  37.             echo "Already started"
  38.         else
  39.             echo "Starting $name"
  40.            
  41.             $cmd >> "$stdout_log" 2>> "$stderr_log" &
  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 $(seq 1 10)
  54.             do
  55.                 if ! is_running; then
  56.                     break
  57.                 fi
  58.                 echo -n "."
  59.                 sleep 1
  60.             done
  61.             echo
  62.             if is_running; then
  63.                 echo "Not stopped; may still be shutting down or shutdown may have failed"
  64.                 exit 1
  65.             else
  66.                 echo "Stopped"
  67.                 if [ -f "$pid_file" ]; then
  68.                     rm "$pid_file"
  69.                 fi
  70.             fi
  71.         else
  72.             echo "Not running"
  73.         fi
  74.     ;;
  75.     restart)
  76.         $0 stop
  77.         if is_running; then
  78.             echo "Unable to stop, will not attempt to start"
  79.             exit 1
  80.         fi
  81.         $0 start
  82.     ;;
  83.     status)
  84.         if is_running; then
  85.             echo "Running"
  86.         else
  87.             echo "Stopped"
  88.             exit 1
  89.         fi
  90.     ;;
  91.     *)
  92.     echo "Usage: $0 {start|stop|restart|status}"
  93.     exit 1
  94.     ;;
  95. esac
  96. exit 0
Advertisement
Add Comment
Please, Sign In to add comment