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

1 Answer 1

5

As stated in the Systemd documentation (in reference to Before= and After=),

Note that those settings are independent of and orthogonal to the requirement dependencies as configured by Requires=, Wants=, Requisite=, or BindsTo=. It is a common pattern to include a unit name in both the After= and Wants= options, in which case the unit listed will be started before the unit that is configured with these options.

After= only tells Systemd what order it should start and stop services in. It doesn't tell it to automatically start the service. You should add Requires=google-startup-scripts.service to the redis unit file and then enable it. It will automatically run the google-startup-scripts first. If google-startup-scripts fails, then so will the redis service.

E.g.,

[Unit]
Description=Redis In-Memory Data Store
Requires=google-startup-scripts.service
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .