Solved How can I set service script shell to use /usr/local/bin/bash as the login shell instead of /bin/csh?

When I run a startup service script, it appears to be using /bin/csh instead of /bin/sh

The relevant line in /etc/passwd
Code:
mastodon:*:1060:1060:User &:/home/mastodon:/bin/sh

The script - edited for clarity:

Code:
#!/bin/sh
# $FreeBSD$
# PROVIDE: mastodon_sidekiq
# REQUIRE: DAEMON postgresql
# KEYWORD: shutdown

. /etc/rc.subr

name="mastodon_sidekiq"
start_cmd="start"
stop_cmd="stop"
rcvar=mastodon_sidekiq_enable

pidfile="/var/run/${name}.pid"

desc="Mastodon Sidekiq Service"

load_rc_config ${name}

start() {

PATH=/home/mastodon/.rbenv/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

/bin/mkdir -p /var/run/mastodon

/usr/sbin/chown mastodon:mastodon /var/run/mastodon

/usr/bin/su mastodon -c "echo $PATH && ps -p $$ && echo $SHELL && env"

/usr/bin/su mastodon -c 'mycommand="$(rbenv init - su)" &&  eval $mycommand'

}

stop() {

/bin/kill -9 `cat /var/run/mastodon/${name}_supervisor.pid`
/bin/kill -15 `cat /var/run/mastodon/${name}.pid`


}

run_rc_command "$1"

Returns the following


Code:
root@mastodon:/usr/local/etc/rc.d # /usr/local/etc/rc.d/mastodon_sidekiq restart
/home/mastodon/.rbenv/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

  PID TT  STAT    TIME COMMAND
67915  4  SJ   0:00.01 /bin/sh /usr/local/etc/rc.d/mastodon_sidekiq restart

/bin/csh <----------------------------- Why is this the result of 'echo $SHELL'?

SHELL=/bin/sh
GROUP=wheel
MACHTYPE=x86_64
EDITOR=vi
PWD=/usr/local/etc/rc.d
LOGNAME=root
HOME=/home/mastodon
LANG=C.UTF-8
RC_PID=67915
OSTYPE=FreeBSD
TERM=xterm-256color
HOST=mastodon.brendans-bits.com
USER=mastodon
SHLVL=2
PAGER=less
MM_CHARSET=UTF-8
VENDOR=amd
PATH=/home/mastodon/.rbenv/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
BLOCKSIZE=K
MAIL=/var/mail/root
HOSTTYPE=FreeBSD
REMOTEHOST=192.168.101.2
_=/usr/bin/env

su: eval: line 1: syntax error near unexpected token `('
su: eval: line 1: `export PATH="/home/mastodon/.rbenv/shims:${PATH}" export RBENV_SHELL=su command rbenv rehash 2>/dev/null rbenv() { local command command="${1:-}" if [ "$#" -gt 0 ]; then shift fi case "$command" in rehash|shell) eval "$(rbenv "sh-$command" "$@")";; *) command rbenv "$command" "$@";; esac }'

The error running the rbenv command does not occur if I interactively log into the shell, which is using sh.
 
With double quotes, the variables are interpreted before being passed to su, so they get the value of SHELL when the line is processed.

Since nothing else has changed that value when running the script, you inherit it from your environment; in this case set by root’s login csh invocation.

Use single quotes if you need to evaluate the variable inside the to-be-launched shell.
But I think you’re really asking why the eval is failing. I think you’re running into issues with multiple lines trying to be evaluated; perhaps try piping the fist command into a shell execution?
 
Just start script with:
#! /usr/local/bin/bash
Unfortunately I am trying to run an rc.d service and AFAIK they require #!/bin/sh

If you want to permanently change user shell to bash run:
chsh -s /usr/local/bin/bash username
Thankyou, but I mistyped the title of the post, I had changed the users login shell to /bin/sh, but was confused about why I was still seeing /bin/csh as the output for echo $SHELL

With double quotes, the variables are interpreted before being passed to su, so they get the value of SHELL when the line is processed.

Since nothing else has changed that value when running the script, you inherit it from your environment; in this case set by root’s login csh invocation.

Use single quotes if you need to evaluate the variable inside the to-be-launched shell.
But I think you’re really asking why the eval is failing. I think you’re running into issues with multiple lines trying to be evaluated; perhaps try piping the fist command into a shell execution?
Ah, I had forgotten that about single vs double quotes, thankyou.

The eval command is failing because the 'wrong' shell is being invoked. I need to go away and learn about interactive vs login sessions and where to set variables for each session.
 
Back
Top