12

I have a upstart configuration file as shown below which works fine in Ubuntu 14:

#/etc/init/data_server.conf
#sudo start data_server
#sudo stop data_server
#sudo status data_server

start on runlevel [2345]
stop on runlevel [016]

chdir /opt/hold/data_server
respawn

post-start script
    echo "data server started at `date +"%F %T"` on `hostname -f`" | mailx -r "abc@host.com" -s "data server Started" "pqr@host.com"
end script

post-stop script
  sleep 30
end script

limit core unlimited unlimited
limit nofile 100000 100000
setuid goldy
exec ./proc_server --init_file=../config/tree.init --port=8080 --dir=/data/hold/ --max_sec=2400 --max_mb=100 --active=5

Now we are moving to Ubuntu 16 so we can't use upstart and looks like we need to use systemd here. I have to make sure whenever system is rebooted or app is killed it should start my systemd script automatically which in turn start my data server. So I came up with below systemd script: Let me know if this is the right way as I am doing it for the first time?

[Unit]
Description=test server
After=network.target
StartLimitIntervalSec=0

[Service]
User=goldy
Group=goldy
Type=simple
WorkingDirectory=/opt/hold/data_server
ExecStart=/opt/hold/data_server/proc_server --init_file=../config/tree.init --port=8080 --dir=/data/hold/ --max_sec=2400 --max_mb=100 --active=5
Restart=always
RestartSec=3
LimitNOFILE=100000
LimitCORE=infinity

[Install]
WantedBy=multi-user.target

Whenever I run above script, it gives me this error, I am not sure whats wrong?

[/lib/systemd/system/queue_server_two.service:3] Unknown lvalue 'StartLimitIntervalSec' in section 'Unit'
user1950349
  • 223
  • 1
  • 3
  • 10

1 Answers1

20

You are likely comparing systemd docs you've read online for a different version instead using the docs on your system that match your version.

Check man systemd.unit on your own system. You may find that on your version, the directive is named

StartLimitInterval= and should be used [Service], not [Unit].

I found the answer by searching for systemd StartLimitIntervalSec.

Mark Stosberg
  • 3,771
  • 23
  • 27
  • make sense thanks.. also is there any way I can add emailing thing in my `systemd` script just like I have in `upstart`? – user1950349 Mar 27 '18 at 20:50
  • @user1950349 [`ExecStartPost=`](https://www.freedesktop.org/software/systemd/man/systemd.service.html#ExecStartPre=) – Michael Hampton Mar 27 '18 at 21:34
  • systemd syntax doesn't support pipes, so you'll need something like `ExecStartPost=/bin/bash -c ''`. Then you can put your command back in there as a quoted bash string. As seen in `man systemd.unit`, you can use %H for the host name, avoiding the call to `hostname -f`. – Mark Stosberg Mar 28 '18 at 11:51
  • got it.. so that means this below line should work? – user1950349 Mar 28 '18 at 19:36
  • ExecStartPost=/bin/bash -c 'echo "data server started at `date +"%F %T"` on %H" | mailx -r "abc@host.com" -s "data server Started" "pqr@host.com"' – user1950349 Mar 28 '18 at 19:37
  • Wow i've been searching all over trying to figure out this error. It appears in so many place, every web page I saw other than this says StartLimitIntervalSec is in Unit, not Service. I've been chasing a red herring because some places say it's StartLimitInterval not StartLimitIntervalSec. I'm using Centos 7.5.1804 (in a docker container, so man pages not easy), not some ancient OS. It's no wonder systemd gets a lot of flack. (but nope, still getting error) – jamshid Aug 08 '18 at 03:34
  • 3
    @jamshid `man systemd.directives` will tell you where any any directive is documented. ` StartLimitIntervalSec=` goes in `Unit`. The above question is about `StartLimitInterval=`. By using your local man pages, you can be sure you are checking the docs for the version you are actually running. – Mark Stosberg Aug 08 '18 at 18:14