The above steps worked beautifully, I have made some detailed steps in my answer here:
My env is as follows
- Ubuntu at 17.10
- I have a python app on Gunicorn 19.x server, I need to start this application as a service.
Firstly you need to write a foo.service file.
[Unit]
Description=FooServer
[Service]
Restart=on-failure
WorkingDirectory=/path/to/your/working/directory/where the foo lives
ExecStart=/what/process/will call foo eg: in my case I used gunicorn app:app
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
[Install]
WantedBy=multi-user.target
The meaning of every word on the left hand side of the '=' sign and their equivalent in (to the earlier) upstart is in link https://wiki.ubuntu.com/SystemdForUpstartUsers
Once the file is ready, let's say you name it as 'foo.service' (the .service extension is important)
You need to place the file in /lib/systemd/system
After which you need to enable the service by calling
systemctl enable foo
Which will prompt you enter your root password as it will be creating symlinks in some root access based folders where all the services party.
If you have reached till here without any hassle , you are good.
Your service is hence created.
Start it by calling
sudo service foo start
systemctl status foo
to see the status
sudo service foo stop
to stop the service
I was on the Gunicorn page all day today and tried all the various options and none of them worked and finally this one worked.
Thank you so much @Zanna and @Nicklas Karlsson
/etc/init.d
if there is no unit file in/etc/systemd/system
or its subdirs. Could you give a little more detail about what you are trying to do? – Zanna Jun 30 '17 at 08:50/etc/init.d
instead of/etc/init
? It will need permissions 755. – Zanna Jun 30 '17 at 09:18/etc/init/d
is used. You might try making a symlink - assuming the script in/etc/init.d
is calledconsul
:sudo ln -s /etc/init.d/consul /etc/systemd/system/consul.service
– Zanna Jun 30 '17 at 09:53/etc/init.d
that I know work without there being any systemd unit file are actually (da)sh scripts. So, maybe you need to "translate" the upstart script into a systemd unit file to get this one to work - see Migrate basic upstart script to systemd – Zanna Jun 30 '17 at 10:18`[Unit] Description=Consul server Requires=network-online.target After=network-online.target
[Service] EnvironmentFile=-/etc/consul.d/consul.env Environment=GOMAXPROCS=2 Restart=on-failure ExecStart=/var/consul/consul agent $OPTIONS -config-dir=/etc/consul.d/bootstrap ExecReload=/bin/kill -HUP $MAINPID KillSignal=SIGINT
[Install] WantedBy=multi-user.target`
and added the symlink from /etc/systemd/system/consul.service but still no evidence that it's trying
– Nicklas Karlsson Jun 30 '17 at 11:05/lib/systemd/system
(they may need the suffix.service
) and then you should runsystemctl enable <name of service>
which causes a symlink to be made from/etc/systemd/system/foo.service
to the real file/lib/systemd/system/foo.service
. Do you get anything fromsystemctl status consul
? – Zanna Jun 30 '17 at 11:11