summaryrefslogtreecommitdiff
path: root/astro/setiathome/files/setiathome.sh
diff options
context:
space:
mode:
Diffstat (limited to 'astro/setiathome/files/setiathome.sh')
-rw-r--r--astro/setiathome/files/setiathome.sh86
1 files changed, 58 insertions, 28 deletions
diff --git a/astro/setiathome/files/setiathome.sh b/astro/setiathome/files/setiathome.sh
index 57b4a55d22aa..4e6b7e7fe061 100644
--- a/astro/setiathome/files/setiathome.sh
+++ b/astro/setiathome/files/setiathome.sh
@@ -14,15 +14,20 @@ rc_path=${rc_dir}/${rc_file}
rc_arg=$1
# override these variables in ${PREFIX}/etc/rc.setiathome.conf
+set -a
seti_wrkdir=/var/db/${rc_file%.sh} # primary working directory
-seti_std_args=-email # command arguments for standard mode
-seti_reg_args=-login # command arguments for register mode
-seti_proxy_args= # proxy arguments
-seti_user=setiathome # user id to run as
-seti_group=${seti_user} # group id to run as
+seti_std_args="-email -graphics" # startup command line arguments
+seti_reg_args=-login # command line arguments to register
+seti_proxy_server= # HTTP proxy server (hostname:port)
+seti_socks_server= # SOCKS proxy server (hostname:port)
+seti_socks_user= # SOCKS proxy user name
+seti_socks_passwd= # SOCKS proxy password
+seti_user=setiathome # user name to run as
+seti_group=${seti_user} # group name to run as
seti_nice=15 # nice level to run at
seti_maxprocs=$(sysctl -n hw.ncpu) # max. number of processes to start
-seti_sleep=21600 # time to sleep between restarts
+seti_sleep_time=21600 # time to sleep between restarts
+set +a
if ! PREFIX=$(expr ${rc_path} : "\(/.*\)/etc/rc\.d/${rc_file}\$"); then
echo "${rc_file}: Cannot determine PREFIX." >&2
@@ -35,12 +40,30 @@ rcconf_file=rc.${rc_file%.sh}.conf
rcconf_path=${rcconf_dir}/${rcconf_file}
if [ -f ${rcconf_path} ]; then
+ set -a
. ${rcconf_path}
+ set +a
fi
program_dir=${PREFIX}/sbin
program_file=${rc_file%.sh}
program_path=${program_dir}/${program_file}
+export program_path
+
+program_args="\
+${seti_std_args} \
+${seti_proxy_server:+-proxy} ${seti_proxy_server} \
+${seti_socks_server:+-socks_server} ${seti_socks_server} \
+${seti_socks_user:+-socks_user} ${seti_socks_user} \
+${seti_socks_passwd:+-socks_passwd} ${seti_socks_passwd} \
+${seti_nice:+-nice} ${seti_nice} \
+"
+export program_args
+
+
+wrapper_dir=${PREFIX}/libexec
+wrapper_file=${rc_file%.sh}.bin
+wrapper_path=${wrapper_dir}/${wrapper_file}
syslog_facility=daemon.err
@@ -50,6 +73,7 @@ while [ ${i} -gt 1 ]; do
seti_wrksuff="${seti_wrksuff} ${i}"
i=$((${i} - 1))
done
+export seti_wrksuff
case "$rc_arg" in
start)
@@ -73,38 +97,44 @@ start)
exit 72
fi
done
- for i in ${seti_wrksuff}; do
- su -fm ${seti_user} -c "exec /bin/sh -T" << EOF > /dev/null &
- cd ${seti_wrkdir}/${i} || exit
- echo \$\$ > shpid.sah
- trap 'kill \$pid;exit' 15
- while :; do
- ${program_path} \
- ${seti_std_args} ${seti_proxy_args} \
- ${seti_nice:+-nice} ${seti_nice} &
- pid=\$!; wait \$pid
- sleep ${seti_sleep} &
- pid=\$!; wait \$pid
- done
-EOF
- done
+ if ps axo comm | egrep ${program_file}; then
+ logger -sp ${syslog_facility} -t ${program_file} \
+ "unable to start: ${program_file} is already running."
+ exit 72
+ fi
+ su -fm ${seti_user} -c "exec ${wrapper_path} > /dev/null &"
echo -n " SETI@home"
;;
stop)
+ pid_path=${seti_wrkdir}/shpid.sah
+ if [ -f ${pid_path} ]; then
+ pid=$(cat ${pid_path})
+ [ -n "${pid}" ] && ps p ${pid} > /dev/null && kill ${pid}
+ rm -f ${pid_path}
+ fi
for i in ${seti_wrksuff}; do
- for pid_path in ${seti_wrkdir}/${i}/pid.sah \
- ${seti_wrkdir}/${i}/shpid.sah; do
- if [ -f ${pid_path} ]; then
- kill $(cat ${pid_path}) 2> /dev/null
- fi
- done
+ pid_path=${seti_wrkdir}/${i}/pid.sah
+ if [ -f ${pid_path} ]; then
+ pid=$(cat ${pid_path})
+ [ -n "${pid}" ] && ps p ${pid} > /dev/null && kill ${pid}
+ fi
done
if [ ! -f ${seti_wrkdir}/pid.sah ]; then
killall ${program_file} 2> /dev/null
fi
;;
+gracefull)
+ for i in ${seti_wrksuff}; do
+ pid_path=${seti_wrkdir}/${i}/pid.sah
+ stop_path=${seti_wrkdir}/${i}/stop_after_send.txt
+ if [ -f ${pid_path} ]; then
+ touch ${stop_path}
+ fi
+ done
+ ;;
+
restart)
$0 stop
$0 start
@@ -187,7 +217,7 @@ register)
;;
*)
- echo "usage: ${rc_file} {start|stop|restart|status|register}" >&2
+ echo "usage: ${rc_file} {start|stop|gracefull|restart|status|register}" >&2
exit 64
;;
esac