Open main menu

CDOT Wiki β

SYA710 Lab02

SYA710 Lab #2

Focus: Linux Startup

PART A (System V on Fedora 8):

Perform the following steps:

  1. Login to Fedora 8 Test as root.
  2. Type in this script. The name of this script should be called carpal.
  3. #!/bin/sh
    #
    # carpal
    #
    # description: carpald is a program which wakes up every so often and 
    #              tells us that we need to take a break from the keyboard 
    #              or we'll lose all functinality of our wrists and never be 
    #              able to type again as long as we live.
    # chkconfig: 3 92 08
    
    [ -f /usr/local/sbin/carpald ] || exit 0
    
    # source function library
    . /etc/rc.d/init.d/functions
    
    case "$1" in 
      start) 
             echo -n "Starting carpald: "
             daemon /usr/local/sbin/carpald &
             echo
             touch /var/lock/subsys/carpald
             ;;
      stop)  
             echo -n "Stopping carpald services: "
             killproc /usr/local/sbin/carpald
             echo
             rm -f /var/lock/subsys/carpald
             ;;
      status) 
             status /usr/local/sbin/carpald
             ;;
      restart|reload)
             $0 stop
             $0 start
             ;;
      *)
             echo "Usage: carpal {start|stop|status|restart|reload}"
             exit 1
    	 ;;
    esac
    exit 0
    
  4. Save the script in /etc/init.d/ directory.
  5. Now create another script named carpald - this script will be the daemon. Your carpald script can look something like this - but feel free to elaborate.
    #!/bin/sh
    #loop forever
    while :
    do        
        # now sleep for 30 seconds       
        sleep 30       
        # after wakeup send message to all users       
        wall <<EOF               
    Ok people! Time to take a break before               
    you get carpal tunnel syndrome!
    EOF
    done
    
  6. Save your carpald script in directory /usr/local/sbin. Make sure the owner and permissions are set correctly.
  7. Now run the command:
  8.      chkconfig --add carpal
    
  9. Now switch to runlevel 3 with the command:
  10.      telinit 3
    
  11. Login as joker and observe what happens.
  12. Answer questions 1-14 in PART C and then do PART B.

PART B: (Upstart on Ubuntu 8.04)

Perform the following steps:

  1. Login to UbuntuHH Test as root.
  2. Now create a script named carpald - this script will be the daemon. Your carpald script can look something like this - but feel free to elaborate.
    #!/bin/sh
    #loop forever
    while :
    do        
        # now sleep for 30 seconds       
        sleep 30       
        # after wakeup send message to all users       
        wall <<EOF               
    Ok people! Time to take a break before               
    you get carpal tunnel syndrome!
    EOF
    done
    
  3. Save your carpald script in directory /usr/local/sbin. Make sure the owner and permissions are set correctly.
  4. Now create a job file named carpal (use vi) and place it in /etc/event.d/ directory. Ensure the permissions are set correctly.
  5. # carpal - carpald 
    #
    # This service manages carpald to notify users of typing breaks 
    # started until it is shut down again.
    
    start on stopped rc2
    start on stopped rc3
    start on stopped rc4
    start on stopped rc5
    
    stop on runlevel 0
    stop on runlevel 1
    stop on runlevel 6
    
    respawn
    exec /usr/local/sbin/carpald
    
  6. Now check carpal's status with this command:
  7.      status carpal
    
  8. Start the carpal service with this command:
  9.      start carpal
    
  10. Again check the status of the carpal service:
  11.      status carpal
    
  12. Open several terminals and wait 30 seconds and observe what happens.
  13. Once you're sure the carpal service is running properly, you can stop it with this command:
  14.      stop carpal
    
  15. Answer the remaining questions in PART C and email your answers to your teacher.
  16. Write a short blog about Linux startup.

PART C: - Questions

  1. What is your full name and Seneca student ID?
  2. What is the purpose of the wall command?
  3. Identify the full path and names of ALL startup/shutdown links created in step 6.
  4. What is the purpose of the chkconfig command?
  5. What is the purpose of the /etc/init.d/functions script?
  6. What is the difference between the init and telinit commands?
  7. What runlevels does Fedora 8 use and what is the purpose of each?
  8. What is the purpose of the daemon and killproc functions?
  9. What common arguments do startup scripts take?
  10. How is a daemon different from a regular user process?
  11. Where (what directory other than /proc) are process numbers normally saved for currently running daemons.
  12. What is the purpose of the dot (.) command and where is it used in this lab?
  13. What is a lock file used for?
  14. What is the full path name of the lock file used in this lab?