instagram arrow-down
Kalle Lilja

Archives

Install Mersenne GIMPS as a daemon

Ubuntu 16.04

Watching this Numberphile video and all of the related ones on YouTube got me on to having a look at this GIMPS, Great Internet Mersenne Prime Search.
I quickly set up an account, joined the Numberphile team, and got it up and running on my Windows machine using the provided getting started Instructions.
The set up is easy enough, download the program- start the program- provide your information- let it run.

As with any service, feature, or task, the question cropped up; Can it be run without intervention Linux? as a daemon
tl;dr: Yes, take a look at the GitHub repo.
Having a look at the Mersenne forum yielded no working result during my search, but I was pointed in a direction, some good old-fashioned tinkering was at hand.

There’s a story here about spinning up test VMs, messing the the code, cursing the transfer of code from Windows to Linux resulting in dos line endings having to be sorted from vi with :set ff=unix or apt-get dos2unix *.
However, I won’t go through all that.

I’ve distributed the working code over on GitHub as per usual.

Setup

The install is automated and performed using setup.sh.
setup.sh will do a whole bunch of good stuff leaving you with a working daemonized install of prime95 to be used by GIMPS.

sudo apt-get install git wget -y
git clone https://github.com/ThatKalle/mprime-gimps.git
cd mprime-gimps/
sudo chmod a+x setup.sh
sudo ./setup.sh

The snippet will install git from repo if not already installed, download all of the required files to a new folder mprime-gimps/, set the setup.sh script to executable and run it.

First off we’ll create the user account used to run the task, mprime.
This is as basuc as an account can be, no sudo, no password.
The folder to house related data is also created.

# Setup structure
sudo useradd -r mprime
sudo mkdir /usr/sbin/mprime

Secondly, the script to run the prime95 client, startmprime, is copied over to /usr/sbin/mprime and set to be runable by the new mprime user.

# Setup run script
sudo cp ./startmprime /usr/sbin/mprime/startmprime
sudo chmod a+x /usr/sbin/mprime/startmprime
sudo chown mprime:mprime /usr/sbin/mprime /usr/sbin/mprime/startmprime

Next up, logging is set up and configured to rotate daily using the logrotate function. Further reading related to logrotate can be found here.

# Setup logging
sudo touch /var/log/mprime.log
sudo chown mprime:mprime /var/log/mprime.log
# Logrotate
sudo touch /etc/logrotate.d/mprimed
echo -e '/var/log/mprime.log {\nrotate7\ndaily\nmissingok\nnotifempty\ncompress\ndelaycompress\ncopytruncate\n}' | sudo tee -a /etc/logrotate.d/mprimed

Followed by installing the actual deamonization of the startmprime script and setting it to run on boot via update-rc.d.

# Setup init.d daemon
sudo cp ./mprimed /etc/init.d/mprimed
sudo chmod a+x /etc/init.d/mprimed
# Run Daemon on boot
sudo update-rc.d mprimed defaults

Lastly the prime95 client is installed and subsequently configured to use your own mersenne account and so on. Follow the on-screen instructions.

# Install MPrime
wget http://www.mersenne.org/ftp_root/gimps/p95v293.linux64.tar.gz -P /tmp
sudo -u mprime tar -xvzf /tmp/p95v293.linux64.tar.gz -C /usr/sbin/mprime

echo "mprime requires manual intervention, proceed with setup. select: 5. Test/Quit when done."
read -p "Ready? (y/n) " RESP
if [ "$RESP" = "y" ]; then
    sudo -u mprime /usr/sbin/mprime/mprime -m
    sleep 1
    else
    echo "setup terminated, run 'sudo -u mprime /usr/sbin/mprime/mprime -m' to manually configure mprime."
    exit 1
fi

When configured, exit the manually started mprime using the “5. Test/Quit when done” option.
Run the daemonized version, sudo /etc/init.d/mprimed start.
It’s now safe to remove git and wget again if not needed. sudo apt-get remove git wget -y.

Information

With the install in place and running the cpu usage should be up at 100%, also, the mprime.log should start populating, tail -f /var/log/mprime.log.
The machine should also shorty show up under your CPUs on the Mersenne site.
More information available over on GitHub as per usual.

This is working set of code running on blank Linux machines on my end,
this is most likely not the correct, best, or most proper way of doing a deamonized prime95 client, but, it’s a way.
Use at your own risk and all that.