Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init.d script improvements #3115

Merged
merged 1 commit into from
Aug 13, 2015
Merged

init.d script improvements #3115

merged 1 commit into from
Aug 13, 2015

Conversation

KoeSystems
Copy link
Contributor

Objectives

  1. Clarify script changing variables to capital letter.
  2. Allow to overwrite all the variables with default variables.
  3. Check if config file exists and it's readable.
  4. Check if pidfile is writable.

Motivation

  1. The current init script use lower case for some variables which names match with the output messages, changing this variables to capital letter makes the script more standard and more readable.
  2. The current init script does not allow the overwrite of all the variables with environment variables, this would make that some users need to change the init script (instead of add environment variables or edit /etc/default/influxdb) or would make harder to manage influxdb from automatisation systems like puppet.
  3. The config file exists by default ( built from package.sh ), however could exist a race condition in some environments, better if we check if config file exists.
  4. Like point 3, some race condition could happen, better if we check if pidfile is writable.

Changes

  1. Change all the variables in lower case by capital letter.
  2. Move the definition of the variables before load the $DEFAULT file
  3. Check if config file is readable, if not exit 4.
  4. If the pidfile doesn't exists, check if writable doing a touch with the proper user, exit 5 if it fails.

Backward compatibility

No changes in the way influxDB is launched neither how the init script is called neither in the value of default variables, so it's full backward compatible.

Testing

I didn't find integration test over the builded package and the CI test seems to test "only" the code, not the init script.

For this reason I run some manual test:

  • with empty /etc/default/influxdb
root@vm01:~# service influxdb version 
InfluxDB v0.9.0 (git: .... )

root@vm01:~# service influxdb status
influxdb Process is not running [ FAILED ]

root@vm01:~# service influxdb start
Starting the process influxdb [ OK ]
influxdb process was started [ OK ]

root@vm01:~# service influxdb start
influxdb process is running [ FAILED ]

root@vm01:~# service influxdb stop
influxdb process was stopped [ OK ]

root@vm01:~# service influxdb stop
influxdb process is not running [ FAILED ]

with some config in /etc/default/influxdb

root@vm01:~# cat /etc/default/influxdb 
CONFIG=/opt/influxdb/etc/influxdb.conf

root@vm01:~# service influxdb start
config file doesn't exists [ FAILED ]
root@vm01:~# cat /etc/default/influxdb 
PIDFILE=/var/run/influxdb.pid

root@vm01:~# service influxdb start
/var/run/influxdb.pid now writable, check permissions [ FAILED ]
root@vm01:~# cat /etc/default/influxdb
CONFIG=/etc/opt/influxdb/influxdb.conf
PIDFILE=/var/run/influxdb/influxdb.pid

root@vm01:~# service influxdb start
Starting the process influxdb [ OK ]
influxdb process was started [ OK ]

@otoolep
Copy link
Contributor

otoolep commented Jun 24, 2015

Thanks @KoeSystems -- we'll definitely take a look. Have you signed the CLA?

case $1 in
start)
# Check if config file exists
if [ ! -r $CONFIG ]; then
log_failure_msg "config file doesn't exists"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exists -> exist

@KoeSystems
Copy link
Contributor Author

@otoolep I've just sign the CLA.

# Daemon name, where is the actual executable
# If the daemon is not there, then exit.
DAEMON=/opt/influxdb/influxd
[ -x $DAEMON ] || exit 5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 is the standard return code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, there isn't standard exit codes in bash except 0,1 and 2 ... I saw you were using exit 5 when the daemon doesn't exist so I use the same when PID is not writable. I add too "exit 4" when config file is not present. I didn't change the exit code when DAEMON doesn't exits.

I respected the exit codes to ensure the backward compatibility and because I think that it doesn't really matter (except for 0 , 1 or 2).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

@otoolep
Copy link
Contributor

otoolep commented Jun 25, 2015

Thanks again @KoeSystems -- can you rebase? We had to merge in some other changes to this file and there is now a conflict.

if [ -r $DEFAULT ]; then
source $DEFAULT
if [ -r /lib/lsb/init-functions ]; then
source /lib/lsb/init-functions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this going to break RedHat installations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still working for RedHat flavours as you can see here init script test

Btw, you can check in the current raw init file that we already load /lib/lsb/init-functions if exists, is something that this PR does not change.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems fair

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a RedHat / CentOS user but may need an elif and source /etc/init.d/functions. Then below, also check for daemon function before falling back to starting $DAEMON directly. (more below)

@pauldix
Copy link
Member

pauldix commented Jul 23, 2015

@KoeSystems if you can rebase we'll merge this in right away. Thanks!

@KoeSystems
Copy link
Contributor Author

@pauldix @otoolep Rebase done, thanks!

@otoolep otoolep self-assigned this Aug 13, 2015
@otoolep
Copy link
Contributor

otoolep commented Aug 13, 2015

@KoeSystems -- unfortunately the patch has conflict markers embedded within it i.e. >>>> and this change is not mergeable. If you can fix that I will then merge.

Allow to overwrite all the variables with environment variables.
Check if config file exists and it's readable.
Check if pidfile is writable.
@KoeSystems
Copy link
Contributor Author

Done, sorry for the fail when I did the rebase. Now should works.

@otoolep
Copy link
Contributor

otoolep commented Aug 13, 2015

Tested this on a Digital Ocean droplet and all functionality remains in place. Thanks @KoeSystems

otoolep added a commit that referenced this pull request Aug 13, 2015
@otoolep otoolep merged commit 1037b17 into influxdata:master Aug 13, 2015
else
log_success_msg "$name process was started"
exit 0
nohup $DAEMON -pidfile $PIDFILE -config $CONFIG $INFLUXD_OPTS >>$STDOUT 2>>$STDERR &
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the removal of su here an intentional change? Now, on CentOS 6 and 7, where start-stop.daemon is not available, InfluxDB runs as root if started via init.d script. Prepending sudo -g $GROUP -u $USER to this line is a workaround.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May need another which daemon check here and if available, do something like...

daemon --user=$USER:$GROUP --pidfile=$PIDFILE ...

Then fall back to starting $DAEMON directly if daemon function isn't available. su may have problems if $USER is the same as the user running the init script.

@KoeSystems
Copy link
Contributor Author

I've just open an issue for this 3803

@KoeSystems
Copy link
Contributor Author

I created a new PR 3804 with the solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants