diff options
Diffstat (limited to 'misc/upclient/files/upclient.sh')
-rw-r--r-- | misc/upclient/files/upclient.sh | 93 |
1 files changed, 69 insertions, 24 deletions
diff --git a/misc/upclient/files/upclient.sh b/misc/upclient/files/upclient.sh index 70470e68b6fa..f124a7f31218 100644 --- a/misc/upclient/files/upclient.sh +++ b/misc/upclient/files/upclient.sh @@ -1,35 +1,80 @@ #!/bin/sh +# +# $FreeBSD$ +# +# Start or stop upclient. +# -if ! PREFIX=$(expr $0 : "\(/.*\)/etc/rc\.d/$(basename $0)\$"); then - echo "$0: Cannot determine the PREFIX" >&2 - exit 1 -fi +rc_file=${0##*/} +rc_arg=$1 -if [ -f ${PREFIX}/etc/upclient.conf ]; then - if grep -qs '^[ ]*AuthKey[ ]*=' ${PREFIX}/etc/upclient.conf; then - if grep -qs '^[ ]*AuthKey[ ]*=[ ]*<your_authkey>' ${PREFIX}/etc/upclient.conf; then - echo "upclient: AuthKey not configured in ${PREFIX}/etc/upclient.conf -- aborted." >&2 - exit 1 - fi - else - echo "upclient: ${PREFIX}/etc/upclient.conf is out of date -- aborted." >&2 - exit 1 - fi -else - echo "upclient: ${PREFIX}/etc/upclient.conf doesn't exist -- aborted." >&2 - exit 1 +if ! PREFIX=$(expr $0 : "\(/.*\)/etc/rc\.d/${rc_file}\$"); then + echo "${rc_file}: Cannot determine PREFIX." >&2 + echo "Please use the complete pathname." >&2 + exit 64 fi -case "$1" in +program_dir=${PREFIX}/sbin +program_file=upclient +program_path=${program_dir}/${program_file} + +config_dir=${PREFIX}/etc +config_file=${program_file}.conf +config_path=${config_dir}/${config_file} + +pid_dir=/var/run +pid_file=${program_file}.pid +pid_path=${pid_dir}/${pid_file} + +syslog_facility=daemon.err + +case "$rc_arg" in start) - [ -x ${PREFIX}/sbin/upclient ] && ${PREFIX}/sbin/upclient > /dev/null && echo -n ' upclient' - ;; + if [ ! -x ${program_path} ]; then + logger -sp ${syslog_facility} -t ${program_file} \ + "unable to start: ${program_path} is missing." + exit 72 + fi + if [ ! -f ${config_path} ]; then + logger -sp ${syslog_facility} -t ${program_file} \ + "unable to start: ${config_path} is missing." + exit 72 + fi + ws=" " + if ! grep -qs "^[$ws]*AuthKey[$ws]*=" ${config_path}; then + logger -sp ${syslog_facility} -t ${program_file} \ + "unable to start: AuthKey is missing from" \ + "${config_path}." + exit 72 + fi + if grep -qs "^[$ws]*AuthKey[$ws]*=[$ws]*<your_authkey>" ${config_path} + then + logger -sp ${syslog_facility} -t ${program_file} \ + "unable to start: AuthKey isn't configured in" \ + "${config_path}." + exit 72 + fi + ${program_path} && + echo -n " ${program_file}" + ;; stop) - [ -r /var/run/upclient.pid ] && kill `cat /var/run/upclient.pid` > /dev/null && echo -n ' upclient' - ;; + if [ -r ${pid_path} ]; then + kill $(cat ${pid_path}) 2> /dev/null + else + killall ${program_file} 2> /dev/null + fi + ;; +restart) + $0 stop + $0 start + ;; +status) + ps -auxww | egrep ${program_file} | egrep -v "($0|egrep)" + ;; *) - echo "Usage: `basename $0` {start|stop}" >&2 - ;; + echo "usage: ${rc_file} {start|stop|restart|status}" >&2 + exit 64 + ;; esac exit 0 |