This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Help when switching betwen 1.5 and 1.7: services


I've written two scripts that may be useful for others who have both cygwin-1.5 and cygwin-1.7 trees installed. To use them:

put a copy of both scripts into <cygwin-1.5-root>/bin and <cygwin-1.7-root>/bin. Then, when switching from, say, 1.5 to 1.7:

cygwin-1.5$ stop_and_remove_services
cygwin-1.5$ exit

cygwin-1.7$ install_and_start_services

The install_and_atart_services should be customized for your installation -- in fact, it might be useful to customize the two different versions. stop_and_remove_services is pretty generic.

install_and_start_services assumes that the services you specify (via SERVICES_TO_INSTALL) have already been properly configured using the associated foo-config scripts, *in the tree you're invoking the script from*. It's very dumb; everything is hard-coded -- but it's just a transition tool and not worthy of the effort to make it totally generic or to turn it into a 'package' of some sort.

Download and customize...

--
Chuck

P.S. depends on csih.
#!/bin/bash
# must be run as Administrator

stop_and_remove_service() {
  if cygrunsrv -Q $service 2>/dev/null | grep Running >/dev/null 2>&1
  then
    echo "stopping $service" 1>&2
    if ! cygrunsrv -E $service >/dev/null 2>&1
    then
      echo "failed to stop $service" 1>&2
      return 1
    fi
  fi
  if cygrunsrv -Q $service >/dev/null 2>&1
  then
    echo "removing $service" 1>&2
    if ! cygrunsrv -R $service >/dev/null 2>&1
    then
      echo "failed to remove $service" 1>&2
      return 1
    fi
  fi
  return 0
}

stop_and_remove_all_but_syslog_and_cygserver() {
  for service in `cygrunsrv -L`
  do
    case $service in
    *cygserver* ) ;;
    *syslog* ) ;;
    * ) stop_and_remove_service $service ;;
    esac
  done
}
stop_and_remove_syslogs() {
  for service in i`cygrunsrv -L`
  do
    case $service in
    *syslog* ) stop_and_remove_service $service ;;
    esac
  done
}
stop_and_remove_cygservers() {
  for service in `cygrunsrv -L`
  do
    case $service in
    *cygserver* ) stop_and_remove_service $service ;;
    esac
  done
}

stop_and_remove_all_but_syslog_and_cygserver
stop_and_remove_syslogs
stop_and_remove_cygservers

#!/bin/bash
# NOTE: this script assumes that you have previously run the
# appropriate init-* script for the associated services, such
# that all necessary user accounts have been created, and 
# configuration files have been properly constructed, for
# this installation of cygwin.
#
# The ONLY thing this script does is, if necessary, register
# the requested service with the system using hardcoded values,
# and start it.  The services in the following list will be
# installed and started in order.
#
# init, inetd, and sshd are installed under the privileged
# user account, so that they may setuid for new logins or for 
# slave daemons to run under other accounts. For versions of windows
# prior to Vista/Server2003, you may set
#   PRIVILEGED_USER=
# in which case, these three services will be treated like any
# other, and installed under the LocalSystem account.
#
# This script should be copied to /usr/bin and customized for
# (each) installation.

# In the list below:
# Only include 'inetd' if you are not using the init service
#   to start it (and you are not using the xinetd service)
# No default support for install_xinetd, becuase the xinetd-config
#   script only supports using the init service and /etc/rc.d/init.d/xinetd
# Include at most one of 'syslogd' and 'syslog-ng'
SERVICES_TO_INSTALL="cygserver syslog-ng init inetd sshd"

# ======================================================================
# Initialization
# ======================================================================
PROGNAME=$(basename $0)
_tdir=$(dirname $0)
PROGDIR=$(cd $_tdir && pwd)

CSIH_SCRIPT=/usr/share/csih/cygwin-service-installation-helper.sh
PREFIX=/usr
SYSCONFDIR=/etc
LOCALSTATEDIR=/var
source ${CSIH_SCRIPT}

PRIVILEGED_USER=cyg_server
PRIVILEGED_PASS="$1"
if [ -n "$PRIVILEGED_USER" -a  -z "$1" ]
then
  csih_get_value "Please enter the password for $PRIVILEGED_USER" -s
  PRIVILEGED_PASS="${csih_value}"
fi

if [ -n "$PRIVILEGED_USER" -a -z "$PRIVILEGED_PASS" ]
then
  csih_error "Empty password for $PRIVILEGED_USER"
fi

