Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. dan@Caffeine:/etc/init.d$ sudo /etc/init.d/irssid start
  2. [sudo] password for dan:
  3. * Mandatory option 'user' was not specified in '/home/dan/.irssi/config'
  4.  
  5. #!/bin/bash
  6.  
  7. ### BEGIN INIT INFO
  8. # Provides: irssid
  9. # Required-Start: $network
  10. # Required-Stop: $network
  11. # Default-Start: 2 3 4 5
  12. # Default-Stop: 0 1 6
  13. # Short-Description: Start irssi daemon within screen session at boot time
  14. # Description: This init script will start an irssi session under screen using the settings provided in /etc/irssid.conf
  15. ### END INIT INFO
  16.  
  17.  
  18. # Include the LSB library functions
  19. . /lib/lsb/init-functions
  20.  
  21.  
  22. # Setup static variables
  23. configFile='/home/dan/.irssi/config'
  24. daemonExec='/usr/bin/screen'
  25. daemonArgs='-D -m -S irc'
  26. daemonName="$(basename "$daemonExec")"
  27. pidFile='/var/run/irssid.pid'
  28.  
  29.  
  30. #
  31. # Checks if the environment is capable of running the script (such as
  32. # availability of programs etc).
  33. #
  34. # Return: 0 if the environmnt is properly setup for execution of init script, 1
  35. # if not all conditions have been met.
  36. #
  37. function checkEnvironment() {
  38. # Verify that the necessary binaries are available for execution.
  39. local binaries=(irssi screen)
  40.  
  41. for bin in "${binaries[@]}"; do
  42. if ! which "$bin" > /dev/null; then
  43. log_failure_msg "Binary '$bin' is not available. Please install \
  44. package containing it."
  45. exit 5
  46. fi
  47. done
  48. }
  49.  
  50.  
  51. #
  52. # Checks if the configuration files are available and properly setup.
  53. #
  54. # Return: 0 if irssid if properly configured, 1 otherwise.
  55. #
  56. function checkConfig() {
  57. # Make sure the configuration file has been created
  58. if ! [ -f $configFile ]; then
  59. log_failure_msg "Please populate the configuration file '$configFile' \
  60. before running."
  61. exit 6
  62. fi
  63.  
  64. # Make sure the required options have been set
  65. local reqOptions=(user group session)
  66. for option in "${reqOptions[@]}"; do
  67. if ! grep -q -e "^[:blank:]*$option=" "$configFile"; then
  68. log_failure_msg "Mandatory option '$option' was not specified in \
  69. '$configFile'"
  70. exit 6
  71. fi
  72. done
  73. }
  74.  
  75.  
  76. #
  77. # Loads the configuration file and performs any additional configuration steps.
  78. #
  79. function configure() {
  80. . "$configFile"
  81. daemonArgs="$daemonArgs -S $session irssi"
  82. [ -n $args ] && daemonArgs="$daemonArgs $args"
  83. daemonCommand="$daemonExec $daemonArgs"
  84. }
  85.  
  86.  
  87. #
  88. # Starts the daemon.
  89. #
  90. # Return: LSB-compliant code.
  91. #
  92. function start() {
  93. start-stop-daemon --start --quiet --oknodo --pidfile "$pidFile" \
  94. --make-pidfile --chuid "$user:$group" --background \
  95. --exec "$daemonExec" -- $daemonArgs
  96. }
  97.  
  98.  
  99. #
  100. # Stops the daemon.
  101. #
  102. # Return: LSB-compliant code.
  103. #
  104. function stop() {
  105. start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile "$pidFile" \
  106. --chuid "$user:$group" --exec "$daemonExec" -- $daemonArgs
  107. }
  108.  
  109.  
  110. checkEnvironment
  111. checkConfig
  112. configure
  113.  
  114. case "$1" in
  115. start)
  116. log_daemon_msg "Starting daemon" "irssid"
  117. start && log_end_msg 0 || log_end_msg $?
  118. ;;
  119. stop)
  120. log_daemon_msg "Stopping daemon" "irssid"
  121. stop && log_end_msg 0 || log_end_msg $?
  122. ;;
  123. restart)
  124. log_daemon_msg "Restarting daemon" "irssid"
  125. stop
  126. start && log_end_msg 0 || log_end_msg $?
  127. ;;
  128. force-reload)
  129. log_daemon_msg "Restarting daemon" "irssid"
  130. stop
  131. start && log_end_msg 0 || log_end_msg $?
  132. ;;
  133. status)
  134. status_of_proc -p "$pidFile" "$daemonExec" screen && exit 0 || exit $?
  135. ;;
  136. *)
  137. echo "irssid (start|stop|restart|force-reload|status|help)"
  138. ;;
  139. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement