Compare Pastes
Differences between the pastes
#125072 (31.07.2019 16:49)
and
#138987 (25.07.2020 15:40).
1 | #!/sbin/openrc-run | |
1 | ||
2 | # Copyright 1999-2017 Gentoo Foundation | |
3 | # Distributed under the terms of the GNU General Public License v2 | |
4 | ||
5 | extra_started_commands="attach resume suspend" | |
6 | ||
7 | depend() { | |
8 | # we can use dns and net, but we can also in most cases live without them | |
9 | use dns net ntp-client ntpd | |
10 | } | |
11 | ||
12 | create_work_directory() { | |
13 | local sslcrt="/etc/ssl/certs/ca-certificates.crt" | |
14 | ||
15 | if [ ! -d "${RUNTIMEDIR}" ]; then | |
16 | einfo "Directory ${RUNTIMEDIR} does not exist, creating now." | |
17 | if ! mkdir -p "${RUNTIMEDIR}"; then | |
18 | eerror "Directory ${RUNTIMEDIR} could not be created!" | |
19 | return 1 | |
20 | fi | |
21 | ||
22 | # ensure proper ownership | |
23 | if ! chown "${USER}:${GROUP}" "${RUNTIMEDIR}"; then | |
24 | eerror "Changing ownership of '${RUNTIMEDIR}' to '${USER}:${GROUP}' failed!" | |
25 | return 1 | |
26 | fi | |
27 | fi | |
28 | ||
29 | if [ ! -e "${RUNTIMEDIR}"/ca-bundle.crt ]; then | |
30 | if [ ! -f "${sslcrt}" ]; then | |
31 | eerror "'${sslcrt}' does not exist!" | |
32 | return 1 | |
33 | fi | |
34 | ||
35 | if ! ln -s "${sslcrt}" "${RUNTIMEDIR}"/ca-bundle.crt; then | |
36 | eerror "Symlinking '${sslcrt}' failed!" | |
37 | return 1 | |
38 | fi | |
39 | fi | |
40 | ||
41 | return 0 | |
42 | } | |
43 | ||
44 | fix_lib_symlinks() { | |
45 | local src="$1" | |
46 | local tgt="$2" | |
47 | ||
48 | # If the source does not exist, we can not do anything | |
49 | if [ ! -f "${src}" ] ; then | |
50 | return 1 | |
51 | fi | |
52 | ||
53 | # Check whether the symlink is already there and in order | |
54 | if [ -L "${tgt}" ] ; then | |
55 | if [ -f "${tgt}" ] ; then | |
56 | return 0 | |
57 | fi | |
58 | ||
59 | # Remove broken symlink | |
60 | if ! rm -f "${tgt}"; then | |
61 | eerror "Removing '${tgt}' failed!" | |
62 | return 1 | |
63 | fi | |
64 | fi | |
65 | ||
66 | # symlink the correct path | |
67 | if ! ln -snf "${src}" "${tgt}"; then | |
68 | eerror "Symlinking '${src}' to '${tgt}' failed!" | |
69 | return 1 | |
70 | fi | |
71 | ||
72 | return 0 | |
73 | } | |
74 | ||
75 | cuda_check() { | |
76 | local libsource="/opt/cuda/lib/libcudart.so" | |
77 | local libtarget="${RUNTIMEDIR}/libcudart.so" | |
78 | ||
79 | fix_lib_symlinks "${libsource}" "${libtarget}" || return 1 | |
80 | return 0 | |
81 | } | |
82 | ||
83 | opencl_check() { | |
84 | local libsource="/usr/lib/libOpenCL.so" | |
85 | local libtarget="${RUNTIMEDIR}/libOpenCL.so" | |
86 | ||
87 | fix_lib_symlinks "${libsource}" "${libtarget}" || return 1 | |
88 | return 0 | |
89 | } | |
90 | ||
91 | env_check() { | |
92 | # Make sure the configuration is sane | |
93 | : ${USER:="boinc"} | |
94 | : ${GROUP:="boinc"} | |
95 | : ${RUNTIMEDIR:="/var/lib/boinc"} | |
96 | : ${BOINCBIN:="$(which boinc_client)"} | |
97 | : ${BOINC_PIDFILE:="/var/run/boinc_client.pid"} | |
98 | : ${BOINCCMD:="$(which /usr/bin/boinccmd)"} | |
99 | : ${ALLOW_REMOTE_RPC:="yes"} | |
100 | : ${NICELEVEL:="19"} | |
101 | # ARGS is not checked, it could have been explicitly set | |
102 | # to be empty by the user. | |
103 | ||
104 | # If the client was not found (how?) something is seriously wrong | |
105 | if [ ! -x "${BOINCBIN}" ]; then | |
106 | eerror "No boinc_client found!" | |
107 | return 1 | |
108 | fi | |
109 | ||
110 | # The boinccmd is crucial, or we can not attach, suspend or resume | |
111 | # the boinc client | |
112 | if [ ! -x "${BOINCCMD}" ]; then | |
113 | eerror "No boinccmd program found!" | |
114 | return 1 | |
115 | fi | |
116 | ||
117 | return 0 | |
118 | } | |
119 | ||
120 | need_passwd_arg() { | |
121 | local vers=$(${BOINCBIN} --version | tr -d .) | |
122 | [ -z "${vers}" ] && vers="00" | |
123 | [ $(expr substr "${vers}" 1 2) -lt 74 ] && return 0 | |
124 | ||
125 | # From version 7.4 on, the default is to read | |
126 | # gui_rpc_auth.cfg for the password. | |
127 | ||
128 | return 1 | |
129 | } | |
130 | ||
131 | start_pre() { | |
132 | env_check || return 1 | |
133 | create_work_directory || return 1 | |
134 | cuda_check || einfo "CUDA not supported" | |
135 | opencl_check || einfo "OpenCL not supported" | |
136 | ||
137 | if [ ! -f "${RUNTIMEDIR}/lockfile" ]; then | |
138 | einfo "File \"${RUNTIMEDIR}/lockfile\" does not exist, assuming first run." | |
139 | einfo "You need to setup an account on the BOINC project homepage beforehand!" | |
140 | einfo "Go to http://boinc.berkeley.edu/ and locate your project." | |
141 | einfo "Then either run ${RC_SERVICE} attach or connect with a gui client" | |
142 | einfo "and attach to a project with that." | |
143 | einfo "" | |
144 | ewarn "Note that for attaching to some project you need your network up and running." | |
145 | ewarn "network is needed only for jobs fetching afterwards" | |
146 | fi | |
147 | ||
148 | return 0 | |
149 | } | |
150 | ||
151 | start() { | |
152 | if [ "${ALLOW_REMOTE_RPC}" = "yes" ]; then | |
153 | ARGS="${ARGS} --allow_remote_gui_rpc" | |
154 | fi | |
155 | ||
156 | ARGS="${ARGS} --dir "${RUNTIMEDIR}" --redirectio" | |
157 | ||
158 | ebegin "Starting ${RC_SVCNAME}" | |
159 | start-stop-daemon --start --nicelevel ${NICELEVEL} \ | |
160 | --user "${USER}:${GROUP}" --quiet --make-pidfile \ | |
161 | --pidfile "${BOINC_PIDFILE}" --background \ | |
162 | --exec "${BOINCBIN}" -- ${ARGS} | |
163 | eend $? | |
164 | } | |
165 | ||
166 | attach() { | |
167 | local password="" | |
168 | local url="" | |
169 | local key="" | |
170 | ||
171 | env_check || return 1 | |
172 | ||
173 | einfo "If you can't find your account key just try to obtain it by using:" | |
174 | einfo " boinccmd --passwd PASSWORD_FROM_GUI_RPC_AUTH --lookup_account URL EMAIL PASSWORD" | |
175 | ||
176 | printf " Enter the Project URL: " | |
177 | read url | |
178 | printf " Enter your Account Key: " | |
179 | read key | |
180 | ||
181 | if ! service_started; then | |
182 | "${RC_SERVICE}" start | |
183 | fi | |
184 | ||
185 | if need_passwd_arg; then | |
186 | password="--passwd \"$(cat "${RUNTIMEDIR}/gui_rpc_auth.cfg")\"" | |
187 | fi | |
188 | ||
189 | ebegin "${RC_SVCNAME}: Attaching to project" | |
190 | start-stop-daemon --user "${USER}:${GROUP}" --quiet \ | |
191 | --chdir "${RUNTIMEDIR}" --exec "${BOINCCMD}" \ | |
192 | -- ${password} --project_attach ${url} ${key} | |
193 | eend $? | |
194 | ||
195 | sleep 10 | |
196 | tail "${RUNTIMEDIR}/stdoutdae.txt" | |
197 | } | |
198 | ||
199 | stop() { | |
200 | local password="" | |
201 | local stop_timeout="SIGTERM/60/SIGTERM/30/SIGKILL/30" | |
202 | ||
203 | env_check || return 1 | |
204 | ||
205 | if need_passwd_arg; then | |
206 | password="--passwd \"$(cat "${RUNTIMEDIR}/gui_rpc_auth.cfg")\"" | |
207 | fi | |
208 | ||
209 | ebegin "Stopping ${RC_SVCNAME}" | |
210 | start-stop-daemon --stop --quiet --progress \ | |
211 | --retry ${stop_timeout} \ | |
212 | --pidfile "${BOINC_PIDFILE}" | |
213 | eend $? | |
214 | } | |
215 | ||
216 | resume() { | |
217 | env_check || return 1 | |
218 | ||
219 | local password="" | |
220 | ||
221 | if need_passwd_arg; then | |
222 | password="--passwd \"$(cat "${RUNTIMEDIR}/gui_rpc_auth.cfg")\"" | |
223 | fi | |
224 | ||
225 | for url in $(cd "${RUNTIMEDIR}" ; \ | |
226 | "${BOINCCMD}" ${password} --get_project_status | \ | |
227 | sed -n 's/\s*master URL: //p'); do | |
228 | ebegin "Resuming ${url}" | |
229 | start-stop-daemon --user "${USER}:${GROUP}" --quiet \ | |
230 | --chdir "${RUNTIMEDIR}" --exec "${BOINCCMD}" \ | |
231 | -- ${password} --project ${url} resume | |
232 | eend $? | |
233 | done | |
234 | } | |
235 | ||
236 | suspend() { | |
237 | env_check || return 1 | |
238 | ||
239 | local password="" | |
240 | ||
241 | if need_passwd_arg; then | |
242 | password="--passwd \"$(cat "${RUNTIMEDIR}/gui_rpc_auth.cfg")\"" | |
243 | fi | |
244 | ||
245 | for url in $(cd "${RUNTIMEDIR}" ; \ | |
246 | "${BOINCCMD}" ${password} --get_project_status | \ | |
247 | sed -n 's/\s*master URL: //p'); do | |
248 | ebegin "Suspending ${url}" | |
249 | start-stop-daemon --user "${USER}:${GROUP}" --quiet \ | |
250 | --chdir "${RUNTIMEDIR}" --exec "${BOINCCMD}" \ | |
251 | -- ${password} --project ${url} suspend | |
252 | eend $? | |
253 | done |