Browse Source

Use systemd service unit configuration for ZNC

Mike Ashley 8 years ago
parent
commit
4afa3c97b0

+ 0
- 139
roles/ircbouncer/files/etc_init.d_znc View File

@@ -1,139 +0,0 @@
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=/usr/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
138
-
139
-:

+ 11
- 0
roles/ircbouncer/files/etc_systemd_system_znc.service View File

@@ -0,0 +1,11 @@
1
+[Unit]
2
+Description=ZNC, an IRC bouncer
3
+After=network.target
4
+
5
+[Service]
6
+ExecStart=/usr/bin/znc --datadir=/usr/lib/znc
7
+PIDFile=/var/run/znc/znc.pid
8
+User=znc
9
+
10
+[Install]
11
+WantedBy=multi-user.target

+ 6
- 3
roles/ircbouncer/tasks/znc.yml View File

@@ -11,8 +11,11 @@
11 11
 - name: Create znc user
12 12
   user: name=znc state=present home=/var/lib/znc system=yes group=znc shell=/usr/sbin/nologin
13 13
 
14
-- name: Copy znc init file into place
15
-  copy: src=etc_init.d_znc dest=/etc/init.d/znc mode=0755
14
+- name: Ensure pid directory exists
15
+  file: state=directory path=/var/run/znc group=znc owner=znc
16
+
17
+- name: Copy znc service file into place
18
+  copy: src=etc_systemd_system_znc.service dest=/etc/systemd/system/znc.service mode=0644
16 19
 
17 20
 - name: Create a combined version of the private key with public cert and intermediate + root CAs
18 21
   shell: cat /etc/ssl/private/wildcard_private.key /etc/ssl/certs/wildcard_combined.pem >
@@ -42,4 +45,4 @@
42 45
   tags: ufw
43 46
 
44 47
 - name: Ensure znc is a system service
45
-  service: name=znc state=started enabled=true
48
+  service: name=znc state=restarted enabled=true

Loading…
Cancel
Save