Mystic is a powerful BBS platform that supports several flavours of Linux. The ‘Mystic Internet Service’ (MIS) binary can run as a daemon, but treating it as a proper system service for system startup and shutdown requires a bit of extra work.
I came across this great post by David Stephens, which covers how to get MIS configured for automatic startup/shutdown with an init.d script. Unfortunately, most newer Linux distributions have moved away from init.d in favour of systemd service modules instead. In addition to just having the services start/stop at boot, I wanted for them to be able to better handle some common problems I was seeing. This includes:
- Situations where the mis.bsy semaphore file isn’t cleaned up when the MIS daemon is stopped. I’ve had this happen numerous times when MIS is stopped both gracefully and forcefully. The daemon can’t be started until the file is manually cleaned up in these situations. The script checks for a stale semaphore and removes it if there is no MIS PID running.
- On my system, shutting down the MIS daemon can take a long time and sometimes the process fails to stop after a SIGTERM. I wanted a way to forcefully terminate it using ‘kill -9’ after a period of time elapses. The script does this automatically after sixty seconds.
- Other miscellaneous checks and balances – i.e. not attempting to stop the service if it isn’t running, and to return proper error codes when exiting to indicate whether or not the process started/stopped successfully.
You can find the following files in the ZIP archive:
readme.txt – instructions similar to this web page.
mis-start.sh – the bash shell script to start the mis daemon.
mis-stop.sh – the bash shell script to stop the mis daemon.
mis.service – the systemd service file
file_id.diz – file descriptor
You can download the ZIP file here:
These scripts should work without modification (aside from a few variables) on any Debian based Linux distribution, including Ubuntu and Raspbian. I’d imagine they could run on CentOS, RHEL and others as well, but I have not tested them on other distributions.
These instructions can be found in the contained readme.txt file in each of the .zip files. The instructions assume that you have a basic understanding of Linux. Depending on your system configuration, some customization may be necessary.
- If running, stop your mystic daemon manually before following these instructions.
- Extract mystic-systemd.zip to an accessible location. If you want to just use your home directory, you can run:
unzip mystic-systemd.zip ~/ cd ~/mystic-systemd
- Edit the mis-start.sh and mis-stop.sh scripts using nano, vi or your favourite editor. You’ll need to modify the variables at the top of each script. Namely the following:
MIS_PATH=/mystic MIS_OPTS=daemon MIS_SHUT_OPTS=shutdownMIS_PATH is the location of your mystic install. By default, it’s set to /mystic. For MIS_OPTS, you’ll want to use “daemon” unless you are running an older version of mystic. Older versions used “-d” instead.
- If you want to allow the script to forcefully shutdown MIS after 60 seconds using ‘kill -9’, you’ll need to uncomment the section of mis-stop.sh between the dashes. Simply remove the ‘#’ character from each line of that section. Leaving it commented will cause the script to give up with an error code of 1 after 60 seconds of waiting for the process to stop gracefully.
- Copy the mis-start.sh and mis-stop.sh scripts to your mystic install directory. For example, if your mystic directory is /mystic, use:
cp mis-start.sh /mystic cp mis-stop.sh /mystic
- Ensure the scripts are executable. To be sure, you can run the following (assuming they are in /mystic):
chmod +x /mystic/mis-start.sh chmod +x /mystic/mis-stop.sh
- Test the scripts from your mystic directory. I’d recommend ensuring your MIS daemon is stopped before testing. If you are not logged in as root, you’ll need to use sudo. Try mis-start.sh first. If it’s successful, you should see something like this:
sudo ./mis-start.sh Attempting to start the Mystic Internet Service (mis).. No stale semaphore file found. Proceeding to start the mis daemon.. [MIS] Executing servers in DAEMON mode Checking to ensure the process starts.. Finished! Mis daemon has been started successfully at PID 1613.
You’ll know the script was successful if you get a ‘0’ exit code from the following command:
echo $? 0
The mis-stop.sh script should output something like this:
sudo ./mis-stop.sh Attempting to stop the Mystic Internet Service daemon.. MIS daemon is currently running with PID 499. Stopping.. [MIS] Note: This must be executed with SUDO or ROOT [MIS] Sending shutdown signal for PID 499 Checking to ensure the process stops.. MIS process still running. Waiting 5 seconds.. Finished! MIS daemon has been stopped successfully.
If your process fails to stop gracefully, and you have uncommented the lines to forcefully stop it, you may see output similar to the following:
sudo ./mis-stop.sh Attempting to stop the Mystic Internet Service daemon.. MIS daemon is currently running with PID 1613. Stopping.. [MIS] Note: This must be executed with SUDO or ROOT [MIS] Sending shutdown signal for PID 1613 Checking to ensure the process stops.. MIS process still running. Waiting 5 seconds.. MIS process still running. Waiting 5 seconds.. MIS process still running. Waiting 5 seconds.. MIS process still running. Waiting 5 seconds.. MIS process still running. Waiting 5 seconds.. MIS process still running. Waiting 5 seconds.. MIS process still running. Waiting 5 seconds.. MIS process still running. Waiting 5 seconds.. MIS process still running. Waiting 5 seconds.. MIS process still running. Waiting 5 seconds.. MIS process still running. Waiting 5 seconds.. MIS process still running. Waiting 5 seconds.. Error: Process failed to stop gracefully after 60 seconds. Stopping process forcefully using kill -9 because the mis.bsy semaphore was already removed Success. MIS daemon was forcefully stopped.
Note: The above is still considered a success with an exit code of ‘0’, because in the end, the process was stopped.
- Once you are confident your scripts are working correctly, you’ll need to modify the mis.service file. Be sure to set your paths correctly in the two options shown below:
- Once done, copy the mis.service file to your /lib/systemd/system directory. Note that you’ll need root for this, so use sudo if necessary:
sudo cp mis.service /lib/systemd/system
- Next, enable the service using systemctl. This will allow the service to start at bootup. You’ll need root access for this as well:
sudo systemctl enable mis.service
Now that you’ve installed the mis.service file, you can start, stop and restart the Mystic daemon using the following commands:
sudo systemctl start mis sudo systemctl stop mis sudo systemctl restart mis
If you want to prevent it from starting with the system, use ‘disable’ instead of ‘enable’.
sudo systemctl disable mis.service
To get service status, run the following:
sudo systemctl status mis systemctl status mis.service ● mis.service - Mystic Internet Service Loaded: loaded (/lib/systemd/system/mis.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2019-09-29 22:55:56 EDT; 10min ago Main PID: 1874 (mis) CGroup: /system.slice/mis.service └─1874 /mystic/mis daemon
The status output will also include the last ten lines of script output, which can be helpful for debugging purposes. Because of the way the scripts were designed, if it shows a green status, then the daemon should definitely be running.
I hope that other SysOps will find these scripts helpful. Please feel free to add to them or modify them for additional functionality.
Multi Relay Chat
Update 11/4/2020: In addition to the MIS daemon, I also wanted to treat the mrc_client.py script used for the Multi Relay Chat (MRC) application in a similar way. You can find a systemd service module and similar scripts for MRC here. The process to implement these for MRC is very similar to what is outlined above.
13 thoughts on “Mystic BBS systemd Start/Stop Scripts”
Works perfectly on my Pi3 Stretch setup; and I learned a little more about systemd.
Thanks for putting this together!
Glad it was helpful, Aaron!
Thank you for this, it’s exactly what I was looking for! You mentioned having scripts for MRC, would it possible to get those as well?
Just another note of thanks — I had been thinking about how I should start putting various things into startup on my server, and saw this linked to from the arcadiabbs guide on getting doors setup using dosemu. A few minutes of following the guide later, and now Mystic runs when my server reboots. And I have a few ideas on how to get other things working, too.
Thanks for having the guide up.
Thanks so much for this. It was exactly what I was looking for. You mentioned that you had scripts for MRC as well, would it be possible to get those?
Hi Jonathon, I did indeed get these created for MRC as well, but never got around to updating the post. I’ll try to get this added soon.
Hi Johnathon, I zipped up the systemd module and scripts for MRC and updated the article above. The link to download them is at the bottom in the new section called “Multi Relay Chat”. The process to deploy these is pretty much the same as outlined for MIS. Just be sure to set the correct variables in the scripts before running.
This is great, but since it runs as sudo I’m having file permission issues when Mystic runs a linux command line command, or an MPL tries to like… ‘cat’ something from within the MPL. Is there anyway to run as ‘pi’, or… have you ran into any permissions issues like this and know a quick fix??? THANK YOU, this is really nicely written.
Good question – it’s been a while, but I recall having similar issues when binding mystic to TCP ports less than 1024. Root access is required to bind ports in the lower range. I would have issues running any external programs or dosemu based stuff in that configuration. I used to run mis on TCP 2022/2023 and then use iptables to redirect 22/23 to the higher ports internally. Might be worth a try?
You can also try to set the “User=” to someone other than root in mis.service, but I haven’t tried that so not sure it’ll work.
I think because I run telnet on port 1337 and ssh on port 1338 that I could just change user to ‘bbs’ and that it would run oK. I think. 😛 Thanks so much for these mods – they are wonderful.
This is an outstanding example of clear instruction. You are an excellent writer.
Thanks very much for the kind words!
This is SO awesome! thank you SO much!!