tazpanel rev 51

Implement daemons management
author Christophe Lincoln <pankso@slitaz.org>
date Sat Apr 09 05:45:44 2011 +0200 (2011-04-09)
parents bdb2dbfdba44
children 730f8bcacabc
files TODO boot.cgi lib/libtazpanel styles/default/images/start.png styles/default/images/started.png styles/default/images/stop.png styles/default/images/stopped.png tazpanel.conf
line diff
     1.1 --- a/TODO	Sat Apr 09 00:23:41 2011 +0200
     1.2 +++ b/TODO	Sat Apr 09 05:45:44 2011 +0200
     1.3 @@ -13,4 +13,6 @@
     1.4  	* Improve boot.cgi to handle theming GRUB, fbsplash and Slim and
     1.5  	  improve rcS.conf.
     1.6  	* Handle start-stop-restart daemons and check status in system.cgi
     1.7 +	* Crond management interface
     1.8 +	* Firewall PID file and configuration
     1.9  
     2.1 --- a/boot.cgi	Sat Apr 09 00:23:41 2011 +0200
     2.2 +++ b/boot.cgi	Sat Apr 09 05:45:44 2011 +0200
     2.3 @@ -26,9 +26,114 @@
     2.4  #
     2.5  
     2.6  case "$QUERY_STRING" in
     2.7 +	daemons*)
     2.8 +		#
     2.9 +		# Everything until user login
    2.10 +		#
    2.11 +		# Start and stop a daemom. I think we dont need restart sine 2 
    2.12 +		# clicks and you done
    2.13 +		case "$QUERY_STRING" in
    2.14 +			*=start=*)
    2.15 +				daemon=${QUERY_STRING#*=start=}
    2.16 +				sleep 1
    2.17 +				/etc/init.d/$daemon start | log ;;
    2.18 +			*=stop=*)
    2.19 +				daemon=${QUERY_STRING#*=stop=}
    2.20 +				/etc/init.d/$daemon stop | log ;;
    2.21 +		esac
    2.22 +		. /etc/rcS.conf
    2.23 +		TITLE="- Boot"
    2.24 +		xhtml_header
    2.25 +		debug_info
    2.26 +		cat << EOT
    2.27 +<div id="wrapper">
    2.28 +	<h2>`gettext "Manage deamons"`</h2>
    2.29 +	<p>
    2.30 +		`gettext "Check, start and stop deamons on SliTaz"` 
    2.31 +	</p>
    2.32 +</div>
    2.33 +EOT
    2.34 +		# Demon list
    2.35 +		table_start
    2.36 +		cat << EOT
    2.37 +<thead>
    2.38 +	<tr>
    2.39 +		<td>`gettext "Name"`</td>
    2.40 +		<td>`gettext "Description"`</td>
    2.41 +		<td>`gettext "Status"`</td>
    2.42 +		<td>`gettext "Action"`</td>
    2.43 +		<td>`gettext "PID"`</td>
    2.44 +	</tr>
    2.45 +</thead>
    2.46 +EOT
    2.47 +		cd /etc/init.d
    2.48 +		list="`ls | sed -e /.sh/d -e /rc./d -e /RE/d -e /daemon/d \
    2.49 +			-e /firewall/d`"
    2.50 +		for name in $list
    2.51 +		do
    2.52 +			pkg=""
    2.53 +			pid=""
    2.54 +			status=""
    2.55 +			SHORT_DESC=""
    2.56 +			echo '<tr>'
    2.57 +			# Name
    2.58 +			echo "<td>$name</td>"
    2.59 +			# First check if deamon is started at bootime
    2.60 +			[ echo "RUN_DAEMONS" | fgrep $name ] && boot="on boot"
    2.61 +			# Standard SliTaz busybox deamons and firewall
    2.62 +			case "$name" in
    2.63 +				firewall)
    2.64 +					gettext "<td>SliTaz Firewall with iptable rules</td>" ;;
    2.65 +				httpd)
    2.66 +					gettext "<td>Small and fast web server with CGI support</td>" ;;
    2.67 +				ntpd)
    2.68 +					gettext "<td>Network time protocol deamon</td>" ;;
    2.69 +				ftpd)
    2.70 +					gettext "<td>Anonymous FTP server</td>" ;;
    2.71 +				udhcpd)
    2.72 +					gettext "<td>Busybox DHCP server</td>" ;;
    2.73 +				syslogd|klogd)
    2.74 +					gettext "<td>Linux Kernel log daemon</td>" ;;
    2.75 +				crond|dnsd|tftpd|inetd|zcip)
    2.76 +					gettext "<td>Deamon powered by BusyBox</td>" ;;
    2.77 +				*)
    2.78 +					# Descrition from receipt
    2.79 +					[ -d "$LOCALSTATE/installed/$name" ] && pkg=$name
    2.80 +					[ -d "$LOCALSTATE/installed/${name%d}" ] && pkg=${name%d}
    2.81 +					[ -d "$LOCALSTATE/installed/${name}-pam" ] && pkg=${name}-pam
    2.82 +					if [ "$pkg" ]; then
    2.83 +						. $LOCALSTATE/installed/$pkg/receipt
    2.84 +						echo "<td>$SHORT_DESC</td>"
    2.85 +					else
    2.86 +						echo "<td>----</td>"
    2.87 +					fi ;;
    2.88 +			esac
    2.89 +			# Attemp to get daemon status
    2.90 +			pidfile=`find /var/run -name *$name*.pid`
    2.91 +			[ "$pidfile" ] && pid=`cat $pidfile`
    2.92 +			# dbus
    2.93 +			[ -f /var/run/${name}/pid ] && pid=`cat /var/run/${name}/pid`
    2.94 +			# apache
    2.95 +			[ "$name" = "apache" ] && pid=`cat /var/run/$name/httpd.pid`
    2.96 +			# Pidof works for many daemon
    2.97 +			[ "$pid" ] || pid=`pidof $name`
    2.98 +			if [ "$pid" ]; then
    2.99 +				echo "<td><img src='$IMAGES/started.png' /></td>"
   2.100 +				echo "<td><a href='$SCRIPT_NAME?daemons=stop=$name'>
   2.101 +				<img src='$IMAGES/stop.png' /></a></td>"
   2.102 +				echo "<td>$pid</td>"
   2.103 +			else
   2.104 +				echo "<td>-</td>"
   2.105 +				echo "<td><a href='$SCRIPT_NAME?daemons=start=$name'>
   2.106 +					<img src='$IMAGES/start.png' /></a></td>"
   2.107 +				echo "<td>-----</td>"
   2.108 +			fi
   2.109 +			echo '</tr>'
   2.110 +		done
   2.111 +		table_end ;;
   2.112  	*)
   2.113  		#
   2.114 -		# Everything until user login
   2.115 +		# Default content with summary
   2.116  		#
   2.117  		. /etc/rcS.conf
   2.118  		TITLE="- Boot"
   2.119 @@ -36,59 +141,20 @@
   2.120  		debug_info
   2.121  		cat << EOT
   2.122  <div id="wrapper">
   2.123 -	<h2>`gettext "Boot &amp; startup"`</h2>
   2.124 +	<h2>`gettext "Boot &amp; Start services"`</h2>
   2.125  	<p>
   2.126  		`gettext "Everything that appends before user login."` 
   2.127  	</p>
   2.128  </div>
   2.129  
   2.130 +<div>
   2.131 +	<a class="button" href="$SCRIPT_NAME?daemons">Manage daemons</a>
   2.132 +</div>
   2.133 +
   2.134  <h3>`gettext "Kernel cmdline"`</h3>
   2.135  <pre>
   2.136  `cat /proc/cmdline`
   2.137  </pre>
   2.138 -EOT
   2.139 -		# Demon list
   2.140 -		table_start
   2.141 -		cat << EOT
   2.142 -<thead>
   2.143 -	<tr>
   2.144 -		<td>`gettext "Name"`</td>
   2.145 -		<td>`gettext "Dessciption"`</td>
   2.146 -		<td>`gettext "Status"`</td>
   2.147 -	</tr>
   2.148 -</thead>
   2.149 -EOT
   2.150 -		for d in `echo $RUN_DAEMONS`
   2.151 -		do
   2.152 -			echo '<tr>'
   2.153 -			echo "<td>$d</td>"
   2.154 -			if [ -d "$LOCALSTATE/installed/$d" ]; then
   2.155 -				. $LOCALSTATE/installed/$d/receipt
   2.156 -				echo "<td>$SHORT_DESC</td>"
   2.157 -			else
   2.158 -				# Standard SliTaz deamons
   2.159 -				case "$d" in
   2.160 -					firewall)
   2.161 -						gettext "<td>SliTaz Firewall with iptable rules</td>" ;;
   2.162 -					hald)
   2.163 -						. $LOCALSTATE/installed/hal/receipt
   2.164 -						echo "<td>$SHORT_DESC</td>" ;;
   2.165 -					*)
   2.166 -						echo "<td>N/A</td>" ;;
   2.167 -				esac
   2.168 -			fi
   2.169 -			# Running or not
   2.170 -			if pidof $d; then
   2.171 -				echo "<td>`gettext \"Running\"` (`pidof $d`)</td>"
   2.172 -			else
   2.173 -				gettext "<td>Stopper</td>"
   2.174 -			fi
   2.175 -			echo '</tr>'
   2.176 -		done
   2.177 -
   2.178 -		
   2.179 -		table_end
   2.180 -		cat << EOT
   2.181  <h3>`gettext "Local startup commands"`</h3>
   2.182  <pre>
   2.183  `cat /etc/init.d/local.sh`
     3.1 --- a/lib/libtazpanel	Sat Apr 09 00:23:41 2011 +0200
     3.2 +++ b/lib/libtazpanel	Sat Apr 09 05:45:44 2011 +0200
     3.3 @@ -27,6 +27,11 @@
     3.4  	fi
     3.5  }
     3.6  
     3.7 +# LOG activities
     3.8 +log() {
     3.9 +	grep ^[a-zA-Z0-9] | sed s'/\.*\]//' >> $LOG_FILE
    3.10 +}
    3.11 +
    3.12  # Network interface status
    3.13  interface_status() {
    3.14  	if 	ifconfig | grep -A 1 $i | grep -q inet; then
     4.1 Binary file styles/default/images/start.png has changed
     5.1 Binary file styles/default/images/started.png has changed
     6.1 Binary file styles/default/images/stop.png has changed
     7.1 Binary file styles/default/images/stopped.png has changed
     8.1 --- a/tazpanel.conf	Sat Apr 09 00:23:41 2011 +0200
     8.2 +++ b/tazpanel.conf	Sat Apr 09 05:45:44 2011 +0200
     8.3 @@ -13,7 +13,10 @@
     8.4  FOOTER="/styles/$STYLE/footer.html"
     8.5  
     8.6  # Display some debug message
     8.7 -DEBUG="1"
     8.8 +DEBUG="0"
     8.9 +
    8.10 +# Activity log file
    8.11 +LOG_FILE="/var/log/slitaz/tazpanel.log"
    8.12  
    8.13  # Terminal settings
    8.14  TERMINAL="xterm"