Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
18
votes
1
answers
16577
views
zsh: is there a problem with always enabling extended glob?
I recetnly came across setopt extended_glob ...in order to enable extended globbing which allows for a number of cool wildcard additions, like excluding specific patterns, for example: ls ^foo* ...will use `ls` on every path in your current directory except for patterns that match `foo*`. I found on...
I recetnly came across
setopt extended_glob
...in order to enable extended globbing which allows for a number of cool wildcard additions, like excluding specific patterns, for example:
ls ^foo*
...will use
ls
on every path in your current directory except for patterns that match foo*
.
I found one tutorial suggesting to put setopt extended_glob
inside your .zshrc
, but I guess since many zsh config templates miss that option and the option being *disabled by default* it has some downsides or even side-effects?
Or is it absolutely harmless always enabling extended_glob
via putting it inside one's .zshrc
?
daniel451
(1107 rep)
Mar 17, 2018, 05:40 PM
• Last activity: Dec 12, 2024, 07:02 AM
2
votes
1
answers
1231
views
Python script as rc service on FreeBSD operating system
I have a Python script that I would like to run in a FreeNAS jail. It works without the service daemon, but I would like to start it as a service. I have created the following service script **`/etc/rc.d/attendance`** ```sh #!/bin/sh # PROVIDE: attendance # REQUIRE: DAEMON # KEYWORD: shutdown . /etc...
I have a Python script that I would like to run in a FreeNAS jail. It works without the service daemon, but I would like to start it as a service.
I have created the following service script **
/etc/rc.d/attendance
**
#!/bin/sh
# PROVIDE: attendance
# REQUIRE: DAEMON
# KEYWORD: shutdown
. /etc/rc.subr
name=attendance
rcvar=attendance_enable
load_rc_config $name
: ${attendance_enable="NO"}
pidfile="/var/run/${name}.pid"
command="/root/Zkteco/app.py"
command_interpreter=/usr/local/bin/python
run_rc_command "$1"
I have also added **attendance_enable="YES"
** under /etc/rc.conf
.
When I run **service attendance start
** I receive
Starting attendance
limits: /root/Zkteco/app.py: No such file or directory
/etc/rc.d/attendance: WARNING: failed to start attendance
Even though the directory exists, I tried moving it from /etc/rc.d/attendance
to /usr/local/etc/rc.d/attendance
and it seems to work, but it never goes as a background process either and I have to Ctrl+C to stop it.
Any recommendation?
The script is a web application using FastAPI and Uvicorn, does it have anything to do with it?
How can I see the logs of the service error trying to start.
**Thing I’ve tried**
I created a binary with pyinstaller --onefile
from the script. And
changed
#!/bin/sh
.
.
.
command="/usr/local/bin/app"
run_rc_command "$1
This change made the service start but again, it never goes to background.
Ukhu
(21 rep)
May 8, 2023, 10:12 PM
• Last activity: Oct 24, 2024, 05:50 AM
0
votes
1
answers
129
views
Automating proxy configuration across multiple applications without plaintext password
More generally than the post described here: https://unix.stackexchange.com/questions/752484/using-bash-functionality-in-rc-files?noredirect=1#comment1432155_752484 I would like to set an appropriate proxy configuration for all/multiple applications including but not limited to: snap/apt/cpan/pip/wg...
More generally than the post described here: https://unix.stackexchange.com/questions/752484/using-bash-functionality-in-rc-files?noredirect=1#comment1432155_752484
I would like to set an appropriate proxy configuration for all/multiple applications including but not limited to: snap/apt/cpan/pip/wget/curl. Moreover, I would like to avoid having my proxy password displayed anywhere in plaintext. How/is it possible to achieve this?
[This post](https://unix.stackexchange.com/questions/279670/how-can-i-specify-a-system-wide-proxy-without-giving-my-password-in-plaintext) implies that every system process will be configured for proxy via
/etc/environment
. I have not had such success (see EDIT), so I am currently under the assumption that all proxy configurations must be made per application. Regarding the [linked post](https://unix.stackexchange.com/questions/266808/avoiding-plain-text-password-in-http-proxy/266934#266934) , and the use of secret-tool
, it seems to me that this assumes the file defining the proxy configuration(s) can evaluate bash expressions (which hasn't been my experience with the .curlrc
/.wgetrc
files).
EDIT:
With the contents of etc/environment
equal to:
http_proxy=http://user:pass@proxy.com:80
https_proxy=http://user:pass@proxy.com:80
and the contents of my .curlrc
file equal to:
proxy=http://user:pass@proxy.com:80
I can run:
curl https://unix.stackexchange.com/posts/752654/edit --output test.html
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 70115 0 70115 0 0 99k 0 --:--:-- --:--:-- --:--:-- 99k
which generates test.html
as expected.
Without changing the contents of /etc/environment
and removing the .curlrc
file, the download hangs indefinitely:
curl https://unix.stackexchange.com/posts/752654/edit --output test.html
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:25 --:--:-- 0
I'm using RHEL on WSL.
Sterling Butters
(117 rep)
Jul 28, 2023, 02:21 PM
• Last activity: Oct 2, 2024, 08:46 PM
0
votes
1
answers
69
views
When is the ENV variable set
according to POSIX, the `ENV` environment variable is used to specify initialization files to be read (such as some kind of `.profile` and `.rc` files), but if this variable is used to specify these files, how can we set it? Normally, one would put an `export FOO="..."` in their initialization files...
according to POSIX, the
ENV
environment variable is used to specify initialization files to be read (such as some kind of .profile
and .rc
files), but if this variable is used to specify these files, how can we set it?
Normally, one would put an export FOO="..."
in their initialization files, but this variable needs to be set before those files are read (it needs to be set so they *can* be read)
user21749640
(101 rep)
Aug 5, 2024, 03:54 AM
• Last activity: Aug 5, 2024, 06:39 AM
4
votes
2
answers
18372
views
Why is rcS required after file system is mounted by the kernel?
I using embedded Linux, I have compiled the kernel without initramfs and kernel is booting fine. But It shows me `rcS` file is not found I have put it in `/etc/init.d/rcS` and my `rcS` file look like #!/bin/sh echo "Hello world" After the file system is mounted by the kernel it prints `Hello world`....
I using embedded Linux, I have compiled the kernel without initramfs and kernel is booting fine. But It shows me
rcS
file is not found I have put it in /etc/init.d/rcS
and my rcS
file look like
#!/bin/sh
echo "Hello world"
After the file system is mounted by the kernel it prints Hello world
.
Can any one tell/explain me why this file is require and how could I start those start up scripts in particular order?
I am using Raspberry Pi with busybox and it works fine but get I got stuck in the startup.
Shantanu Banerjee
(469 rep)
Nov 19, 2012, 05:20 AM
• Last activity: Jun 17, 2024, 02:12 PM
1
votes
1
answers
120
views
Forgejo pid file (/var/run/forgejo.pid) : not readable in Truenas Core (FreeBSD Jail)
I have been trying to get Forgejo running in a Truenas Core (FreeBSD jail) for over a week. When I manually start Forgejo as the git user it runs as expected, however attempting to get it to run with the included rc file provided by the ports package it errors out. [Forgejo Port][1] [rc.d script][2]...
I have been trying to get Forgejo running in a Truenas Core (FreeBSD jail) for over a week. When I manually start Forgejo as the git user it runs as expected, however attempting to get it to run with the included rc file provided by the ports package it errors out.
Forgejo Port
rc.d script
When I start forgejo manually it runs:
root@Forgejo:/home/jailuser # su git
git@Forgejo:/home/jailuser $ forgejo web -c /usr/local/etc/forgejo/conf/app.ini
2024/04/23 18:59:36 cmd/web.go:242:runWeb() [I] Starting Forgejo on PID: 4748
2024/04/23 18:59:36 cmd/web.go:111:showWebStartupMessage() [I] Forgejo version:1.21.11-1 built with GNU Make 4.4.1, go1.21.9 : bindata, pam, sqlite, sqlite_unlock_notify
However, when I attempt to start the forgejo service I get the following pid not found error:
root@Forgejo:/home/jailuser # service forgejo start
/usr/local/etc/rc.d/forgejo: DEBUG: Sourcing /etc/defaults/rc.conf
/usr/local/etc/rc.d/forgejo: DEBUG: pid file (/var/run/forgejo.pid): not readable.
/usr/local/etc/rc.d/forgejo: DEBUG: checkyesno: forgejo_enable is set to YES.
/usr/local/etc/rc.d/forgejo: DEBUG: run_rc_command: doit: forgejo_start
_
root@Forgejo:/home/jailuser # mount
Main/iocage/jails/Forgejo/root on / (zfs, local, noatime, nfsv4acls)
root@Forgejo:/home/jailuser # ll /var
total 81
drwxr-x--- 2 root wheel 2 Mar 1 18:50 account/
drwxr-xr-x 4 root wheel 4 Mar 1 18:50 at/
drwxr-x--- 4 root audit 4 Mar 1 18:50 audit/
drwxrwx--- 2 root authpf 2 Mar 1 18:50 authpf/
drwxr-x--- 2 root wheel 8 Apr 23 03:21 backups/
drwxr-xr-x 2 root wheel 2 Mar 1 18:50 cache/
drwxr-x--- 2 root wheel 3 Mar 1 19:06 crash/
drwxr-x--- 3 root wheel 3 Mar 1 18:50 cron/
drwxr-xr-x 14 root wheel 17 Apr 20 21:43 db/
dr-xr-xr-x 2 root wheel 2 Mar 1 18:50 empty/
drwxrwxr-x 2 root games 2 Mar 1 18:50 games/
drwx------ 2 root wheel 2 Mar 1 18:50 heimdal/
drwxr-xr-x 3 root wheel 23 Apr 23 00:00 log/
drwxrwxr-x 2 root mail 5 Apr 20 21:01 mail/
drwxr-xr-x 2 daemon wheel 3 Apr 20 19:28 msgs/
drwxr-xr-x 2 root wheel 2 Mar 1 18:50 preserve/
drwxr-xr-x 6 root wheel 18 Apr 23 18:56 run/
drwxrwxr-x 2 root daemon 2 Mar 1 18:50 rwho/
drwxr-xr-x 9 root wheel 9 Mar 1 18:50 spool/
drwxrwxrwt 3 root wheel 3 Mar 1 18:50 tmp/
drwxr-xr-x 3 unbound unbound 3 Mar 1 18:50 unbound/
drwxr-xr-x 2 root wheel 4 Mar 1 19:24 yp/
root@Forgejo:/home/jailuser #
Manually executing the daemon command results in an exit status of 0 with no other useful information. Tried relocating the pid file to a directory with 777 permissions and still getting the same error. My only guess right now would be that forgejo is dying almost immediately before daemon is able to create the pid file? Not sure how to get stdout from forgejo to see if there are any errors (forgejo is not logging anything to its log file directory). Any ideas?
UPDATE:
Adding truss to the init script on the call to daemon yields the following:
53609: mmap(0x0,135168,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34376810496 (0x801048000)
53609: mprotect(0x801044000,4096,PROT_READ) = 0 (0x0)
53609: issetugid() = 0 (0x0)
53609: sigfastblock(0x1,0x801047490) = 0 (0x0)
53609: open("/etc/libmap.conf",O_RDONLY|O_CLOEXEC,0101130030) = 3 (0x3)
53609: fstat(3,{ mode=-rw-r--r-- ,inode=16052,size=35,blksize=4096 }) = 0 (0x0)
53609: read(3,"includedir /usr/local/etc/libmap.d\n",35) = 35 (0x23)
53609: close(3) = 0 (0x0)
53609: open("/usr/local/etc/libmap.d",O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC,0165) ERR#2 'No such file or directory'
53609: open("/var/run/ld-elf.so.hints",O_RDONLY|O_CLOEXEC,0100416054) = 3 (0x3)
53609: read(3,"Ehnt\^A\0\0\0\M^@\0\0\0w\0\0\0\0\0\0\0v\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",128) = 128 (0x80)
53609: fstat(3,{ mode=-r--r--r-- ,inode=741826,size=247,blksize=4096 }) = 0 (0x0)
53609: pread(3,"/lib/casper:/lib:/usr/lib:/usr/lib/compat:/usr/local/lib:/usr/local/lib/compat/pkg:/usr/local/lib/perl5/5.36/mach/CORE\0",119,0x80) = 119 (0x77)
53609: close(3) = 0 (0x0)
53609: open("/lib/casper/libutil.so.9",O_RDONLY|O_CLOEXEC|O_VERIFY,00) ERR#2 'No such file or directory'
53609: open("/lib/libutil.so.9",O_RDONLY|O_CLOEXEC|O_VERIFY,00) = 3 (0x3)
53609: fstat(3,{ mode=-r--r--r-- ,inode=190,size=79952,blksize=80384 }) = 0 (0x0)
53609: mmap(0x0,4096,PROT_READ,MAP_PRIVATE|MAP_PREFAULT_READ,3,0x0) = 34376945664 (0x801069000)
53609: mmap(0x0,98304,PROT_NONE,MAP_GUARD,-1,0x0) = 34376949760 (0x80106a000)
53609: mmap(0x80106a000,32768,PROT_READ,MAP_PRIVATE|MAP_FIXED|MAP_NOCORE|MAP_PREFAULT_READ,3,0x0) = 34376949760 (0x80106a000)
53609: mmap(0x801072000,49152,PROT_READ|PROT_EXEC,MAP_PRIVATE|MAP_FIXED|MAP_NOCORE|MAP_PREFAULT_READ,3,0x7000) = 34376982528 (0x801072000)
53609: mmap(0x80107e000,4096,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_PREFAULT_READ,3,0x12000) = 34377031680 (0x80107e000)
53609: mmap(0x80107f000,4096,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_PREFAULT_READ,3,0x12000) = 34377035776 (0x80107f000)
53609: mmap(0x801080000,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_ANON,-1,0x0) = 34377039872 (0x801080000)
53609: munmap(0x801069000,4096) = 0 (0x0)
53609: close(3) = 0 (0x0)
53609: open("/lib/casper/libc.so.7",O_RDONLY|O_CLOEXEC|O_VERIFY,012320443000) ERR#2 'No such file or directory'
53609: open("/lib/libc.so.7",O_RDONLY|O_CLOEXEC|O_VERIFY,012320443000) = 3 (0x3)
53609: fstat(3,{ mode=-r--r--r-- ,inode=126,size=1940168,blksize=131072 }) = 0 (0x0)
53609: mmap(0x0,4096,PROT_READ,MAP_PRIVATE|MAP_PREFAULT_READ,3,0x0) = 34376945664 (0x801069000)
53609: mmap(0x0,4190208,PROT_NONE,MAP_GUARD,-1,0x0) = 34377048064 (0x801082000)
53609: mmap(0x801082000,540672,PROT_READ,MAP_PRIVATE|MAP_FIXED|MAP_NOCORE|MAP_PREFAULT_READ,3,0x0) = 34377048064 (0x801082000)
53609: mmap(0x801106000,1343488,PROT_READ|PROT_EXEC,MAP_PRIVATE|MAP_FIXED|MAP_NOCORE|MAP_PREFAULT_READ,3,0x83000) = 34377588736 (0x801106000)
53609: mmap(0x80124e000,40960,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_PREFAULT_READ,3,0x1ca000) = 34378932224 (0x80124e000)
53609: mmap(0x801258000,24576,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_PREFAULT_READ,3,0x1d3000) = 34378973184 (0x801258000)
53609: mmap(0x80125e000,2240512,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_ANON,-1,0x0) = 34378997760 (0x80125e000)
53609: munmap(0x801069000,4096) = 0 (0x0)
53609: close(3) = 0 (0x0)
53609: mprotect(0x80124e000,36864,PROT_READ) = 0 (0x0)
53609: mprotect(0x80124e000,36864,PROT_READ|PROT_WRITE) = 0 (0x0)
53609: mprotect(0x80124e000,36864,PROT_READ) = 0 (0x0)
53609: readlink("/etc/malloc.conf",0x7fffffffc610,1024) ERR#2 'No such file or directory'
53609: issetugid() = 0 (0x0)
53609: mmap(0x0,2097152,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON|MAP_ALIGNED(21),-1,0x0) = 34382807040 (0x801600000)
53609: mmap(0x0,2097152,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON|MAP_ALIGNED(12),-1,0x0) = 34384904192 (0x801800000)
53609: mmap(0x0,4194304,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON|MAP_ALIGNED(21),-1,0x0) = 34387001344 (0x801a00000)
53609: mprotect(0x1026000,4096,PROT_READ) = 0 (0x0)
53609: sigaction(SIGHUP,{ SIG_IGN SA_RESTART ss_t },{ SIG_DFL 0x0 ss_t }) = 0 (0x0)
53609: sigaction(SIGTERM,{ SIG_IGN SA_RESTART ss_t },{ SIG_DFL 0x0 ss_t }) = 0 (0x0)
53609: socket(PF_LOCAL,SOCK_DGRAM|SOCK_CLOEXEC,0) = 3 (0x3)
53609: getsockopt(3,SOL_SOCKET,SO_SNDBUF,0x7fffffffd85c,0x7fffffffd858) = 0 (0x0)
53609: setsockopt(3,SOL_SOCKET,SO_SNDBUF,0x7fffffffd85c,4) = 0 (0x0)
53609: connect(3,{ AF_UNIX "/var/run/logpriv" },106) = 0 (0x0)
53609: openat(AT_FDCWD,"/var/run",O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC,00) = 4 (0x4)
53609: openat(4,"forgejo.pid",O_WRONLY|O_NONBLOCK|O_CREAT|O_CLOEXEC,0600) = 5 (0x5)
53609: flock(5,LOCK_EX|LOCK_NB) = 0 (0x0)
53609: fstatat(4,"forgejo.pid",{ mode=-rw------- ,inode=742728,size=0,blksize=131072 },0x0) = 0 (0x0)
53609: fstat(5,{ mode=-rw------- ,inode=742728,size=0,blksize=131072 }) = 0 (0x0)
53609: ftruncate(5,0x0) = 0 (0x0)
53609: fstat(5,{ mode=-rw------- ,inode=742728,size=0,blksize=131072 }) = 0 (0x0)
53609: cap_rights_limit(4,{ CAP_UNLINKAT }) = 0 (0x0)
53609: cap_rights_limit(5,{ CAP_PWRITE,CAP_FTRUNCATE,CAP_FSTAT,CAP_EVENT }) = 0 (0x0)
53609: sigaction(SIGHUP,{ SIG_IGN 0x0 ss_t },{ SIG_IGN SA_RESTART ss_t }) = 0 (0x0)
53609: fork() = 53610 (0xd16a)
53610:
53610: setsid() = 53610 (0xd16a)
53609: exit(0x0)
53609: process exit, rval = 0
53610: sigaction(SIGHUP,{ SIG_IGN SA_RESTART ss_t },0x0) = 0 (0x0)
53610: madvise(0x0,0,MADV_PROTECT) ERR#1 'Operation not permitted'
53610: pipe2(0x7fffffffd9c0,0) = 0 (0x0)
53610: kqueuex() ERR#78 'Function not implemented'
53610: SIGNAL 12 (SIGSYS) code=SI_KERNEL
53610: process killed, signal = 12
UPDATE:
TrueNAS-13.0-U6.1
jailuser@Forgejo:~ $ uname -a
FreeBSD Forgejo 13.1-RELEASE-p9 FreeBSD 13.1-RELEASE-p9 n245429-296d095698e TRUENAS amd64
IronFractal
(13 rep)
Apr 30, 2024, 02:52 AM
• Last activity: May 4, 2024, 09:09 AM
0
votes
1
answers
181
views
Using bash functionality in rc files
I am trying to do something similar to https://unix.stackexchange.com/questions/266808/avoiding-plain-text-password-in-http-proxy but inside the .wgetrc/.curlrc configuration files. For whatever reason, I have spotty luck by passing proxy settings through the command line (i.e. the configuration fil...
I am trying to do something similar to https://unix.stackexchange.com/questions/266808/avoiding-plain-text-password-in-http-proxy but inside the .wgetrc/.curlrc configuration files. For whatever reason, I have spotty luck by passing proxy settings through the command line (i.e. the configuration files are completely reliable).
The problem is that I don't want my proxy password in plaintext anywhere on the system (e.g. in my bash_history or hardcoded into the rc files). Is there any workaround to leverage bash functionality within these rc files? Ideally, I wouldn't have spotty luck with the CLI proxy settings but I haven't been able to pinpoint why this is the case.
Sterling Butters
(117 rep)
Jul 26, 2023, 03:38 PM
• Last activity: Jul 26, 2023, 03:48 PM
0
votes
1
answers
43
views
/etc/rc.local not being run everytime a user logs in via ssh
I have set up the `/etc/systemd/system/rc-local.service` as follows: ``` [Unit] Description=/etc/rc.local Compatibility ConditionPathExists=/etc/rc.local [Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 StandardOutput=tty RemainAfterExit=yes SysVStartPriority=99 [Install] WantedBy=m...
I have set up the
/etc/systemd/system/rc-local.service
as follows:
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
The rights are set up properly on the /etc/rc.local
script:
File: /etc/rc.local
...
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
The service (hence the rc.local script) is started successfully every time the machine starts up.
However, the script does not get run every time a user logs in via ssh.
What am I missing? I'm starting to believe that I have the concept wrong.
E. Jaep
(137 rep)
Jun 22, 2023, 01:24 PM
• Last activity: Jun 22, 2023, 02:19 PM
0
votes
1
answers
420
views
Stop not called for init rc.d service
I have a very simple SysVinit service in `/etc/rc.d`: #!/bin/bash PIDFILE="/var/run/test.pid" status() { if [ -f "$PIDFILE" ]; then echo 'Service running' return 1 fi return 0 } start() { if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")"; then echo 'Service already running' return 1 fi echo 'Start...
I have a very simple SysVinit service in
/etc/rc.d
:
#!/bin/bash
PIDFILE="/var/run/test.pid"
status() {
if [ -f "$PIDFILE" ]; then
echo 'Service running'
return 1
fi
return 0
}
start() {
if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")"; then
echo 'Service already running'
return 1
fi
echo 'Starting...'
test & echo $! > "$PIDFILE"
return 0
}
stop() {
if [ ! -f "$PIDFILE" ] || ! kill -0 "$(cat "$PIDFILE")"; then
echo 'Service not running'
return 1
fi
echo 'Stopping...'
kill -15 "$(cat "$PIDFILE")" && rm -f "$PIDFILE"
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
When the system starts it starts the service.
But when the system stops, it never calls the stop command. The only reason I can think off is that the system either thinks the service is not running or was not started correctly.
But what are the requirements for that?
- Do you need to return a special exitcode for the start command?
- Do I need to create a file in /var/lock/subsys
to signal that it is active?
- Anything else that might cause the system to think the service did not start?
Maestro
(211 rep)
Apr 18, 2023, 03:28 AM
• Last activity: Apr 18, 2023, 08:42 PM
8
votes
2
answers
3903
views
How can I customize $PROMPT_COMMAND without overwriting the default (if present)?
Mac's Terminal comes with a default `PROMPT_COMMAND` that checks the history and updates the current working directory (title of the tab): Add `echo $PROMPT_COMMAND` to the top of your `.bash_profile` and you'll see: shell_session_history_check; update_terminal_cwd --- I want to add my own `PROMPT_C...
Mac's Terminal comes with a default
PROMPT_COMMAND
that checks the history and updates the current working directory (title of the tab):
Add echo $PROMPT_COMMAND
to the top of your .bash_profile
and you'll see:
shell_session_history_check; update_terminal_cwd
---
I want to add my own PROMPT_COMMAND
without over-writing the default. The default should come before my custom PROMPT_COMMAND
with a semicolon and space to separate the two.
Note that some programs (such as IntelliJ and VS Code) don't have a default! So I wouldn't want to include the space/semicolon in that case.
JBallin
(391 rep)
Aug 31, 2018, 06:27 PM
• Last activity: Mar 24, 2023, 10:15 PM
11
votes
2
answers
4545
views
Run .zshrc when passing command via -c
I have a script that runs a command via `zsh -c`. However, when `zsh` runs, it doesn't appear to load `~/.zshrc`. I understand [a login shell flag exists](https://unix.stackexchange.com/questions/126956/functions-defined-in-zshrc-not-found-when-running-script), but even `zsh -lc ` doesn't seem to wo...
I have a script that runs a command via
zsh -c
. However, when zsh
runs, it doesn't appear to load ~/.zshrc
.
I understand [a login shell flag exists](https://unix.stackexchange.com/questions/126956/functions-defined-in-zshrc-not-found-when-running-script) , but even zsh -lc
doesn't seem to work.
How can I get functions, aliases, and variables defined in my *~/.zshrc* to populate when running it with zsh -c
?
Qix - MONICA WAS MISTREATED
(789 rep)
Jul 23, 2015, 05:28 PM
• Last activity: Sep 16, 2022, 03:37 PM
5
votes
1
answers
1736
views
Stow doesn't use the "ignore" option given in the rc file
# Summary `--ignore= ` lines that I put in my `.stowrc` does not work. When running Stow, it says "Loading defaults from .stowrc", yet it has no effect. But passing the `--ignore= ` lines to the command directly works. # Problem Assume this directory: user@user-machine:~/test-stow/stow$ tree -a . ├─...
# Summary
--ignore=
lines that I put in my .stowrc
does not work. When running Stow, it says "Loading defaults from .stowrc", yet it has no effect. But passing the --ignore=
lines to the command directly works.
# Problem
Assume this directory:
user@user-machine:~/test-stow/stow$ tree -a
.
├── a
│ └── car
└── .stowrc
1 directory, 2 files
Contents of ./.stowrc
:
--ignore='car'
So my expectation is that running the command stow --verbose=3 a/
while in that directory is equivalent to running stow --ignore='car' --verbose=3 a/
if the ./.stowrc
file wasn't there.
Now I run:
user@user-machine:~/test-stow/stow$ stow --verbose=3 a
Loading defaults from .stowrc
stow dir is /home/user/test-stow/stow
stow dir path relative to target /home/user/test-stow is stow
cwd now /home/user/test-stow
cwd restored to /home/user/test-stow/stow
cwd now /home/user/test-stow
Planning stow of package a...
Stowing contents of stow/a (cwd=~/test-stow)
Stowing stow/a/car
LINK: car => stow/a/car
Planning stow of package a... done
cwd restored to /home/user/test-stow/stow
Processing tasks...
cwd now /home/user/test-stow
cwd restored to /home/user/test-stow/stow
Processing tasks... done
Note that this *does* create the symlink to ./car
, despite the ignore
line in ./.stowrc
.
Now I undo the operation by running stow -D --verbose=3 a/
:
user@user-machine:~/test-stow/stow$ stow -D --verbose=3 a/
stow dir is /home/user/test-stow/stow
stow dir path relative to target /home/user/test-stow is stow
cwd now /home/user/test-stow
Planning unstow of package a...
Unstowing from . (cwd=~/test-stow, stow dir=stow)
Unstowing stow/a/car
car did not exist to be unstowed
Planning unstow of package a... done
cwd restored to /home/user/test-stow/stow
cwd now /home/user/test-stow
cwd restored to /home/user/test-stow/stow
Processing tasks...
If I delete everything in ./.stowrc
and run stow --verbose=3 --ignore='car' a/
, I get a different result:
user@user-machine:~/test-stow/stow$ stow --verbose=3 --ignore='car' a/
stow dir is /home/user/test-stow/stow
stow dir path relative to target /home/user/test-stow is stow
cwd now /home/user/test-stow
cwd restored to /home/user/test-stow/stow
cwd now /home/user/test-stow
Planning stow of package a...
Stowing contents of stow/a (cwd=~/test-stow)
Planning stow of package a... done
cwd restored to /home/user/test-stow/stow
Processing tasks...
Now a symlink to ./car
was *not* created, as expected and desired.
# What about $HOME/.stowrc
?
Placing the .stowrc
file in the home directory instead of $HOME/test-stow/stow
has the same effect; a symlink to the file car
still gets made.
# Ignore lists
Having a file $HOME/test-stow/stow/.stow-local-ignore
with the content "car" instead of the .stowrc
file doesn't work, either. The symlink to the file named car
still gets created.
---
**GNU Stow version**: 2.2.0
**Perl version**: perl 5, version 18
# Update
[Here] is my reply to Adam Spiers' answer.
Guildenstern
(452 rep)
Aug 21, 2016, 05:54 PM
• Last activity: Aug 31, 2022, 02:22 AM
2
votes
2
answers
1394
views
FreeBSD: /etc/rc.conf persistently read-only
I am running a single-user FreeBSD and I am trying to edit ```rc.conf``` but it appears to be read-only for some reason. I can't change it from the root account. Indeed, ```id``` gives: ```uid=0(root) gid=0(wheel) groups=0(wheel),5(operator)``` Trying to mount with ```mount -u -w``` does not help ei...
I am running a single-user FreeBSD and I am trying to edit
.conf
but it appears to be read-only for some reason. I can't change it from the root account. Indeed,
gives:
=0(root) gid=0(wheel) groups=0(wheel),5(operator)
Trying to mount with -u -w
does not help either.
Tomasz Kania
(123 rep)
Jul 18, 2022, 04:39 PM
• Last activity: Jul 19, 2022, 09:58 AM
1
votes
0
answers
967
views
For automatic startup is it enough to copy script to /etc/rc.d folders?
we have installed some tool on RedHat linux 8.5 which comes with a README file that explains steps we should do, in order to enable automatic startup: - Copy the 'accurev' script to the /etc/rc.d/init.d/ `cp /opt/accurev/extras/unix/accurev /etc/rc.d/init.d/` - make links as follows `ln -s /etc/rc.d...
we have installed some tool on RedHat linux 8.5 which comes with a README file that explains steps we should do, in order to enable automatic startup:
- Copy the 'accurev' script to the /etc/rc.d/init.d/
cp /opt/accurev/extras/unix/accurev /etc/rc.d/init.d/
- make links as follows
ln -s /etc/rc.d/init.d/accurev /etc/rc.d/rc0.d/K35accurev
ln -s /etc/rc.d/init.d/accurev /etc/rc.d/rc1.d/K35accurev
ln -s /etc/rc.d/init.d/accurev /etc/rc.d/rc2.d/S77accurev
ln -s /etc/rc.d/init.d/accurev /etc/rc.d/rc3.d/S77accurev
ln -s /etc/rc.d/init.d/accurev /etc/rc.d/rc5.d/S77accurev
ln -s /etc/rc.d/init.d/accurev /etc/rc.d/rc6.d/K35accurev
README file does not contain any further instructions.
Since this is a production server I cannot test this properly, unfortunately.
Will this be enough to have the script started upon the reboot?
I was searching the similar topics like https://unix.stackexchange.com/questions/20357/how-can-i-make-a-script-in-etc-init-d-start-at-boot and they mention the chkconfig
tool which this README instruction does not mention, so I just wanted to be sure if I covered all the steps.
I couldn't find any instruction related to /etc/rc.d
without mentioned chkconfig
tool
Thanks a lot!
AndreyS
(288 rep)
Jun 22, 2022, 08:43 AM
• Last activity: Jun 22, 2022, 08:57 AM
3
votes
1
answers
10999
views
Windows Subsystem for Linux is unable to determine current runlevel
# Issue Many apt-get installs are failing b/c the system can't determine current runlevel # Background specs: $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.1 LTS Release: 16.04 Codename: xenial $ uname -a Linux systemName 4.4.0-43-Microsoft #1-Micros...
# Issue
Many apt-get installs are failing b/c the system can't determine current runlevel
# Background specs:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.1 LTS
Release: 16.04
Codename: xenial
$ uname -a
Linux systemName 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014 x86_64 x86_64 x86_64 GNU/Linux
# Explaniation
I am trying to install virtualbox on WSL and I got the following error:
$ VBoxManage --version
WARNING: The character device /dev/vboxdrv does not exist.
Please install the virtualbox-dkms package and the appropriate
headers, most likely linux-headers-Microsoft.
I solved this by following these steps . To
dpkg-reconfigure virtualbox-dkms
.
But then I got the following:
dpkg: warning: version '*-*' has bad syntax: version number does not start with digit
It is likely that 4.4.0-43-Microsoft belongs to a chroot's host
Module build for the currently running kernel was skipped since the
kernel source for this kernel does not seem to be installed.
invoke-rc.d: could not determine current runlevel
How can get the invoke-rc.d to return the correct runlevel?
Gabriel Fair
(371 rep)
Apr 13, 2017, 04:00 PM
• Last activity: Jan 30, 2022, 11:00 PM
1
votes
1
answers
215
views
Would including a line like "source ~/rc/.zshrc" in my ~/.zshrc be equivelent to including all the text from ~/rc/.zshrc in my ~/.zshrc?
I want to keep my `~/.zshrc` in a github repo, and since I don't want to make my ~ folder a git repository, I plan to move my `~/.zshrc` to a folder called `rc` and then include `source ./rc/.zshrc` in my `~/.zshrc` file. I'm wondering if there's any reason to keep everything within the actual `~/.z...
I want to keep my
~/.zshrc
in a github repo, and since I don't want to make my ~ folder a git repository, I plan to move my ~/.zshrc
to a folder called rc
and then include source ./rc/.zshrc
in my ~/.zshrc
file.
I'm wondering if there's any reason to keep everything within the actual ~/.zshrc
file instead of moving it to ~/rc/.zshrc
-----------------------
I use an Intel mac, could possibly use the .zshrc
on a cloud server with ubuntu, and will probably get a mac with an M chip in the next few years if that's relevant
Sam
(33 rep)
Nov 7, 2021, 12:36 AM
• Last activity: Nov 7, 2021, 05:47 AM
0
votes
0
answers
40
views
How do I know what config files are being read by my bash shell?
I'm on a macOS system. My `SHELL` variable says `/bin/bash`, but I have Homebrew `bash` installed too. I deleted my `.bash_profile` file, and my `.bashrc` only sets the `PATH`. But now every time I type Command + T to open a new tab in `Terminal.app`, something echoes the word `foo` just before I'm...
I'm on a macOS system. My
SHELL
variable says /bin/bash
, but I have Homebrew bash
installed too.
I deleted my .bash_profile
file, and my .bashrc
only sets the PATH
. But now every time I type Command+T to open a new tab in Terminal.app
, something echoes the word foo
just before I'm given my prompt. I grepped around in /etc
and found nothing, but since this is a Mac things might just be arranged differently.
Is there a way to know which config files are being read in when I start up a shell? Where should I look?
Lucky
(129 rep)
Sep 29, 2021, 07:51 PM
• Last activity: Sep 30, 2021, 08:07 AM
0
votes
2
answers
312
views
How to run Odoo ERP as daemon on FreeBSD?
I've cloned odoo ERP using git, in directory /home/amr/erp/odoo. Of course I've create a virtual environment and created a startup script "odoo" in /usr/local/etc/rc.d My concern is not to run the rc script as a root user so I've created a non login user by the following command: ``` pw adduser odoo...
I've cloned odoo ERP using git, in directory /home/amr/erp/odoo. Of course I've create a virtual environment and created a startup script "odoo" in /usr/local/etc/rc.d
My concern is not to run the rc script as a root user so I've created a non login user by the following command:
pw adduser odoo -d /nonexistent -s /usr/sbin/nologin -c "Odoo ERP"
My problem is that when I run the app with "odoo" user it fails but when I run it with "amr" user it starts.
So how I can make the app run with "odoo" user, here my rc script:
#!/bin/sh
#
# PROVIDE: odoo
# REQUIRE: DAEMON
# KEYWORD: shutdown
#
. /etc/rc.subr
name="odoo"
user="odoo"
rcvar="odoo_enable"
odoo_command="/home/amr/erp/odoo/.venv/bin/python /home/amr/erp/odoo/odoo-bin -c /home/amr/erp/odoo/odoo.conf --without-demo=all"
pidfile="/var/run/${name}.pid"
command="/usr/sbin/daemon"
command_args="-P ${pidfile} -u ${user} -r -f ${odoo_command}"
load_rc_config "${name}"
: "${odoo_enable:=no}"
run_rc_command "$1"
Amr
(61 rep)
Jan 3, 2021, 11:18 AM
• Last activity: Aug 12, 2021, 04:15 AM
1
votes
2
answers
8696
views
How to automatically add keyfile and passphrase to ssh-agent?
Linux 4.4.0-34-generic #53-Ubuntu SMP Wed Jul 27 16:06:39 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux I use the script to start ssh-agent and start other script (which is using *expect* to sent passphrase to agent). #!/bin/bash eval `ssh-agent -s` /root/script2 **/root/script2:** #!/usr/bin/expect -f sp...
Linux 4.4.0-34-generic #53-Ubuntu SMP Wed Jul 27 16:06:39 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
I use the script to start ssh-agent and start other script (which is using *expect* to sent passphrase to agent).
#!/bin/bash
eval
ssh-agent -s
/root/script2
**/root/script2:**
#!/usr/bin/expect -f
spawn ssh-add /root/.ssh/key
expect "Enter passphrase for /root/.ssh/key:"
send "passphrase\n";
interact
All scripts are +x
Passphrase is valid 100%
After starting first script I get:
Agent pid 3985
spawn ssh-add /root/.ssh/key
Enter passphrase for /root/.ssh/key:
Identity added: /root/.ssh/key (/root/.ssh/key)
As you see, *agent started* and *Identity added* BUT when I try "*ssh-add -l*" I get:
Error connecting to agent: No such file or directory
But process is still working with 3985 PID.
Why it tells me *Identity added* but *ssh-add -l* didn't work? :(
Ok, I try manually eval ssh-agent and add keyfile:
root@:~# eval ssh-agent -s
Agent pid 4063
root@:~# ssh-add -l
The agent has no identities.
root@:~# ssh-add /root/.ssh/key
Enter passphrase for /root/.ssh/key:
Identity added: /root/.ssh/key (/root/.ssh/key)
root@:~# ssh-add -l
4096 SHA256:FxPiCFYOiRree0ogNPpo81DTDUqmr1Brlo0LFnFK12o /root/.ssh/key (RSA)
Why it work when I try to run it manually? How to fix that?
I want to add that to rc.local to autostart it when PC starts.
UPD
if I try to run only **script2** manually, it works (key adds to agent).
So I thing problem is with eval sh-agent, but I don't know what's wrong
rGA145
(449 rep)
Aug 21, 2016, 09:23 PM
• Last activity: Aug 10, 2021, 11:15 PM
2
votes
1
answers
602
views
how to distinguish ssh from scp in ~/.ssh/rc?
I'd like to launch `neofetch` (a small utility that displays a banner) each time I log into a remote server via OpenSSH. So, I just added `/usr/bin/neofetch` into my `~/.ssh/rc` file, and it works fine. The problem is that `~/.ssh/rc` is also parsed when I `scp` into the server. A complete `scp` com...
I'd like to launch
neofetch
(a small utility that displays a banner) each time I log into a remote server via OpenSSH. So, I just added /usr/bin/neofetch
into my ~/.ssh/rc
file, and it works fine.
The problem is that ~/.ssh/rc
is also parsed when I scp
into the server. A complete scp
command works just fine, there is however a problem when I try to use the autocomplete feature of scp
, when I type `` so it displays the files/folders available on the remote server, example :
$ scp remote-host:/t
\\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\`\\\"\\\"\\\"\\\
\\\ \\\$\\\$\\\:\\\ \\\ \\\ \\\ \\\ \\\ \\\$\\\$.\\\ \\\ \\\ ^\\\[0m^[\\\[31m^[\\\[1m-^[\\\[0m^[\\\[1m\\\ \\\ \\\ \\\ \\\,d\\\$\\\$\\\'\\\
\\\ \\\ \\\ \\\ \\\ \\\`\\\$\\\$b.\\\
\\\ \\\,\\\$\\\$P\\\'\\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\`\\\$\\\$\\\$.\\\
\\\ \\\$\\\$P\\\ \\\ \\\ \\\ \\\ \\\ d\\\$\\\'\\\ \\\ \\\ \\\ \\\ ^[\\\[0m^[\\\[31m^[\\\[1m\\\,^[\\\[0m^[\\\[1m\\\ \\\ \\\ \\\ \\\$\\\$P\\\
\\\'\\\,\\\$\\\$P\\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\,ggs.\\\ \\\ \\\ \\\ \\\ \\\`\\\$\\\$b\\\:\\\
\\\ \\\$\\\$\\\;\\\ \\\ \\\ \\\ \\\ \\\ Y\\\$b._\\\ \\\ \\\ _\\\,d\\\$P\\\'\\\
^[\\\[0m^[\\\[1m\\\ \\\`\\\$\\\$b\\\ \\\ \\\ \\\ \\\ \\\ ^[\\\[0m^[\\\[31m^[\\\[1m\\\"-.__\\\
^[\\\[0m^[\\\[1m\\\ \\\ \\\`Y\\\$\\\$\\\
(...)
Usually $ scp remote-host:/t
shows me the files/folders starting with /t
(for example /tmp
), but now it executes the neofetch
banner.
Is there a way to distinguish $ ssh
from $ scp
in ~/.ssh/rc
(to launch neofetch
only when I ssh
into the server, not when I scp
into it) ?
Note : I don't want to launch neofetch each time I launch bash, nor each time I launch a login shell, so putting it in /etc/bash.bashrc
or in /etc/profile
is not an option. I only want to launch it after an SSH connection.
I did some research and tried a few things :
- Inspired by [this post , I tried :
[ -t 0 ]; then /usr/bin/neofetch; fi
and
tty > /dev/null; then /usr/bin/neofetch; fi
But it's not working (neofetch
is never launched, not even after an $ ssh
)
- Inspired by that post , I also tried to use the $-
environment variable to distinguish between interactive and non interactive sessions, but it doesn't work either, because ~/.ssh/rc
is parsed by dash, not by bash (and $-
is a bash variable)
I found however a working solution (well, sort of...). It was inspired by this post :
- On the server, in ~/.ssh/rc
, I put :
[ ! "$LC_SCP" = "yes" ]; then /usr/bin/neofetch; fi
- On the client, I have to set an LC_SCP
environment variable before the $ scp
:
$ export LC_SCP=yes
$ scp -o SendEnv=LC_SCP remote-host:/t
(works, doesn't launch neofetch)
It works, but it's cumbersomee. Isn't there a better way to distinguish between ssh
and scp
sessions in ~/.ssh/rc
?
ChennyStar
(1969 rep)
Jul 6, 2021, 05:06 PM
• Last activity: Jul 6, 2021, 07:42 PM
Showing page 1 of 20 total questions