0

I'm trying to get my system.service file to run a command that is inside my start script. I've tried adding StandardInput= which did not work, so I believe I misunderstood how that operates. I've also tried the following unit below:

This fails, of course. How would I execute the command ./start start ?

Description=Service File
Wants=network-online.target
After=syslog.target network.target nss-lookup.target network-online.target

[Service] User=host WorkingDirectory=/home/host/Server/ ExecStart=/home/host/Server/start start Restart=always RestartSec=30

[Install] WantedBy=multi-user.target

Lex King
  • 39
  • 4
  • the file name is start.sh and it executes three functions, Start, Stop, Compile. I want it to do start. – Lex King Dec 19 '23 at 22:00
  • I type the command ./start start and is seems to process everything normally. I tried ./start.sh start and it failed to start. For now I managed to create three different scripts to run it on start up, but if I could get it in one that'd be super helpful. – Lex King Dec 22 '23 at 22:53
  • In the root directory for my server, where all the start files are compiled, I can run my command ./start start I can get everything green lit. If I try to run the command ./start.sh start it will throw the following error: /home/host/Server$ ./start.sh start bash: ./start.sh: No such file or directory It runs scripts inside that start file to initialise the servers activating and connecting the 3 ports of the game. I got each of these 3 services on their own individual files to be enabled at startup. – Lex King Dec 24 '23 at 11:55
  • I guess when you say "root directory for my server", you mean /home/host/Server, not the actual root directory /. So you have an executable file /home/host/Server/start, ie. an executable file named start which lies in the directory /home/host/Server of your server. But you also have a file named start.sh? In which directory does that lie? Is it executable too? What is the difference between the two? Please be a bit more forthcoming with information about your environment. Bear in mind that I cannot see what's on your server. – Tilman Dec 24 '23 at 14:02
  • Yes the "root" of the directory being the Server folder. I've attached an image in the link below to show the file. It seems to be a standard script and executes as it should, for the last 10+ years. https://i.imgur.com/z4VVJm9.png

    What I need it to do is execute a command, or function, "start" when the system.service file is enabled. ExecStart=/home/host/Server/start start This does not work. Is there a way to run a function like this in a system.service file?

    – Lex King Dec 24 '23 at 14:40
  • Ok, so we've sorted out that your script file is called start, not start.sh. You may want to edit your question to fix that. As to running it from a systemd unit, your approach is basically correct and should work. So it remains to diagnose why it doesn't work in your case. I cannot say anything specific without knowing what's actually inside your start file, but generally speaking you would inspect relevant log files to find out what's going wrong. – Tilman Dec 25 '23 at 11:28
  • What does your script actually do? Does it require a graphical desktop session? Does id launch some graphical window? Can you show us the code of your script? How do you know/identify that it doesn't work from the systemd unit? Do you get any errors? What's the output of systemctl status name.service where name.service is your unit's file name? – Raffa Dec 25 '23 at 14:39
  • Thanks. A py script can work to solve what I need. That's a good work around! Many thanks. – Lex King Dec 26 '23 at 22:19

1 Answers1

0

Edit your systemd service as follows:

ExecStart=/bin/bash -c '/home/host/Server/start.sh start'

Then:

sudo systemctl daemon-reload
GAD3R
  • 3,507