summaryrefslogtreecommitdiff
path: root/usr/libexec
diff options
context:
space:
mode:
Diffstat (limited to 'usr/libexec')
-rwxr-xr-xusr/libexec/commission/commission45
-rwxr-xr-xusr/libexec/commission/commission-php-fpm77
-rw-r--r--[-rwxr-xr-x]usr/libexec/commission/off.sh10
3 files changed, 130 insertions, 2 deletions
diff --git a/usr/libexec/commission/commission b/usr/libexec/commission/commission
new file mode 100755
index 0000000..52d88ba
--- /dev/null
+++ b/usr/libexec/commission/commission
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
+DAEMON=/usr/sbin/lighttpd
+DAEMONNAME="lighttpd"
+NAME=commission
+DESC="MT lighttpd Commissioning Server"
+OPTS="-f /etc/lighttpd-commission.conf"
+PIDFILE=/var/run/lighttpd-commission.pid
+CONF_DIR=/var/config
+ENABLED=yes
+
+PASSWORDS=$(passwd -Sa | egrep '^[^[:space:]]+[[:space:]]P[[:space:]]' | wc -l)
+
+if (($PASSWORDS == 0)) ; then
+ # No password, so indicate commissioning mode
+ # php-fpm-commision will be turned on as well
+ rm -f "/run/mt-commission"
+ echo 'ENABLED="yes"' >"/run/mt-commission"
+else
+ ENABLED="no"
+ echo 'ENABLED="no"' >"/run/mt-commission"
+fi
+
+[ -f "/etc/default/no-${NAME}" ] && . "/etc/default/no-${NAME}"
+
+if [ ! -f $CONF_DIR/server.pem ]; then
+ echo "Generating server cert"
+ openssl req \
+ -x509 -nodes -days 3650 \
+ -subj '/C=US/ST=Minnesota/L=Minneapolis/CN=mlinux.example.com' \
+ -newkey rsa:2048 -keyout $CONF_DIR/server.pem -out $CONF_DIR/server.pem
+fi
+
+if [ "$ENABLED" != "yes" ]; then
+ echo "Some user has a password"
+ if [ "$VERBOSE" = very ] ; then
+ passwd -Sa | egrep '^[^[:space:]]+[[:space:]]P[[:space:]]' | logger -s -p daemon.notice
+ echo "user count with passwords: $PASSWORDS"
+ fi
+ exit
+fi
+echo -n "Starting $DESC: "
+"$DAEMON" $OPTS
+echo "$NAME."
diff --git a/usr/libexec/commission/commission-php-fpm b/usr/libexec/commission/commission-php-fpm
new file mode 100755
index 0000000..f3a53b4
--- /dev/null
+++ b/usr/libexec/commission/commission-php-fpm
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+### BEGIN INIT INFO
+# Provides: php-fpm
+# Required-Start: $remote_fs $network
+# Required-Stop: $remote_fs $network
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: starts php-fpm
+# Description: starts the PHP FastCGI Process Manager daemon
+### END INIT INFO
+
+DESC="MT php commissioning server "
+NAME="php-fpm-commission"
+prefix=/usr
+exec_prefix=/usr
+
+php_fpm_BIN=/usr/sbin/php-fpm
+php_fpm_CONF="/etc/${NAME}.conf"
+php_fpm_PID="/var/run/${NAME}.pid"
+
+
+php_opts="-R --fpm-config $php_fpm_CONF --pid $php_fpm_PID"
+ENABLED=yes
+
+wait_for_pid () {
+ try=0
+
+ while test $try -lt 35 ; do
+
+ case "$1" in
+ 'created')
+ if [ -f "$2" ] ; then
+ try=''
+ break
+ fi
+ ;;
+
+ 'removed')
+ if [ ! -f "$2" ] ; then
+ try=''
+ break
+ fi
+ ;;
+ esac
+
+ echo -n .
+ try=`expr $try + 1`
+ sleep 1
+
+ done
+
+}
+
+ [ -f "/run/mt-commission" ] && . "/run/mt-commission"
+ if [[ $ENABLED != "yes" ]]; then
+ echo "$NAME: disabled in /run/mt-commission"
+ exit
+ fi
+
+ echo -n "Starting php-fpm "
+
+ $php_fpm_BIN --daemonize $php_opts
+
+ if [ "$?" != 0 ] ; then
+ echo " failed"
+ exit 1
+ fi
+
+ wait_for_pid created $php_fpm_PID
+
+ if [ -n "$try" ] ; then
+ echo " failed"
+ exit 1
+ else
+ echo " done"
+ fi
diff --git a/usr/libexec/commission/off.sh b/usr/libexec/commission/off.sh
index 6bb51b7..afd3c1f 100755..100644
--- a/usr/libexec/commission/off.sh
+++ b/usr/libexec/commission/off.sh
@@ -1,4 +1,10 @@
#!/bin/bash
+INIT=$(ps --no-headers -o comm -p1)
sleep 30
-/etc/init.d/commission stop 2>&1 | logger -p local0.crit
-/etc/init.d/commission-php-fpm stop 2>&1 | logger -p local0.crit
+if [[ ${INIT} == systemd ]] ; then
+ systemctl stop commission stop
+ systemctl stop commission-php-fpm
+else
+ /etc/init.d/commission stop 2>&1 | logger -p local0.crit
+ /etc/init.d/commission-php-fpm stop 2>&1 | logger -p local0.crit
+fi