Outils pour utilisateurs

Outils du site


linux:installation:znc_bouncer_irc

https://wiki.znc.in/Running_ZNC_as_a_system_daemon#Create_the_init.d_Scripts

Installation

agi znc

On va créer un user pour znc :

sudo useradd --create-home -d /var/lib/znc --system --shell /sbin/nologin --comment "Account to run ZNC daemon" --user-group znc
sudo -u znc /usr/bin/znc --datadir=/var/lib/znc --makeconf

Ensure the config file in /var/lib/znc/config/znc.conf instructs ZNC to create a PID file:

echo "PidFile = /var/run/znc/znc.pid" | sudo su - znc -s /bin/bash -c "tee -a /var/lib/znc/configs/znc.conf"

Après avoir répondu aux questions pour la config, on va créer un daemon :

nano /etc/init.d/znc
znc.txt
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: znc
  4. # Required-Start: $remote_fs $syslog
  5. # Required-Stop: $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: ZNC IRC bouncer
  9. # Description: ZNC is an IRC bouncer
  10. ### END INIT INFO
  11.  
  12. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  13. DESC="ZNC daemon"
  14. NAME=znc
  15. DAEMON=/usr/bin/$NAME
  16. DATADIR=/var/lib/znc
  17. DAEMON_ARGS="--datadir=$DATADIR"
  18. PIDDIR=/var/run/znc
  19. PIDFILE=$PIDDIR/$NAME.pid
  20. SCRIPTNAME=/etc/init.d/$NAME
  21. USER=znc
  22. GROUP=znc
  23.  
  24. # Exit if the package is not installed
  25. [ -x "$DAEMON" ] || exit 0
  26.  
  27. # Read configuration variable file if it is present
  28. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  29.  
  30. # Load the VERBOSE setting and other rcS variables
  31. . /lib/init/vars.sh
  32.  
  33. # Define LSB log_* functions.
  34. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  35. # and status_of_proc is working.
  36. . /lib/lsb/init-functions
  37.  
  38. #
  39. # Function that starts the daemon/service
  40. #
  41. do_start()
  42. {
  43. # Return
  44. # 0 if daemon has been started
  45. # 1 if daemon was already running
  46. # 2 if daemon could not be started
  47. if [ ! -d $PIDDIR ]
  48. then
  49. mkdir $PIDDIR
  50. fi
  51. chown $USER:$GROUP $PIDDIR
  52. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test --chuid $USER > /dev/null || return 1
  53. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --chuid $USER -- $DAEMON_ARGS > /dev/null || return 2
  54. }
  55.  
  56. #
  57. # Function that stops the daemon/service
  58. #
  59. do_stop()
  60. {
  61. # Return
  62. # 0 if daemon has been stopped
  63. # 1 if daemon was already stopped
  64. # 2 if daemon could not be stopped
  65. # other if a failure occurred
  66. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME --chuid $USER
  67. RETVAL="$?"
  68. [ "$RETVAL" = 2 ] && return 2
  69. # Wait for children to finish too if this is a daemon that forks
  70. # and if the daemon is only ever run from this initscript.
  71. # If the above conditions are not satisfied then add some other code
  72. # that waits for the process to drop all resources that could be
  73. # needed by services started subsequently. A last resort is to
  74. # sleep for some time.
  75. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON --chuid $USER
  76. [ "$?" = 2 ] && return 2
  77. # Many daemons don't delete their pidfiles when they exit.
  78. rm -f $PIDFILE
  79. return "$RETVAL"
  80. }
  81.  
  82. #
  83. # Function that sends a SIGHUP to the daemon/service
  84. #
  85. do_reload() {
  86. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME --chuid $USER
  87. return 0
  88. }
  89.  
  90. case "$1" in
  91. start)
  92. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  93. do_start
  94. case "$?" in
  95. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  96. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  97. esac
  98. ;;
  99. stop)
  100. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  101. do_stop
  102. case "$?" in
  103. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  104. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  105. esac
  106. ;;
  107. status)
  108. status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
  109. ;;
  110. reload)
  111. log_daemon_msg "Reloading $DESC" "$NAME"
  112. do_reload
  113. log_end_msg $?
  114. ;;
  115. restart)
  116. log_daemon_msg "Restarting $DESC" "$NAME"
  117. do_stop
  118. case "$?" in
  119. 0|1)
  120. do_start
  121. case "$?" in
  122. 0) log_end_msg 0 ;;
  123. 1) log_end_msg 1 ;; # Old process is still running
  124. *) log_end_msg 1 ;; # Failed to start
  125. esac
  126. ;;
  127. *)
  128. # Failed to stop
  129. log_end_msg 1
  130. ;;
  131. esac
  132. ;;
  133. *)
  134. echo "Usage: $SCRIPTNAME {status|start|stop|reload|restart}" >&2
  135. exit 3
  136. ;;
  137. esac
sudo chmod 755 /etc/init.d/znc

Insert the script into the boot sequence :

sudo update-rc.d znc defaults    # For Debian systems

Start the service :

sudo service znc start

Verify that the service is running :

sudo service znc status

Ajout du certificat SSL

On en a déjà un, donc il suffit de faire une copie sur le certificat ZNC : # on fait un backup avant cp /var/lib/znc/znc.pem /var/lib/znc/znc.pem.bak cat /etc/letsencrypt/live/$TON_DNS/{privkey,cert,chain}.pem > /var/lib/znc/znc.pem

Lancement du daemon lors du boot

Create the systemd unit

nano /etc/systemd/system/znc.service
znc.service
  1. [Unit]
  2. Description=ZNC, an advanced IRC bouncer
  3. After=network-online.target
  4.  
  5. [Service]
  6. ExecStart=/usr/bin/znc -f --datadir=/var/lib/znc
  7. User=znc
  8.  
  9. [Install]
  10. WantedBy=multi-user.target

Start the systemd unit and enable it for running on boot

With system service run:

sudo systemctl start znc.service
sudo systemctl enable znc.service

« start » starts the service now and « enable » starts it on boot.

linux/installation/znc_bouncer_irc.txt · Dernière modification : 2022/09/03 16:59 de tutospisto