# How to start the Mender Server automatically at system start

**URL:** <https://hub.mender.io/t/how-to-start-the-mender-server-automatically-at-system-start/2885>\
**Category:** General Discussions\
**Created:** [November 24, 2020, 11:15am UTC](https://hub.mender.io/t/how-to-start-the-mender-server-automatically-at-system-start/2885 "2020-11-24T11:15:02Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![PJK](https://avatars.discourse-cdn.com/v4/letter/p/bc79bd/32.png) [@PJK](https://hub.mender.io/u/PJK)\
**Post date:** [November 24, 2020, 11:15am UTC](https://hub.mender.io/t/how-to-start-the-mender-server-automatically-at-system-start/2885/1 "2020-11-24T11:15:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [November 24, 2020, 1:35pm UTC](https://hub.mender.io/t/how-to-start-the-mender-server-automatically-at-system-start/2885/2 "2020-11-24T13:35:40Z")

</div>

> [@PJK](#):
>
> 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.

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 🙂.

---

<div class="post-metadata">

**Author:** ![peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@peter](https://hub.mender.io/u/peter)\
**Post date:** [November 24, 2020, 2:08pm UTC](https://hub.mender.io/t/how-to-start-the-mender-server-automatically-at-system-start/2885/3 "2020-11-24T14:08:01Z")

</div>

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](https://hub.mender.io/t/mender-server-start-at-boot/1931/2)

peter

---

<div class="post-metadata">

**Author:** ![PJK](https://avatars.discourse-cdn.com/v4/letter/p/bc79bd/32.png) [@PJK](https://hub.mender.io/u/PJK)\
**Post date:** [November 24, 2020, 2:50pm UTC](https://hub.mender.io/t/how-to-start-the-mender-server-automatically-at-system-start/2885/4 "2020-11-24T14:50:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dellgreen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/dellgreen/32/85_2.png) [@dellgreen](https://hub.mender.io/u/dellgreen)\
**Post date:** [November 24, 2020, 6:27pm UTC](https://hub.mender.io/t/how-to-start-the-mender-server-automatically-at-system-start/2885/5 "2020-11-24T18:27:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PJK](https://avatars.discourse-cdn.com/v4/letter/p/bc79bd/32.png) [@PJK](https://hub.mender.io/u/PJK)\
**Post date:** [November 25, 2020, 8:20am UTC](https://hub.mender.io/t/how-to-start-the-mender-server-automatically-at-system-start/2885/6 "2020-11-25T08:20:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dellgreen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/dellgreen/32/85_2.png) [@dellgreen](https://hub.mender.io/u/dellgreen)\
**Post date:** [November 25, 2020, 9:28am UTC](https://hub.mender.io/t/how-to-start-the-mender-server-automatically-at-system-start/2885/7 "2020-11-25T09:28:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PJK](https://avatars.discourse-cdn.com/v4/letter/p/bc79bd/32.png) [@PJK](https://hub.mender.io/u/PJK)\
**Post date:** [November 25, 2020, 9:31am UTC](https://hub.mender.io/t/how-to-start-the-mender-server-automatically-at-system-start/2885/8 "2020-11-25T09:31:09Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![dellgreen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/dellgreen/32/85_2.png) [@dellgreen](https://hub.mender.io/u/dellgreen)\
**Post date:** [November 25, 2020, 10:13am UTC](https://hub.mender.io/t/how-to-start-the-mender-server-automatically-at-system-start/2885/9 "2020-11-25T10:13:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PJK](https://avatars.discourse-cdn.com/v4/letter/p/bc79bd/32.png) [@PJK](https://hub.mender.io/u/PJK)\
**Post date:** [November 25, 2020, 12:12pm UTC](https://hub.mender.io/t/how-to-start-the-mender-server-automatically-at-system-start/2885/10 "2020-11-25T12:12:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![matteog](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@matteog](https://hub.mender.io/u/matteog)\
**Post date:** [December 4, 2020, 9:56am UTC](https://hub.mender.io/t/how-to-start-the-mender-server-automatically-at-system-start/2885/11 "2020-12-04T09:56:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PJK](https://avatars.discourse-cdn.com/v4/letter/p/bc79bd/32.png) [@PJK](https://hub.mender.io/u/PJK)\
**Post date:** [December 4, 2020, 10:09am UTC](https://hub.mender.io/t/how-to-start-the-mender-server-automatically-at-system-start/2885/12 "2020-12-04T10:09:54Z")

</div>

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.
