Run the command in the background
Introduction
Sometimes, you really need those server-wide program to run in background, because you need to avoid some accidents to interrupt our service program.
There are some methods I will introduce here:
1. tmux:
tmux new -s [tty-name]
: start a new tty window with your set nametmux attach -t [tty-name]
: attach a existing tmux tty with namecrtl + b
and thend
: exit tmux tty but keep it in background
LATER but this command or we call it shortcut sometimes don’t work, if I find the reason, I will update here.
2. nohup:
nohup ./my_script.sh &
nohup ./my_script.sh > output.log 2>&1 &
3. systemctl(Systemd)
TODO: MacOS: launchctl(launchd)
I recommend you use systemctl
, but that is not absolute, different methods have different using scenario. Because we can easily control services via simple commands, and all the journal will be set at journalctl. But if you don’t have root authority, you should give up this method.
Make sure your basic service command is workable.
1 | ./bin/x64/factorio --start-server ./saves/SA_Multi.zip |
Register this command to systemctl
1 | # /etc/systemd/system |
Make our own service unit:
1 | touch factorio.service |
and put this example into this file:
1 | [Unit] |
Reload systemctl daemon:
1 | systemctl daemon-reload |
Start our service:
1 | systemctl start factorio |
Review our journal: journalctl
1 | journalctl -u factorio.service -f |