2

I'm trying to convert an upstart script to systemd, but I can't figure out how to pass command line arguments to the executable. Here is the original upstart script:

# job description

description "job description"

start on (started wrouterd and wrouterd-started)
stop on (stopping wrouterd)

instance    $SLUG[$PHONE]

chdir       /var/application/bin
console     log
manual
respawn
respawn limit 5 60

exec /usr/bin/php my_script.php --phone=${PHONE} --slug=${SLUG}

So far, this is what I got:

[Unit]
Description=service description
After=wrouterd.service

[Service]
Type=simple
WorkingDirectory=/var/application/bin
StandardOutput=tty, StandardError=tty
Restart=on-failure
RestartSec=30s
ExecStart=/usr/bin/php my_script.php --phone=${PHONE} --slug=${SLUG}

I've read something about environment files but I'm not sure if they apply to my case because they say here that "A service shouldn't change it's options very often" and "Service parameters don't change on a regular basis, and neither do their config files", and I currently have about 130 of instances of this job running at the same time and I need to be able to start and stop at any time. Will I need to create an environment file for every single instance? Or do I need to change the variables in a single environment file and then start/stop the script?

0

Perhaps you are looking for instances. See this blog discussing how a single getty unit is instantiated as many times as desired by creating a symbolic link to it, with the filename holding an arbitrary parameter that is passed to the unit, where it can be recovered as %I or %i.

For example, doing

systemctl start serial-getty@ttyUSB0.service

will first look for a file with that exact filename, then remove the ttyUSB0 part and look for a serial-getty@.service file. Inside the /usr/lib/systemd/system/serial-getty@.service unit you will see lines like

ExecStart=-/sbin/agetty -s %I 115200,38400,9600

which will cause getty to run with arg ttyUSB0 in place of the %I.

I can highly recommend reading all of the series of blogs on systemd.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.