Lines 2-106
Link Here
|
2 |
# |
2 |
# |
3 |
# $FreeBSD: ports/astro/setiathome/files/setiathome.sh,v 1.5 2001/07/04 14:27:58 kevlo Exp $ |
3 |
# $FreeBSD: ports/astro/setiathome/files/setiathome.sh,v 1.5 2001/07/04 14:27:58 kevlo Exp $ |
4 |
# |
4 |
# |
5 |
# Start or stop setiathome, or set up working directory and register |
5 |
# Start or stop SETI@home, or set up working directory and register. |
6 |
# |
6 |
# |
7 |
|
7 |
|
8 |
# override these variables in ${PREFIX}/etc/setiathome.conf |
8 |
rc_file=${0##*/} |
|
|
9 |
rc_arg=$1 |
10 |
|
11 |
# override these variables in ${PREFIX}/etc/rc.setiathome.conf |
9 |
seti_wrkdir=/var/db/setiathome # primary working directory |
12 |
seti_wrkdir=/var/db/setiathome # primary working directory |
10 |
seti_bindir=!!SUBDIR!! # exec directory relative to ${PREFIX} |
|
|
11 |
seti_command=setiathome # command name |
12 |
seti_std_args=-email # command arguments for standard mode |
13 |
seti_std_args=-email # command arguments for standard mode |
13 |
seti_reg_args=-login # command arguments for register mode |
14 |
seti_reg_args=-login # command arguments for register mode |
14 |
seti_proxy_args= # proxy arguments |
15 |
seti_proxy_args= # proxy arguments |
15 |
seti_user=nobody # user id to run as |
16 |
seti_user=nobody # user id to run as |
16 |
seti_nice=1 # nice level to run at |
17 |
seti_nice=15 # nice level to run at |
17 |
seti_maxprocs=`sysctl -n hw.ncpu` # max. number of processes to start |
18 |
seti_maxprocs=$(sysctl -n hw.ncpu) # max. number of processes to start |
18 |
seti_syslog=daemon.err # syslog facility.level |
|
|
19 |
|
19 |
|
20 |
if ! PREFIX=$(expr $0 : "\(/.*\)/etc/rc\.d/${0##*/}\$"); then |
20 |
if ! PREFIX=$(expr $0 : "\(/.*\)/etc/rc\.d/${rc_file}\$"); then |
21 |
echo "${0##*/}: Cannot determine PREFIX." >&2 |
21 |
echo "${rc_file}: Cannot determine PREFIX." >&2 |
22 |
echo "Please use the complete pathname." >&2 |
22 |
echo "Please use the complete pathname." >&2 |
23 |
exit 64 |
23 |
exit 64 |
24 |
fi |
24 |
fi |
|
|
25 |
|
26 |
rcconf_dir=${PREFIX}/etc |
27 |
rcconf_file=rc.${rc_file%.sh}.conf |
28 |
rcconf_path=${rcconf_dir}/${rcconf_file} |
25 |
|
29 |
|
26 |
if [ -f ${PREFIX}/etc/setiathome.conf ]; then |
30 |
if [ -f ${rcconf_path} ]; then |
27 |
. ${PREFIX}/etc/setiathome.conf |
31 |
. ${rcconf_path} |
28 |
fi |
32 |
fi |
29 |
|
33 |
|
|
|
34 |
program_dir=${PREFIX}/sbin |
35 |
program_file=setiathome |
36 |
program_path=${program_dir}/${program_file} |
37 |
|
38 |
syslog_facility=daemon.err |
39 |
|
30 |
i=${seti_maxprocs} |
40 |
i=${seti_maxprocs} |
31 |
seti_wrksuff="." |
41 |
seti_wrksuff="." |
32 |
while [ ${i} -gt 1 ]; do |
42 |
while [ ${i} -gt 1 ]; do |
33 |
seti_wrksuff="${seti_wrksuff} ${i}" |
43 |
seti_wrksuff="${seti_wrksuff} ${i}" |
34 |
i=`expr ${i} - 1` |
44 |
i=$((${i} - 1)) |
35 |
done |
45 |
done |
36 |
|
46 |
|
37 |
case $1 in |
47 |
case "$rc_arg" in |
38 |
start) |
48 |
start) |
39 |
for i in ${seti_wrksuff}; do |
49 |
if [ ! -x ${program_path} ]; then |
40 |
if [ ! -d ${seti_wrkdir}/${i} ]; then |
50 |
logger -sp ${syslog_facility} -t ${program_file} \ |
41 |
logger -sp ${seti_syslog} -t ${seti_command} \ |
51 |
"unable to start: ${program_path} is missing." |
42 |
"unable to start: ${seti_wrkdir}/${i} is missing." |
52 |
exit 72 |
43 |
exit 72 |
53 |
fi |
44 |
fi |
54 |
for i in ${seti_wrksuff}; do |
45 |
if [ ! -f ${seti_wrkdir}/${i}/user_info.sah ]; then |
55 |
if [ ! -d ${seti_wrkdir}/${i} ]; then |
46 |
logger -sp ${seti_syslog} -t ${seti_command} \ |
56 |
logger -sp ${syslog_facility} -t ${program_file} \ |
47 |
"unable to start: please log in to SETI@home first. (${seti_wrkdir}/${i}/user_info.sah is missing.)" |
57 |
"unable to start: ${seti_wrkdir}/${i} is missing." |
48 |
exit 72 |
58 |
exit 72 |
49 |
fi |
59 |
fi |
50 |
done |
60 |
if [ ! -f ${seti_wrkdir}/${i}/user_info.sah ]; then |
51 |
for i in ${seti_wrksuff}; do |
61 |
logger -sp ${syslog_facility} -t ${program_file} \ |
52 |
su -fm ${seti_user} -c "\ |
62 |
"unable to start: please log in to SETI@home first" \ |
53 |
(cd ${seti_wrkdir}/${i} && \ |
63 |
"(${seti_wrkdir}/${i}/user_info.sah is missing)." |
54 |
exec ${PREFIX}/${seti_bindir}/${seti_command} \ |
64 |
logger -sp ${syslog_facility} -t ${program_file} \ |
|
|
65 |
"run \"$0 register\" to accomplish this." |
66 |
exit 72 |
67 |
fi |
68 |
done |
69 |
for i in ${seti_wrksuff}; do |
70 |
su -fm ${seti_user} -c "\ |
71 |
(cd ${seti_wrkdir}/${i} && exec ${program_path} \ |
55 |
${seti_std_args} ${seti_proxy_args} \ |
72 |
${seti_std_args} ${seti_proxy_args} \ |
56 |
${seti_nice+-nice} ${seti_nice} >/dev/null &)" |
73 |
${seti_nice+-nice} ${seti_nice} >/dev/null &)" |
57 |
echo -n " SETI@home" |
74 |
done |
58 |
done |
75 |
echo -n " SETI@home" |
59 |
;; |
76 |
;; |
60 |
|
77 |
|
61 |
stop) |
78 |
stop) |
62 |
killall ${seti_command} |
79 |
for i in ${seti_wrksuff}; do |
63 |
;; |
80 |
pid_path=${seti_wrkdir}/${i}/pid.sah |
64 |
|
81 |
if [ -f ${pid_path} ]; then |
65 |
register) |
82 |
kill $(cat ${pid_path}) 2> /dev/null |
66 |
# Create or update primary working directory (in case the uid changed) |
|
|
67 |
mkdir -p ${seti_wrkdir} |
68 |
chown ${seti_user} ${seti_wrkdir} |
69 |
chmod u=Xrw,g=Xr,o=Xr ${seti_wrkdir} |
70 |
seti_dontlogin=no |
71 |
if [ -f ${seti_wrkdir}/user_info.sah ]; then |
72 |
echo " It seems you have already registered with SETI@home. Would you like" |
73 |
echo -n " to repeat the procedure? [Y/n] " |
74 |
read a |
75 |
if [ "X${a}" = "Xn" -o "X${a}" = "XN" ]; then |
76 |
seti_dontlogin=yes |
77 |
fi |
78 |
fi |
79 |
# No need to register if we've already done so |
80 |
if [ "X${seti_dontlogin}" != "Xyes" ]; then |
81 |
su -fm ${seti_user} -c "\ |
82 |
cd ${seti_wrkdir} && \ |
83 |
exec ${PREFIX}/${seti_bindir}/${seti_command} \ |
84 |
${seti_reg_args} ${seti_proxy_args}" |
85 |
fi |
83 |
fi |
86 |
|
84 |
done |
87 |
if [ ${seti_maxprocs} -gt 1 ]; then |
85 |
if [ ! -f ${seti_wrkdir}/pid.sah ]; then |
88 |
echo " Updating additional working directories." |
86 |
killall ${program_file} 2> /dev/null |
89 |
i=${seti_maxprocs} |
87 |
fi |
90 |
while [ ${i} -gt 1 ]; do |
88 |
;; |
91 |
mkdir -p ${seti_wrkdir}/${i} |
89 |
|
92 |
chown ${seti_user} ${seti_wrkdir}/${i} |
90 |
restart) |
93 |
chmod 755 ${seti_wrkdir}/${i} |
91 |
$0 stop |
94 |
# Assume the user want's all processes to run with the same registration |
92 |
$0 start |
95 |
rm -f ${seti_wrkdir}/${i}/user_info.sah |
93 |
;; |
96 |
ln -sf ../user_info.sah ${seti_wrkdir}/${i} |
94 |
|
97 |
i=`expr ${i} - 1` |
95 |
status) |
98 |
done |
96 |
ps -auxww | egrep ${program_file} | egrep -v "($0|egrep)" |
|
|
97 |
;; |
98 |
|
99 |
register) |
100 |
if [ ! -x ${program_path} ]; then |
101 |
echo "${program_file}:" \ |
102 |
"unable to register: ${program_path} is missing." >&2 |
103 |
exit 72 |
104 |
fi |
105 |
# Create or update primary working directory (in case the uid changed) |
106 |
mkdir -p ${seti_wrkdir} |
107 |
chown ${seti_user} ${seti_wrkdir} |
108 |
chmod u=Xrw,g=Xr,o=Xr ${seti_wrkdir} |
109 |
seti_dontlogin=no |
110 |
if [ -f ${seti_wrkdir}/user_info.sah ]; then |
111 |
echo " It seems you have already registered with" \ |
112 |
"SETI@home. Would you" |
113 |
echo -n " like to repeat the procedure? [Y/n] " |
114 |
read a |
115 |
if [ "X${a}" = "Xn" -o "X${a}" = "XN" ]; then |
116 |
seti_dontlogin=yes |
99 |
fi |
117 |
fi |
100 |
;; |
118 |
fi |
|
|
119 |
# No need to register if we've already done so |
120 |
if [ "X${seti_dontlogin}" != "Xyes" ]; then |
121 |
su -fm ${seti_user} -c "\ |
122 |
cd ${seti_wrkdir} && \ |
123 |
exec ${program_path} \ |
124 |
${seti_reg_args} ${seti_proxy_args}" |
125 |
fi |
126 |
if [ ${seti_maxprocs} -gt 1 ]; then |
127 |
echo " Updating additional working directories." |
128 |
i=${seti_maxprocs} |
129 |
while [ ${i} -gt 1 ]; do |
130 |
mkdir -p ${seti_wrkdir}/${i} |
131 |
chown ${seti_user} ${seti_wrkdir}/${i} |
132 |
chmod 755 ${seti_wrkdir}/${i} |
133 |
# Assume the user want's all processes to run |
134 |
# with the same registration |
135 |
rm -f ${seti_wrkdir}/${i}/user_info.sah |
136 |
ln -sf ../user_info.sah ${seti_wrkdir}/${i} |
137 |
i=$((${i} - 1)) |
138 |
done |
139 |
fi |
140 |
;; |
101 |
|
141 |
|
102 |
*) |
142 |
*) |
103 |
echo "usage: ${0##*/} {start|stop|register}" >&2 |
143 |
echo "usage: ${rc_file} {start|stop|restart|status|register}" >&2 |
104 |
exit 64 |
144 |
exit 64 |
105 |
;; |
145 |
;; |
106 |
esac |
146 |
esac |