How do I automatically start a service on Ubuntu

6.1k views Asked by At

I need to run postgresql for my Rails app, which I do like this at the terminal:

$ sudo service postgresql start

How do I automate this process so that postgresql just starts automatically for me either whenever my app needs it, whenever I login, or whenever my server starts. I'm on Ubuntu 15.10.

Thanks.

3

There are 3 answers

1
Babar Al-Amin On

Auto start PostgreSQL on OS startup.

I'm not sure about, which OS you're using. On Ubuntu it should be:

sudo update-rc.d postgresql enable

There are several ways to auto start a program per OS. Better consult to your specific OS docs.

3
Sanjay Singh On

Stale PID needs removal. First step

rm /usr/local/var/postgres/postmaster.pid

Second step

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

0
Plinio Garcia On

I do not know exactly the procedures you used to install postgres , but when I installed Ubuntu 10.15 had permission issues that prevented the service from starting.

1 ) try to start:

service postgresql start

2 ) make sure that Postgres is the list of services:

ps -ef

3 ) If not, check the log:

cat /var/log/syslog

4 ) At this point my problem was allowed access to the ssl key. If your case also, do:

chown postgres. /etc/ssl/private/ssl-cert-snakeoil.key

5 ) try to start again:

service postgresql start

With this my Postgres started normally (forever)