Startup init file/command


(stdranwl) #1

Hi there,

We are in need of having a init file/service which may help auto-restart of service in case of server reboot any time, did anybody install that so that “service cockroachdb start/stop/restart” will be invoked interactively or by automatic on reboot?

Kindly share any file/clue to get that worked for me.

Thanks


(Ronald) #2

you might want to take a look at https://github.com/oravirt/ansible-cockroachdb especially in the https://github.com/oravirt/ansible-cockroachdb/tree/master/roles/cockroach-systemd role where cockroach is integrated in systemd.


#3

This thread prompted me to try starting our roaches with a systemd service file. Sadly I cannot get it to work, it runs but it does not work.

I have been starting cockroach on cloud instances manually like so:

$ cockroach start --certs-dir=certs  --max-sql-memory=25% --cache=50% --background
CockroachDB node starting at 2018-02-06 12:54:41.485387729 +0000 UTC (took 9.5s)
build:      CCL v1.1.3 @ 2017/11/27 13:59:10 (go1.8.3)
admin:      https://crdb-1:8080
sql:        postgresql://root@crdb-1:26257?application_name=cockroach&sslmode=verify-full&sslrootcert=certs%2Fca.crt
logs:       /home/rsm/cockroach-data/logs
store[0]:   path=/home/rsm/cockroach-data
status:     restarted pre-existing node
clusterID:  32b1e5c6-39bc-434b-abec-72ffecb1efaa
nodeID:     1

And can connect to it from a local PC:

$ cockroach sql --host=46.310.222.37 --certs-dir=./certs
# Welcome to the cockroach SQL interface.
# All statements must be terminated by a semicolon.
# To exit: CTRL + D.
#
# Client version: CockroachDB CCL v1.1.2 (linux amd64, built 2017/11/02 19:32:03, go1.8.3)
# Server version: CockroachDB CCL v1.1.3 (linux amd64, built 2017/11/27 13:59:10, go1.8.3)
# Cluster ID: 32b1e5c6-39bc-434b-abec-72ffecb1efaa
#
# Enter \? for a brief introduction.
#
root@46.310.222.37:26257/>

I create a systemd service file like so:

$ cat /etc/systemd/system/cockroach.service
# /etc/systemd/cocroachdb.service
#   Starts/Stops a cockroach database node.

[Unit]
Description=Cockroach Database cluster node
Requires=network.target

[Service]
Type=simple
WorkingDirectory=/home/rsm
ExecStart=/usr/local/bin/cockroach start --certs-dir=certs  --max-sql-memory=25% --cache=50%
Restart=always
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=cockroach
User=rsm
Group=rsm
Environment=
[Install]
WantedBy=multi-user.target

And start the node:

$ sudo systemctl start cockroach
rsm@crdb-1:~$
rsm@crdb-1:~$ sudo systemctl status cockroach
● cockroach.service - Cockroach Database cluster node
   Loaded: loaded (/etc/systemd/system/cockroach.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2018-02-06 13:01:13 UTC; 9s ago
 Main PID: 31712 (cockroach)
    Tasks: 10 (limit: 4915)
   CGroup: /system.slice/cockroach.service
           └─31712 /usr/local/bin/cockroach start --certs-dir=certs --max-sql-memory=25 --cache=50

Feb 06 13:01:13 crdb-1 systemd[1]: Started Cockroach Database cluster node.
Feb 06 13:01:21 crdb-1 cockroach[31712]: CockroachDB node starting at 2018-02-06 13:01:21.073457814 +0000 UTC (took 7.0s)
Feb 06 13:01:21 crdb-1 cockroach[31712]: build:      CCL v1.1.3 @ 2017/11/27 13:59:10 (go1.8.3)
Feb 06 13:01:21 crdb-1 cockroach[31712]: admin:      https://crdb-1:8080
Feb 06 13:01:21 crdb-1 cockroach[31712]: sql:        postgresql://root@crdb-1:26257?application_name=cockroach&sslmode=verify-full&sslrootcert=ce
Feb 06 13:01:21 crdb-1 cockroach[31712]: logs:       /home/rsm/cockroach-data/logs
Feb 06 13:01:21 crdb-1 cockroach[31712]: store[0]:   path=/home/rsm/cockroach-data
Feb 06 13:01:21 crdb-1 cockroach[31712]: status:     restarted pre-existing node
Feb 06 13:01:21 crdb-1 cockroach[31712]: clusterID:  32b1e5c6-39bc-434b-abec-72ffecb1efaa
Feb 06 13:01:21 crdb-1 cockroach[31712]: nodeID:     1

All looks well and I can see all nodes green in the dashboard.

But I cannot connect to the node from the local PC anymore:

$ cockroach sql --host=46.310.222.37 --certs-dir=./certs
# Welcome to the cockroach SQL interface.
# All statements must be terminated by a semicolon.
# To exit: CTRL + D.
#
Error: unable to connect or connection lost.

Please check the address and credentials such as certificates (if attempting to
communicate with a secure cluster).

EOF
Failed running "sql"

(Ronald) #4

something with selinux?


#5

No idea. This is a Google Cloud instance running Debian Stretch.

I have a bunch of other services running on similar instances and they have never given me any problem.

I was hunting around in the logs looking for clues. No luck yet…


(Marc) #6

This is a problem with the % sign, it is used as a formatting symbol. If you look at the command run, it is missing the percents, so is trying to set a very very very small amount of memory for sql and caching:

For systemd, I believe %% is that you want for a single percentage sign.

@jesse: I’m having a hard time finding that in the docs (hard to search for %%). Do you recall where it is?


(Marc) #7

Nevermind, I found it. It’s under the start command flag docs.

We should really throw a big warning when the memory sizes are too small to make sense (eg: anything <= 100 is probably a percentage missing a %).


#8

Excellent. The %% works a treat. Thanks.

I was starting to wonder if there were some escapes or quotes needed in service files. Like you I could not find any info.


(stdranwl) #9

Hey there, Do we have any development running which will help usage of conf file same as MySQL do use of “my.cnf” file?


(Tim O'Brien) #10

We don’t currently, though you may be able to translate the configuration into a series of cockroach sql commands via a shell script.