mersenneforum.org  

Go Back   mersenneforum.org > Great Internet Mersenne Prime Search > Software

Reply
 
Thread Tools
Old 2012-05-18, 01:01   #1
CrashM
 
May 2012

1 Posts
Post Init.d Script for MPrime

Extract MPrime files to /usr/lib/mprime and the extra files below should help. Tested on Ubuntu Server 12.04

Quote:

/etc/init.d/mprime


#!/bin/bash
# Init script for MPrime on Debian Linux
# Written by Ben Lawrenson, public domain, use on your own risk.
#

### BEGIN INIT INFO
# Provides: mprime
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: MPrime Service
# Description: Starts the MPrime Service
### END INIT INFO

# Settings
USER='mprime'

mp_start() {
echo "*** Starting MPrime Service..."
if ps ax | grep -v grep | grep /usr/lib/mprime/startmprime > /dev/null; then
echo "*** MPrime may already be running"
read -p "Try stop? (y/n) " RESP
if [ "$RESP" = "y" ]; then
mp_stop
sleep 1
else
exit 1
fi
fi
env TERM="xterm" \
start-stop-daemon \
--start \
--make-pidfile \
--pidfile /var/run/mprime.pid \
--background \
--user $USER \
--name mprime \
--chdir /usr/lib/mprime \
--nicelevel 19 \
--exec /usr/bin/screen -- -D -m -S mprimed /usr/lib/mprime/startmprime
sleep 1
if ps ax | grep -v grep | grep /usr/lib/mprime/startmprime > /dev/null; then
echo "*** MPrime is now running."
exit 0
else
echo "*** MPrime failed to start."
exit 1
fi
}

mp_stop() {
echo "*** Stopping MPrime server..."

if ps ax | grep -v grep | grep /usr/lib/mprime/startmprime > /dev/null; then
echo "*** MPrime running"
else
echo "*** MPrime not running."
exit 0
fi
echo "*** Attemping Conventional Stop..."
screen -p 0 -S mprimed -X eval 'stuff \003'
sync
cnt=0
while :
do
sleep 1
if ps ax | grep -v grep | grep /usr/lib/mprime/startmprime > /dev/null; then
cnt=$(( $cnt + 1 ))
else
break
fi
if [ $cnt -eq 10 ]; then
break
fi
done

if [ -e /var/run/mprime.pid ]; then
read PID < /var/run/mprime.pid
if ps ax | grep -v grep | grep ${PID} | grep /usr/lib/mprime/startmprime > /dev/null; then
echo '*** Conventional Stop Failed... Attempting Forced Stop...'
start-stop-daemon \
--stop \
--signal 15 \
--pidfile /var/run/mprime.pid
fi
fi

if ps ax | grep -v grep | grep /usr/lib/mprime/startmprime > /dev/null; then
echo "*** MPrime may still be running... "
read -p "Force kill all? (y/n) " RESP
if [ "$RESP" = "y" ]; then
killall mprime
sleep 3
if ps ax | grep -v grep | grep /usr/lib/mprime/startmprime > /dev/null; then
echo "*** MPrime may STILL be running... Please kill manually"
exit 1
else
echo "*** MPrime has stopped."
exit 0
fi
fi
else
echo "*** MPrime has stopped."
exit 0
fi
}

mp_status() {
if ps ax | grep -v grep | grep /usr/lib/mprime/startmprime > /dev/null; then
echo "*** MPrime appears to be running"
/usr/lib/mprime/mprime -s
exit 0
else
echo "*** MPrime doesn't appear to be running"
exit 1
fi
}

mp_log() {
read -p "Number of lines to display? " RESP
tail -$RESP /var/log/mprime.log
exit 0
}


case "$1" in
start)
mp_start
;;
stop)
mp_stop
;;
status)
mp_status
;;
log)
mp_log
;;
*)
echo "Usage: /etc/init.d/mprime {start|stop|status|log(lines)}"
echo " ...and hope that it works!"
;;
esac
Quote:
/usr/lib/mprime/startmprime

#!/bin/bash
cd /usr/lib/mprime
./mprime -d >> /var/log/mprime.log
CrashM is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to init an array in Posix bc? ewmayer Linux 29 2018-03-08 21:42
would like a script making. :) Mobilemick Operation Billion Digits 1 2006-01-15 03:49
Help with Startup Script Proggie Software 1 2004-12-19 11:54
Shell script puzzle #1 Xyzzy Linux 5 2004-01-26 10:31
Script for Mac OS X users astatine NFSNET Discussion 2 2004-01-19 13:05

All times are UTC. The time now is 19:59.


Thu Aug 18 19:59:32 UTC 2022 up 17:28, 1 user, load averages: 1.73, 1.69, 1.63

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.

≠ ± ∓ ÷ × · − √ ‰ ⊗ ⊕ ⊖ ⊘ ⊙ ≤ ≥ ≦ ≧ ≨ ≩ ≺ ≻ ≼ ≽ ⊏ ⊐ ⊑ ⊒ ² ³ °
∠ ∟ ° ≅ ~ ‖ ⟂ ⫛
≡ ≜ ≈ ∝ ∞ ≪ ≫ ⌊⌋ ⌈⌉ ∘ ∏ ∐ ∑ ∧ ∨ ∩ ∪ ⨀ ⊕ ⊗ 𝖕 𝖖 𝖗 ⊲ ⊳
∅ ∖ ∁ ↦ ↣ ∩ ∪ ⊆ ⊂ ⊄ ⊊ ⊇ ⊃ ⊅ ⊋ ⊖ ∈ ∉ ∋ ∌ ℕ ℤ ℚ ℝ ℂ ℵ ℶ ℷ ℸ 𝓟
¬ ∨ ∧ ⊕ → ← ⇒ ⇐ ⇔ ∀ ∃ ∄ ∴ ∵ ⊤ ⊥ ⊢ ⊨ ⫤ ⊣ … ⋯ ⋮ ⋰ ⋱
∫ ∬ ∭ ∮ ∯ ∰ ∇ ∆ δ ∂ ℱ ℒ ℓ
𝛢𝛼 𝛣𝛽 𝛤𝛾 𝛥𝛿 𝛦𝜀𝜖 𝛧𝜁 𝛨𝜂 𝛩𝜃𝜗 𝛪𝜄 𝛫𝜅 𝛬𝜆 𝛭𝜇 𝛮𝜈 𝛯𝜉 𝛰𝜊 𝛱𝜋 𝛲𝜌 𝛴𝜎𝜍 𝛵𝜏 𝛶𝜐 𝛷𝜙𝜑 𝛸𝜒 𝛹𝜓 𝛺𝜔