Add boardvoting init script
authorJan Dittberner <jandd@cacert.org>
Wed, 28 Mar 2018 13:54:19 +0000 (15:54 +0200)
committerJan Dittberner <jandd@cacert.org>
Wed, 28 Mar 2018 13:54:19 +0000 (15:54 +0200)
sitemodules/profiles/files/cacert_boardvoting/init.sh [new file with mode: 0644]
sitemodules/profiles/manifests/cacert_boardvoting.pp

diff --git a/sitemodules/profiles/files/cacert_boardvoting/init.sh b/sitemodules/profiles/files/cacert_boardvoting/init.sh
new file mode 100644 (file)
index 0000000..dc815c6
--- /dev/null
@@ -0,0 +1,91 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides:          boardvoting
+# Required-Start:    $remote_fs
+# Required-Stop:     $remote_fs
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: CAcert board voting system
+# Description:       CAcert board voting system
+### END INIT INFO
+
+PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+
+BASE=boardvoting
+
+BOARDVOTING=/usr/local/bin/cacert-boardvoting
+BOARDVOTING_PIDFILE=/var/run/$BASE.pid
+BOARDVOTING_LOGFILE=/var/log/$BASE.log
+BOARDVOTING_OPTS=
+BOARDVOTING_DESC="Boardvoting"
+
+# Get lsb functions
+. /lib/lsb/init-functions
+
+if [ -f /etc/default/$BASE ]; then
+  . /etc/default/$BASE
+fi
+
+# Check boardvoting is present
+if [ ! -x $BOARDVOTING ]; then
+  log_failure_msg "$BOARDVOTING not present or not executable"
+  exit 1
+fi
+
+fail_unless_root() {
+  if [ "$(id -u)" != '0' ]; then
+    log_failure_msg "$BOARDVOTING_DESC must be run as root"
+    exit 1
+  fi
+}
+
+case "$1" in
+  start)
+    fail_unless_root
+
+    touch "$BOARDVOTING_LOGFILE"
+    chown boardvoting:adm "$BOARDVOTING_LOGFILE"
+
+    log_begin_msg "Starting $BOARDVOTING_DESC: $BOARDVOTING"
+    start-stop-daemon --start --background --no-close \
+      --exec "$BOARDVOTING" \
+      --pidfile "$BOARDVOTING_PIDFILE" \
+      --make-pidfile \
+      -- \
+        $BOARDVOTING_OPTS >> "$BOARDVOTING_LOGFILE" 2>&1
+    log_end_msg $?
+    ;;
+
+  stop)
+    fail_unless_root
+    if [ -f "$BOARDVOTING_PIDFILE" ]; then
+      start-stop-daemon --stop --pidfile "$BOARDVOTING_PIDFILE" --retry 5
+      log_end_msg $?
+    else
+      log_warning_msg "$BOARDVOTING_DESC already stopped - file $BOARDVOTING_PIDFILE not found."
+    fi
+    ;;
+
+  restart)
+    fail_unless_root
+  boardvoting_pid=`cat "$BOARDVOTING_PIDFILE" 2> /dev/null`
+  [ -n "$boardvoting_pid" ] \
+    && ps -p $boardvoting_pid > /dev/null 2>&1 \
+    && $0 stop
+  $0 start
+  ;;
+
+  force-reload)
+    fail_unless_root
+    $0 restart
+    ;;
+
+  status)
+    status_of_proc -p "$BOARDVOTING_PIDFILE" "$BOARDVOTING" "$BOARDVOTING_DESC"
+    ;;
+
+  *)
+    echo "Usage: service boardvoting {start|stop|restart|force-reload|status}"
+    exit 1
+    ;;
+esac
index 8ffaaf0..265d94b 100644 (file)
@@ -42,8 +42,33 @@ class profiles::cacert_boardvoting () {
   }
   file { '/etc/boardvoting':
     ensure  => directory,
+    owner   => 'root',
     group   => 'boardvoting',
     mode    => '0750',
     require => Group['boardvoting'],
   }
+  file { '/etc/boardvoting/ssl':
+    ensure  => directory,
+    owner   => 'root',
+    group   => 'boardvoting',
+    mode    => '0750',
+    require => Group['boardvoting'],
+  }
+  file { '/var/lib/boardvoting':
+    ensure  => directory,
+    owner   => 'boardvoting',
+    group   => 'boardvoting',
+    mode    => '0750',
+    require => User['boardvoting'],
+  }
+  package { 'lsb-base':
+    ensure => latest,
+  }
+  file { '/etc/init.d/boardvoting':
+    ensure => present,
+    owner  => 'root',
+    group  => 'root',
+    mode   => '0755',
+    source => 'puppet:///modules/profiles/cacert_boardvoting/init.sh',
+  }
 }