系統供應下列的自動指令集 /etc/init.d/init.srm,在系統變更為執行層級 2 或 3(多重使用者模式)時,它會以一個啟始引數來執行。而在系統關機時,它會以一個停止引數來執行。
#!/bin/sh # # Copyright (c) 1998 by Sun Microsystems, Inc. # All rights reserved. # # Copyright 1995-1997 Softway Pty. Ltd. # # Start/stop Solaris Resource Manager v1.0 # #ident "@(#)init.srm 1.17 98/10/27 SMI" ####################################################################### # Default values. DATADIR=/var/srm ShareDb=$DATADIR/srmDB LimdaemonOptions= ChargeOptionsOn="limits=y:share=y:adjgroups=y:limshare=y" ChargeOptionsOff="limits=n:share=n:adjgroups=n:limshare=n" LostLnode=srmlost IdleLnode=srmidle ####################################################################### # ECHO=echo # For a verbose startup and shutdown ECHO=: # For a quiet startup and shutdown SRMDIR=/usr/srm SRMBIN=$SRMDIR/bin SRMSBIN=$SRMDIR/sbin ETCSRM=/etc/srm PATH=/sbin:/usr/sbin:/bin:$PATH:$SRMSBIN:$SRMBIN export PATH case "$1" in 'start') if [ ! -x $SRMBIN/srmadm ]; then echo "Solaris Resource Manager *not* installed." \ "Missing srmadm command." exit fi # Only bother if sched/SHR is loaded. if [ `$SRMBIN/srmadm` != yes ] then # # Usually this is because /etc/system doesn't have the usual # set initclass="SHR" # or at least a set extraclass="SHR" # echo "Solaris Resource Manager *not* loaded." exit else echo "Enabling Solaris Resource Manager v1.0." if [ `$SRMBIN/srmadm show fileopen` = yes ]; then echo "SRM database file already open - stopping first." limdaemon -k sleep 2 srmadm set $ChargeOptionsOff sync srmadm set fileopen=n $ECHO "SRM inactive" fi $ECHO "Starting SRM..." fi # Check the limconf file. if [ ! -s $ETCSRM/limconf ]; then echo "SRM - file $ETCSRM/limconf is missing " >&2 echo "SRM not started." exit 1 fi if [ ! -f "$ShareDb" ]; then echo "SRM database '$ShareDb' not present - " \ "creating empty database" if [ ! -d "$DATADIR" ]; then mkdir "$DATADIR" chmod 400 "$DATADIR" chown root "$DATADIR" chgrp root "$DATADIR" fi touch "$ShareDb" || { echo "Failed to create '$ShareDb'" >&2 echo "SRM not started" exit 1 } chmod 400 "$ShareDb" chown root "$ShareDb" chgrp root "$ShareDb" fi CreateLnodes=0 if [ ! -s "$ShareDb" ]; then $ECHO "SRM Warning: Using empty database" >&2 CreateLnodes=1 fi $ECHO "SRM starting ... \c" # Open Lnode file. srmadm set -f "$ShareDb" fileopen=y if [ $? != 0 ]; then echo echo "srmadm set -f $ShareDb failed" >&2 echo "SRM not started" exit 1 fi # Set SRM global options. srmadm set $ChargeOptionsOn if [ $? != 0 ]; then echo echo "srmadm set $ChargeOptionsOn failed" >&2 echo "SRM not completely enabled" exit 1 fi # Create if needed the other lnode. liminfo other 2>/dev/null | grep "^Login name: *other " >/dev/null 2>&1 if [ $? -ne 0 ]; then # If user "other" exists but has no lnode, create one. limadm set cpu.shares=1 other 2>/dev/null limadm set sgroup=root other 2>/dev/null fi # Create if needed, and set the lost lnode. if [ x"$LostLnode" != x ]; then liminfo "$LostLnode" 2>/dev/null | \ grep "^Login name: *$LostLnode " >/dev/null 2>&1 if [ $? -ne 0 ]; then limadm set cpu.shares=1 "$LostLnode" limadm set sgroup=root "$LostLnode" fi srmadm set lost="$LostLnode" || $ECHO "SRM - Warning: No user '$LostLnode' for lost lnode" fi # Create if needed, and set the idle lnode. if [ x"$IdleLnode" != x ]; then liminfo "$IdleLnode" 2>/dev/null | \ grep "^Login name: *$IdleLnode " >/dev/null 2>&1 if [ $? -ne 0 ]; then limadm set cpu.shares=0 "$IdleLnode" limadm set sgroup=root "$IdleLnode" fi srmadm set idle="$IdleLnode" || $ECHO "SRM - Warning: No user '$IdleLnode' for idle lnode" fi # If creating SRM database, set up existing users. if [ "$CreateLnodes" -eq 1 ]; then echo "SRM - creating user lnodes; may take a while" # We now want to catch any other users which were not found # on the filesystems. First we need to decide what the maximum # uid value we will create an l-node entry for in the database. # We choose less than the uid for 'nobody' so that we can try # and minimise the apparent size of the database (which is a sparse # file). If the user 'nobody' does not exist then we just have # to take our chances with using all possible uid values. # Unfortunately all this means that there are certain circumstances # where not all users will be taken into account. MaxUID=`awk -F: "\\$1==\"nobody\" { print \\$3 - 100 }" /etc/passwd` if [ $? -eq 0 -a x"$MaxUID" != x ] ; then Cond="uid >= 0 && uid < $MaxUID && !flag.real" else Cond="uid >= 0 && !flag.real" fi UIDS=`limreport "$Cond" '%d\n' uid | wc -l` if [ $UIDS -gt 0 ]; then $ECHO "$UIDS other lnodes to be created " \ "due to passwd entries" limreport "$Cond" 'limadm set -u sgroup=0:cpu.shares=1 %d\necho " uid %7d\r\c"\n' uid uid | sh echo fi fi limdaemon $LimdaemonOptions echo "Solaris Resource Manager v1.0 Enabled." ;; 'stop') # SRM shutdown should be done as late as possible before # filesystems are unmounted. if [ -x $SRMBIN/srmadm ] && $SRMBIN/srmadm show fileopen > /dev/null then limdaemon -k sleep 2 srmadm set $ChargeOptionsOff srmadm set fileopen=n sync $ECHO "Solaris Resource Manager Disabled" fi ;; *) echo "Usage: $0 {start|stop}" ;; esac
此指令集在預設的排程群組中建立 lnode(如果密碼映射中存在此類使用者的話為 other,否則為 root。)並且以郵件提醒系統管理員要將新的 lnode 移入排程階層中的適當位置。
#!/bin/sh # #ident "@(#)nolnode.sh 1.6 98/10/28 SMI" # # Copyright (c) 1998 by Sun Microsystems, Inc. # All rights reserved. # # Copyright 1995-1997 Softway Pty. Ltd. # # A script that called by the PAM module to create a lnode # PATH=/usr/srm/bin:/sbin:/bin export PATH LOCALE=C export LOCALE if [ "$DEBUG" = "true" ] then exec >> /tmp/nolnodelog 2>&1 echo date echo "Attempting to create lnode for $USER" else exec > /dev/null 2>&1 fi err=`limadm set -u cpu.shares=1 "$UID" 2>&1` if [ $? -eq 0 ] then cat <<-EOF | /usr/lib/sendmail root Subject: New lnode created for "$USER" Remember to change scheduling group and shares for "$USER". `limreport lname=='"'"$USER"'"' 'Currently in group "%s" with %d shares\\n' sgroupname cpu.shares` EOF else cat <<-EOF | /usr/lib/sendmail root Subject: Could not create lnode for "$USER" after "$SERVICE" attempt on tty "$TTY", uid "$UID", rhost \""$RHOST"\", limadm said \""$err"\" EOF exit 1 # deny access fi # permit access exit 0