Skip to content

Instantly share code, notes, and snippets.

@plembo
Last active November 3, 2022 15:54
Show Gist options
  • Save plembo/54cc5e18198fcb7de7262d8f48675d45 to your computer and use it in GitHub Desktop.
Save plembo/54cc5e18198fcb7de7262d8f48675d45 to your computer and use it in GitHub Desktop.
Autostart for TK4 on Linux

Implement autostart for TK4 on Linux

I'm a big fan of the MVS 3.8j Tur(n)key 4- System, and the excellent tutorial by moshix on his YouTube channel, How to get MVS 3.8 up and running on Linux. In my case, running on an Ubuntu KVM virtual machine. Of course, as a former server sysadmin I really wanted my server to automatically start when my vm booted up. The following is what I did to make that happen.

For my setup I chose to create a normal user on the vm, mvs, to run the server.

The user's home directory was set to /d1/app/mvs.

Following moshix's tutorial, I installed the tur(n)key system to /d1/app/mvs/mvs38.

Normally, getting things going was as simple as a cd into mvs38/ and then a "./mvs" to start. If I wanted the server to survive my logging off the mvs user, I would have to start it with a "./mvs &" (so it runs in the background).

To make this all happen automatrically I had to create two files.

First, a startup script: /d1/app/mvs/mvs-server:

#!/bin/bash
# Start the local MVS 3.8j system
HOME="/d1/app/mvs"
MVSDIR="${HOME}/mvs38"

cd ${MVSDIR}

./mvs &

Then, a systemd service script: /etc/systemd/system/mvs-server.service:

[Unit]
Description=MVS 3.8 Server
After=multi-user.target

[Service]
Type=forking
ExecStart=/d1/app/mvs/mvs-server
User=mvs

[Install]
WantedBy=multi-user.target

NOTE: I've found a minimalist approach works best when setting up systemd services from scratch. In this case though, setting the "Type" to "forking" turned out to be a key requirement for getting systemd to stick with the process during both startup and subsequent operations. Starting something as a background process (e.g. "mvs &"), by definition forks that process from its originating shell.

Enabling the service under systemd:

$ sudo systemctl enable mvs-server

Starting the service:

$ sudo systemctl start mvs-server

To check status:

$ sudo systemctl status mvs-server

● mvs-server.service - MVS 3.8 Server
   Loaded: loaded (/etc/systemd/system/mvs-server.service; enabled; vendor prese
   Active: active (running) since Thu 2019-08-01 21:36:57 UTC; 32min ago
  Process: 2053 ExecStart=/d1/app/mvs/mvs-server (code=exited, status=0/SUCCESS)
 Main PID: 2054 (mvs)
    Tasks: 76 (limit: 1109)
   CGroup: /system.slice/mvs-server.service
           ├─2054 /bin/bash ./mvs
           └─2067 hercules -d -f conf/tk4-.cnf

Aug 01 21:36:57 mvs02 systemd[1]: Starting MVS 3.8 Server...
Aug 01 21:36:57 mvs02 systemd[1]: Started MVS 3.8 Server.

Stopping the service:

$ sudo systemctl stop mvs-server

Because mvs takes so long to actually complete its startup (at least a minute or two),I usually wait a bit requesting status.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment