[systemd-devel] Starting one service when another one starts

Andrei Borzenkov arvidjaar at gmail.com
Fri Apr 8 14:15:48 UTC 2022


On 08.04.2022 14:54, Nick Howitt wrote:
> Hi,
> I apologise if this is not the right place for user help. If it is not, 
> please point me to the best place.
> 
> I am trying to start a service (clearshare-scheduler) when another 
> service (siad) starts. Clearshare-scheduler is an odd service. When you 
> start it it may run for ages (days+) or it may terminate immediately so 
> I have set it up as a oneshot:
> 
> [Unit]
> Description=Clearshare Scheduler
> PartOf=siad.service
> After=siad.service
> 
> [Service]
> Type=oneshot
> Environment="TERM=dumb"
> ExecStartPre=-/usr/bin/killall -15 -q /usr/sbin/clearshare-scheduler.sh
> ExecStartPre=-/usr/bin/echo "$(/usr/bin/date) Starting scheduler from 
> systemd" >> /var/log/scheduler.log
> ExecStart=/usr/sbin/clearshare-scheduler.sh > /dev/null
> ExecStop=-/usr/bin/killall -15 -q /usr/sbin/clearshare-scheduler.sh
> 
> [Install]
> WantedBy=multi-user.target
> 
> The siad service looks like:
> 
> [Unit]
> Description=Siad
> After=syslog.target network.target clearsync.service
> 
> [Service]
> Type=simple
> OOMScoreAdjust=500
> PIDFile=/var/run/siad.pid
> EnvironmentFile=/etc/sysconfig/siad
> Environment="SIA_DATA_DIR=/var/lib/siad-data"
> ExecStartPre=-/usr/bin/killall -15 -q clearshare-scheduler.sh
> ExecStartPre=-/usr/bin/rm -f /var/run/siad.pid
> ExecStart=/usr/bin/siad $EXTRA_ARGS
> ExecStop=/usr/bin/siac stop
> WorkingDirectory=/var/lib/sia/
> ExecStartPost=/usr/bin/sh -c 'umask 022; /usr/bin/pgrep siad > 
> /var/run/siad.pid'
> 
> [Install]
> WantedBy=multi-user.target
> 

You do not show actual unit names which makes it rather difficult to follow.

> A "systemctl show clearshare-scheduler" lists the PartOf=siad.service as 
> one of its properties but, in reverse, "systemctl show siad" does not 
> list the corresponding ConsistsOf property.
> 
> When I start siad, nothing happens to the clearshare-scheduler service. 

Why do you expect to happen? There is no Wants or Requires in the unit
that is /probably/ siad.service so request to start siad.service will
not pull in any additional units.

> It does not try to start but it runs when I run it on its own. Have I 
> misunderstood something?
> 
> My version of systems is systemd-219-78.el7_9.5.
> 
> Thanks,
> 
> Nick



More information about the systemd-devel mailing list