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
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
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:
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.
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.
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).
[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.