If we include Restart=always in the .service file, does this mean that it again executes ExecStart after the script finishes and hence keeps executing the script in a loop?
Restart option is only invoked if the started process exits; with
always, according to the systemd.service documentation, the service will be restarted if the process exits due to:
- Clean exit code or signal
- Unclean exit code
- Unclean signal
The documentation goes on to say:
As exceptions to the setting above, the service will not be restarted if the exit code or signal is specified in RestartPreventExitStatus= (see below) or the service is stopped with systemctl stop or an equivalent operation. Also, the services will always be restarted if the exit code or signal is specified in RestartForceExitStatus= (see below).
Since you are not configuring a RestartForceExitStatus nor a RestartPreventExitStatus, the process will only be stopped by systemd during a
systemctl stop ("or equivalent operation").
Does app_script.sh start get called continuously, or only if the system service stops?
Neither, as far as that goes. It does not get called continuously, as described above. Neither does it get called if the service stops (apart from calling
/application/app_script.sh stop, of course); only when the process started by the service stops.
Do note that a
Type=simple service instructs systemd to consider the
ExecStart parameter to be the actual service. Your naming convention of
/application/app_script.sh start implies that there's a shell script involved which probably invokes one or more other scripts or binaries. If your shell script forks off that process and itself exits, systemd will consider your service process to have exited.