How to start the Mender Server automatically at system start

We have a working Mender Server instance on our linux server, but I’m having trouble getting the Mender Server to start automatically after the linux server boots.

All methods that I have tried either partially start the Mender Server (with ./run ps I see a number of Docker containers in the up state, but about half of them in the Exit0 state) or don’t do anything at all.

Does anybody have a noob’s guide to getting Mender Server to run at Linux startup?

PS: this is with Mender Server 2.4.0 and Amazon Linux 2

Curious on what methods you have tried?

Not my area of expertise so would not know what to recommend. @tranchitella or @peter might have better insights :slight_smile:.

hello PJK,

and thanks for using Mender.
so I understand there is a problem with running ./run up -d on startup?
you can also check this thread: Mender Server start at boot

peter

Hi peter,

Yes, I saw that post and I have tried it. That is the one that lead to the 50/50 startup.

The other options I’ve tried are using a shell script that was added to both the system and user crontabs as @bootup. The script would cd to the production directory and start the server.

It didn’t work for the user because cron isn’t started for the user account. With the root account I would see the server being started and all the docker containers come online (via ./run ps), only to see them all disappear again (after all the containers had come online).

I also tried to start my startup script via initd, but that had similar results as the linked to solution.

If I use the startup script manually it starts the server as expected and the web interface is accessible. For the other methods I’ve tried this is not the case!

The startup script is really simple:

#!/bin/bash
cd /home/“username”/mender-server/production
./run up -d

Have you double checking that you have disabled the docker policy for allowing it to start the containers automatically on boot, as that needs to be done else you will get race conditions. Then use the systemd startup method outlined above

I followed the instructions in the thread you were posting in, mentioned above. Maybe I made a mistake with the docker instructions. I did the following:

docker update --restart=on-failure menderproduction_mender-deployments_1
docker update --restart=on-failure menderproduction_mender-api-gateway_1
docker update --restart=on-failure menderproduction_mender-create-artifact-worker_1
docker update --restart=on-failure menderproduction_mender-device-auth_1
docker update --restart=on-failure menderproduction_mender-gui_1
docker update --restart=on-failure menderproduction_mender-inventory_1
docker update --restart=on-failure menderproduction_mender-mongo_1
docker update --restart=on-failure menderproduction_mender-useradm_1
docker update --restart=on-failure menderproduction_mender-workflows-server_1
docker update --restart=on-failure menderproduction_mender-workflows-worker_1
docker update --restart=on-failure menderproduction_minio_1
docker update --restart=on-failure menderproduction_storage-proxy_1

Which I think was what you were saying you had done. I’m not sure if this has to be done while the server is running or if it must be done when it is not running.

Apologies, going back over my notes, it looks like I documented the process incorrectly in the forum post it should be:

–restart=no

to stop the containers starting on boot from the docker daemon.

A short cut to configure all your running containers in one go is:

docker update --restart=no $(docker ps -a -q)

I’ll update the forum post

I gave that a try, but now all the docker modules are showing that they are in a state of Exit (0|2) after the reboot!

even after the custom systemd service has ran?
If you disable the custom systemd service can you now confirm that when you reboot that your docker containers are not running and have not been attempted to be started.

Hi dellgreen,

I found a few errors in the .service file (some leftover segments from a previous attempt that lurked below the editor window and the wrong user and a wrong path in ExecStart (I accidentally left in a /mender/ from your example while editing the file).

The service now works as expected.

3 Likes

Can you please post your .service file, just to get a clue on how you managed to get it working?

Hi matteog,

This is the content of my mender-server.service file (with user data replaced with placeholders):

— start of service file —

[Unit]
Description=Mender docker embedded image upgrade services
Requires=docker.service
After=docker.service systemd-user-sessions.service
After=network-online.target network.target

[Service]
Type=simple
TimeoutStopSec=300
User=useraccount
WorkingDirectory=/home/useraccount/mender-server/production
ExecStart=/home/useraccount/mender-server/production/run up -d

[Install]
WantedBy=multi-user.target

— end of service file —

You might need to modify the path to the production directory if you use a different directory structure.

And I did notice that systemctl enable and systemctl start are a bit finicky sometimes, so keep that in mind. I had some weird error messages while I was tuning and testing the changes to my services file. Could be that I wasn’t doing things in the correct order which caused this, but it’s something to keep in mind.

1 Like