# ======================================================================
# cygserver
# ======================================================================
install_cygserver() {
  if ! cygrunsrv -Q cygserver >/dev/null 2>&1
  then
    csih_inform "installing cygserver" 1>&2
    if ! cygrunsrv -I cygserver -d "CYGWIN cygserver" -p /usr/sbin/cygserver
    then
      csih_error_recoverable "FAILED to install cygserver" 1>&2
      return 1
    fi
  fi
  return 0
}

# ======================================================================
# syslogd
# ======================================================================
install_syslogd() {
  if ! cygrunsrv -Q syslogd >/dev/null 2>&1
  then
    csih_inform "installing syslogd" 1>&2
    if ! cygrunsrv -I syslogd -d "CYGWIN syslogd" -p /usr/sbin/syslogd -a -D
    then
      csih_error_recoverable "FAILED to install syslogd" 1>&2
      return 1
    fi
  fi
  return 0
}

# ======================================================================
# syslog-ng
# ======================================================================
install_syslog-ng() {
  if ! cygrunsrv -Q syslog-ng >/dev/null 2>&1
  then
    csih_inform "installing syslog-ng" 1>&2
    if ! cygrunsrv -I syslog-ng -d "CYGWIN syslog-ng" -p /usr/sbin/syslog-ng -a -F
    then
      csih_error_recoverable "FAILED to install syslog-ng" 1>&2
      return 1
    fi
  fi
  return 0
}

# ======================================================================
# inetd
# ======================================================================
install_inetd() {
  if ! cygrunsrv -Q inetd >/dev/null 2>&1
  then
    csih_inform "installing inetd" 1>&2
    
    if [ -z "${PRIVILEGED_PASS}" ]
    then
      if ! cygrunsrv -I inetd -d "CYGWIN inetd" -p /usr/sbin/inetd -a "-D" -y tcpip -e CYGWIN="ntsec smbntsec"
      then
        csih_error_recoverable "FAILED to install inetd" 1>&2
        return 1
      fi
    else
      if ! cygrunsrv -I inetd -d "CYGWIN inetd" -p /usr/sbin/inetd -a "-D" -y tcpip -e CYGWIN="ntsec smbntsec" -u "$PRIVILEGED_USER" -w "$PRIVILEGED_PASS"
      then
        csih_error_recoverable "FAILED to install inetd" 1>&2
        return 1
      fi
    fi
  fi
  return 0
}

# ======================================================================
# sshd
# ======================================================================
install_sshd() {
  if ! cygrunsrv -Q sshd >/dev/null 2>&1
  then
    csih_inform "installing sshd" 1>&2
    if [ -z "${PRIVILEGED_PASS}" ]
    then
      if ! cygrunsrv -I sshd -d "CYGWIN sshd" -p /usr/sbin/sshd -a "-D" -y tcpip -e CYGWIN="ntsec smbntsec"
      then
        csih_error_recoverable "FAILED to install sshd" 1>&2
        return 1
      fi
    else
      if ! cygrunsrv -I sshd -d "CYGWIN sshd" -p /usr/sbin/sshd -a "-D" -y tcpip -e CYGWIN="ntsec smbntsec" -u "$PRIVILEGED_USER" -w "$PRIVILEGED_PASS"
      then
        csih_error_recoverable "FAILED to install sshd" 1>&2
        return 1
      fi
    fi
  fi
  return 0
}

# ======================================================================
# init
# ======================================================================
install_init() {
  if ! cygrunsrv -Q init >/dev/null 2>&1
  then
    csih_inform "installing init" 1>&2
    if [ -z "${PRIVILEGED_PASS}" ]
    then
      if ! cygrunsrv -I init -d "CYGWIN init" -p /sbin/init -a -i -s INT
      then
        csih_error_recoverable "FAILED to install init" 1>&2
        return 1
      fi
    else
      if ! cygrunsrv -I init -d "CYGWIN init" -p /sbin/init -a -i -s INT -u "$PRIVILEGED_USER" -w "$PRIVILEGED_PASS"
      then
        csih_error_recoverable "FAILED to install init" 1>&2
        return 1
      fi
    fi
  fi
  return 0
}

# ======================================================================
# main loop
# ======================================================================
for service in $SERVICES_TO_INSTALL
do
  instfunc=install_${service}
  if test "$(type -t ${instfunc})" == "function"
  then
    if $instfunc
    then
      if ! cygrunsrv -Q $service 2>/dev/null | grep Running >/dev/null 2>&1
      then
        csih_inform "starting $service" 1>&2
        cygrunsrv -S $service
      fi
    fi
  else
    csih_error_recoverable "There is no installation function for $service" 1>&2
  fi
done


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]