Sample Header Ad - 728x90

systemd: How to run a single command that should exit on boot

1 vote
0 answers
665 views
I'd like to have systemd run a program after the system is completely booted and ready to go. Eventually, that process may complete and exit with hopefully 0; in some situations, it may need to have a wrapper script that shuts down the computer when it exists, although it should definitely not be restarted. I'm managing these systems using Chef, and here is what my unit files look like so far: systemd_unit 'siege.service' do content ({ Unit: { Description: 'Run Siege', Requires: 'network-online.target', After: 'network-online.target', Documentation: ['https://github.com/joedog/siege '], AssertPathExists: node['siege']['log_dir'], }, Service: { Type: 'idle', ExecStart: '/usr/local/bin/siege', User: node['current_user'], }}) action [:create] only_if { node['siege']['create_service'] } end systemd_unit 'siege.timer' do content({Unit: { Description: 'Siege timer', Documentation: ['https://github.com/joedog/siege '], After: 'network-online.target', }, Timer: { OnStartupSec: '10s', AccuracySec: '1us', }, Install: { WantedBy: 'multi-user.target', }}) action [:create, :enable] only_if { node['siege']['create_service'] } end So basically I have no idea whether I'm going in the correct direction and whether a timer is the best way of doing this. From what I've read, it sounds like it will start 10s after systemd starts- that's not exactly what I'm looking for; I want it to start immediately after Everything ElseTM. I've seen a lot of similar questions advising the use of a service, but to me, this isn't really a service per se- this is running one program one time that is designed to exit, as you'd expect a user to do. It would really be nice if everything else was started up so Siege can suck up all the network bandwidth or CPU, and I'm not thrilled with my arbitrary 10s but I didn't see a better way. Am I crazy for doing it this way?
Asked by onwsk8r (111 rep)
Dec 27, 2018, 08:42 PM
Last activity: Dec 27, 2018, 09:23 PM