Score:0

How to start a tmux session as a non-root/separate user service while also running a shell script?

ng flag

I'm currently running an automatic service with the following content:

Description=Valheim Dedicated Server

[Service]
User=steam
Group=steam
ExecStart=/opt/steam/valheim/start_server_bepinex.sh
Restart=on-failure

[Install]
Wants=network-online.target
After=network-online.target
WantedBy=multi-user.target

I would like to change the service to do the following:

  1. Start a tmux session > tmux new -s Valheim
  2. Login as the "steam" user > su -ls /bin/bash steam
  3. Run a shell script > /opt/steam/valheim/start_server_bepinex.sh

I tried the following, but it doesn't work:

Description=Valheim Dedicated Server

[Service]
User=steam
Group=steam
ExecStart=tmux new -s Valheim '/opt/steam/valheim/start_server_bepinex.sh'
Restart=on-failure

[Install]
Wants=network-online.target
After=network-online.target
WantedBy=multi-user.target

The script executes a server that has to be accessed in real time in order to manage it through the terminal, so I need an active session and it has to be maintained under the steam user, not as a root. I need to be able to access this session whenever I want.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.