#! /bin/sh ### BEGIN INIT INFO # Provides: tcosxmlrpc-server tcos-server # Required-Start: $local_fs $remote_fs # Required-Stop: $local_fs $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start tcosxmlrpc standalone in installed system # Description: This file should be used to construct scripts to be # placed in /etc/init.d. ### END INIT INFO # Author: Mario Izquierdo (mariodebian) # # Do NOT "set -e" # PATH should only include /usr/* if it runs after the mountnfs.sh script PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/lib/tcos VAR_LIST="LLIUREX_TCOS_TEACHER" LLX_GETVAR="/usr/sbin/llxcfg-showvars" eval `${LLX_GETVAR} ${VAR_LIST}` if [ "$LLIUREX_TCOS_TEACHER" != "Y" ]; then exit 0 fi DESC="TcosXMLRPC server" NAME=tcosxmlrpc-server DAEMON=/usr/lib/tcos/$NAME DAEMON_ARGS="/var/lib/tcos/standalone-server/etc/abyss-standalone-server.conf" DAEMON_WWW="/var/lib/tcos/standalone-server/www" SCRIPTNAME=/etc/init.d/$NAME # Exit if the package is not installed [ ! -e $DAEMON ] && exit 0 # Load the VERBOSE setting and other rcS variables [ -e /lib/init/vars.sh ] && . /lib/init/vars.sh # Define LSB log_* functions. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. . /lib/lsb/init-functions # # Function that starts the daemon/service # do_start() { # don't start if start-stop-daemon is not a ELF file (installing in chroot) if [ $(file /sbin/start-stop-daemon |grep -c ELF) != "1" ] ; then log_begin_msg "Fake start-stop-daemon detected, not starting " return 0 fi # start stunnel4 if [ -x "$(which stunnel4)" ] ; then # fix permissions chown -R stunnel4:stunnel4 /var/lib/tcos/standalone-server/lib/stunnel4/ [ -e /var/lib/tcos/standalone-server/log/stunnel.log ] && \ chown stunnel4:stunnel4 /var/lib/tcos/standalone-server/log/stunnel.log # generate SSL cert [ -e /var/lib/tcos/standalone-server/etc/stunnel/tcos.pem ] && \ rm -f /var/lib/tcos/standalone-server/etc/stunnel/tcos.pem openssl req -new -x509 -nodes -days 365 \ -out /var/lib/tcos/standalone-server/etc/stunnel/tcos.pem \ -keyout /var/lib/tcos/standalone-server/etc/stunnel/tcos.pem \ -subj "/C=/ST=/L=/CN=localhost/emailAddress=root@localhost" 2>/dev/null TMP_FILE=$(mktemp /tmp/tcos.ssl.XXXXXXXX) chmod 600 /var/lib/tcos/standalone-server/etc/stunnel/tcos.pem dd if=/dev/urandom of=$TMP_FILE count=2 2>/dev/null openssl dhparam -rand $TMP_FILE 256 >> /var/lib/tcos/standalone-server/etc/stunnel/tcos.pem 2>/dev/null rm -f $TMP_FILE stunnel4 /var/lib/tcos/standalone-server/etc/stunnel/stunnel-server.conf > /dev/null 2>&1 & fi $DAEMON $DAEMON_ARGS >> /var/lib/tcos/standalone-server/log/tcos-standalone.log 2>&1 || return 2 } # # Function that stops the daemon/service # do_stop() { # stop stunnel4 if [ -f /var/lib/tcos/standalone-server/lib/stunnel4/stunnel4.pid ] ; then kill -9 $(cat /var/lib/tcos/standalone-server/lib/stunnel4/stunnel4.pid) 2>/dev/null rm -f /var/lib/tcos/standalone-server/lib/stunnel4/stunnel4.pid [ -e /var/lib/tcos/standalone-server/etc/stunnel/tcos.pem ] && \ rm -f /var/lib/tcos/standalone-server/etc/stunnel/tcos.pem # empty log file cat /dev/null > /var/lib/tcos/standalone-server/log/stunnel.log fi kill $(cat /var/lib/tcos/standalone-server/log/abyss.pid 2>/dev/null ) 2> /dev/null killall tcosxmlrpc-server 2>/dev/null rm -f /var/lib/tcos/standalone-server/log/abyss.pid # clean www data rm -f ${DAEMON_WWW}/* return 0 } # # Function that enable WakeOnLan in all network devices # do_wakeonlan() { # get list of network interfaces TCOS_NET_DEVS=$(ls /sys/class/net/|grep -v lo|grep -v sit0|grep -v wmaster|grep -v vmnet|grep -v vbox) # search for network interfaces with link ok status for dev in $TCOS_NET_DEVS; do # have link ??? if [ -e /sys/class/net/$dev/carrier ] && \ [ "$(cat /sys/class/net/$dev/carrier 2>/dev/null)" = 1 ] && \ [ "$(/usr/sbin/ethtool $dev| grep -c "Wake-on: g")" = "1" ]; then /usr/sbin/ethtool -s $dev wol g > /dev/null 2>&1 fi done } do_checklog_size() { # clean logs when size > 5 MB for logfile in /var/lib/tcos/standalone-server/log/*; do [ $(du $logfile| awk '{print $1}') -gt 5000 ] && \ cat /dev/null > $logfile done } case "$1" in start) log_daemon_msg "Starting $DESC" "$NAME" do_start case "$?" in 0|1) log_end_msg 0 ;; 2) log_end_msg 1 ;; esac ;; stop) log_daemon_msg "Stopping $DESC" "$NAME" # enable WAKEONLAN in ethernet devices (only needed during poweroff/reboot) do_wakeonlan do_stop do_checklog_size case "$?" in 0|1) log_end_msg 0 ;; 2) log_end_msg 1 ;; esac ;; restart|force-reload) # # If the "reload" option is implemented then remove the # 'force-reload' alias # log_daemon_msg "Restarting $DESC" "$NAME" do_stop case "$?" in 0|1) do_start case "$?" in 0) log_end_msg 0 ;; 1) log_end_msg 1 ;; # Old process is still running *) log_end_msg 1 ;; # Failed to start esac ;; *) # Failed to stop log_end_msg 1 ;; esac ;; status) if [ "$(pidof tcosxmlrpc-server | sed '/^$/d')" = "$(cat /var/lib/tcos/standalone-server/log/abyss.pid 2>/dev/null)" ] && \ [ "$(pidof tcosxmlrpc-server | sed '/^$/d')" != "" ] ; then echo "tcosxmlrpc server running" else echo "tcosxmlrpc server stopped" fi ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|status}" >&2 exit 3 ;; esac exit 0