1

I have these two services, one is Google start up script service and second one is redis service, I want to start redis service once the startup script service is started and done, I have these following systemd config but my redis services won't start with these config

google-startup-scripts.service
[Unit]
Description=Google Compute Engine Startup Scripts
After=network-online.target network.target rsyslog.service
After=google-instance-setup.service google-network-daemon.service
After=cloud-final.service multi-user.target
Wants=cloud-final.service
After=snapd.seeded.service
Wants=snapd.seeded.service

[Service]
RemainAfterExit=yes
ExecStart=/usr/bin/google_metadata_script_runner --script-type startup
KillMode=process
Type=oneshot
StandardOutput=journal+console
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin

[Install]
WantedBy=multi-user.target

redis.service

[Unit]
Description=Redis In-Memory Data Store
After=google-startup-scripts.service

[Service]
Type=notify
PIDFile=/run/redis-6378.pid
ExecStart=/usr/bin/redis-getdevice /etc/redis-getdevice/6378.conf
ExecStop=/usr/bin/redis-cli -p 6378 shutdown
Restart=always

[Install]
WantedBy=multi-user.target

once the google-startup-script.service run and it do the operations and goes to state exited. and redis service doesn't start at all (I'm using After in unit) what I'm doing wrong here

Jack
  • 121
  • 1
  • 1
  • 4

1 Answers1

3

There a number of different keywords to specify systemd unit dependencies. Each with a slightly different effect and implications with regards to failure handling and for example "starting" and "waiting for startup to complete" for example :

Wants

Configures (weak) requirement dependencies on other units. ... Units listed in this option will be started if the configuring unit is. ...

Requires

Similar to Wants=, but declares a stronger requirement dependency. ... If this unit gets activated, the units listed will be activated as well. If one of the other units fails to activate, and an ordering dependency After= on the failing unit is set, this unit will not be started. ...

After

... If unit foo.service contains the setting Before=bar.service and both units are being started, bar.service's start-up is delayed until foo.service has finished starting up. After= is the inverse of Before=, i.e. while Before= ensures that the configured unit is started before the listed unit begins starting up, After= ensures the opposite, that the listed unit is fully started up before the configured unit is started. ...

In that regard your redid.service Unit, with a After=google-startup-scripts.service dependancy, appears correct.

Your issue would seem to be that the google-startup-scripts.service is Type=oneshot. The systemd service manager will consider the unit up after the main ExecStart= process exits.

What can happen is that a script triggers tasks to start and run in the background and doesn't wait for those to complete (or to complete their start-up). The script will continue to the next steps and then successfully complete, systemd considers the unit to be up, but one or more processes are not quite there yet.

You may need to make an adjustment in whatever is running from /usr/bin/google_metadata_script_runner --script-type startup

Bob
  • 5,335
  • 5
  • 24