我已经使用/etc/profile
以下方法设置了我的环境变量:
export VAR=/home/userhome
Run Code Online (Sandbox Code Playgroud)
然后,如果我这样做,echo $VAR
它会显示/home/userhome
但是当我把这个变量的引用放到/etc/init.d/servicename
文件中时,它找不到这个变量。当我service servicename status
使用/etc/init.d/servicename
具有以下内容的文件运行时:
case "$1" in
status)
cd $VAR/dir
;;
esac
Run Code Online (Sandbox Code Playgroud)
它说 /dir: No such file or directory
但如果我运行/etc/init.d/servicename status
而不是service servicename status
如何让 unix 服务看到环境变量?
我需要运行一个软件系统,该系统旨在作为设备安装在专用机器上。为了节省能源,我计划在 VirtualBox VM 上运行系统。
主机是一个带有 SysV-Init 系统的标准 Linux 机器,来宾是一个经过大量修改的 Linux,我不想进一步修改它。VirtualBox 用于 OSE 版本。
我已经想出了如何在主机启动时启动 VM(编辑:这是通过命令完成的,正如 Nikhil 在下面提到的,通过命令VBoxManager startvm
),但是我怎样才能正常关闭 VM?在主机上运行的任何脚本都需要等到来宾完全关闭。
任何人都可以建议如何,例如,执行此操作的服务文件必须看起来如何?
我有 NFSv4 服务器(在 RHELv6.4 上)和 NFS 客户端(CentOSv6.4)。让我们说/etc/exports
:
/shares/website1 <ip-client-1>(rw,sync,no_subtree_check,no_root_squash)
/shares/website2 <ip-client-2>(rw,sync,no_subtree_check,no_root_squash)
Run Code Online (Sandbox Code Playgroud)
然后每当我对此进行一些更改时(假设更改仅适用于client-2
),例如:
/shares/website1 <ip-client-1>(rw,sync,no_subtree_check,no_root_squash)
/shares/xxxxxxxx <ip-client-2>(rw,sync,no_subtree_check,no_root_squash)
Run Code Online (Sandbox Code Playgroud)
然后我总是service nfs restart
。然后最终..挂载点client-1
没有响应 (无法打开其文件等)。(为什么?因为RESTART?)
但如上所述,我只修改了该行client-2
。一切client-1
都还没有改变。
所以我的问题是:
/etc/exports
,我应该restart
提供服务还是什么?service nfs restart
,为什么其他客户端上的挂载点最终会受到影响?(对于那些没有对其进行任何更改的客户端机器/etc/exports
。)这意味着,每当我做出改变/etc/exports
和restart
服务,我将需要去重新mount上的目录EVERY CLIENTS导出列表中,以具有安装点再次合作。
有什么想法吗?
你如何阻止命令service <name> status
使用less
在它的输出?
我有一个脚本可以自动执行一些 sysadmin 操作,在我将服务器升级到 Ubuntu 16.04 后,它中断了,因为检查服务状态的操作被阻塞,因为它使用类似less
显示输出的东西,特别是supervisor
服务。
我有几个守护进程配置为运行,当运行时sudo service supervisor status
,我得到:
* supervisor.service - Supervisor process control system for UNIX
Loaded: loaded (/lib/systemd/system/supervisor.service; disabled; vendor preset: enabled)
Active: active (running) since Mon 2017-02-06 20:35:34 EST; 12h ago
Docs: http://supervisord.org
Process: 18476 ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown (code=exited, status=0/SUCCESS)
Main PID: 20228 (supervisord)
CGroup: /system.slice/supervisor.service
|- 7387 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
|- 7388 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A …
Run Code Online (Sandbox Code Playgroud) 来自我的问题守护进程的进程 id 和会话 id 可以不同吗?,很明显我不能轻易决定守护进程的特性。我在不同的文章和不同的论坛中读到过,该service --status-all
命令可用于列出我系统中的所有守护程序。但是我不认为该命令会列出所有守护程序,因为该命令未列出NetworkManager
当前在我的Ubuntu 14.04
系统中运行的守护程序。是否有一些命令可以列出正在运行的守护程序,或者有什么方法可以从filesystem
自身中找到守护程序?
我正在运行 Ubuntu,其中有目录/etc/rc0.d
, /etc/rc1.d
, /etc/rc2.d
, ..., /etc/rc6.d
。
我机器上的示例文件:
directory example symlinks in the dir
------------------------------------------
/etc/rc1.d: K76dovecot, K77ntp
/etc/rc2.d: S23ntp, S24dovecot
/etc/rc3.d: S23ntp, S24dovecot
/etc/rc4.d: S23ntp, S24dovecot
/etc/rc5.d: S23ntp, S24dovecot
Run Code Online (Sandbox Code Playgroud)
问题:
dovecot
和 的重复安装ntp
到除rc0.d
和之外的所有目录中rc6.d
?dovecot
并ntp
在启动时执行吗?ntp
前始终执行的正确方法是什么dovecot
?我正在使用 CentOS 7,我的目标是每五秒创建一个 cron,但正如我研究的那样,我们只能使用 cron 一分钟,所以我现在正在做的是我创建了一个 shell 文件。
命中.sh
while sleep 5; do curl http://localhost/test.php; done
Run Code Online (Sandbox Code Playgroud)
但我通过右键单击它手动点击了它。
我想要的是为该文件创建一个服务,以便我可以自动启动和停止它。
#!/bin/bash
# chkconfig: 2345 20 80
# description: Description comes here....
# Source function library.
. /etc/init.d/functions
start() {
# code to start app comes here
# example: daemon program_name &
}
stop() {
# code to stop app comes here
# example: killproc program_name
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start …
Run Code Online (Sandbox Code Playgroud) 我想在启动到系统后每 30 分钟执行一次脚本。我知道您可以使用 cron,但我不打算经常使用此功能,因此我想在 systemd 上尝试一下。
到目前为止,我只找到了允许执行一次的单调定时器(至少我是这么认为的)。如果我想从启动/系统启动每 30 分钟执行一次,那么foo.timer
和foo@user.service
会是什么样子?
foo@user.service
[Unit]
Description=run foo
Wants=foo.timer
[Service]
User=%I
Type=simple
ExecStart=/bin/bash /home/user/script.sh
Run Code Online (Sandbox Code Playgroud)
foo.timer
[Unit]
Description=run foo
[Timer]
where I am stuck... ???
Run Code Online (Sandbox Code Playgroud) 我创建了以下服务,amos.service,它需要作为 amos(amos 组的成员)运行
[Unit]
Description=AMOS Service
After=network.target
[Service]
User=amos
Group=amos
Type=simple
WorkingDirectory=/usr/share/amos
ExecStart=/usr/share/amos/amos_service.sh start
ExecStop=/usr/share/amos/amos_service.sh stop
Restart=on-failure
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
所有权限都已设置/usr/share/amos
为amos:amos
amos_service.sh 如下:
#!/bin/bash
CUDIR=$(dirname "$0")
cd /usr/share/amos
start() {
exec /usr/share/amos/run_amos.sh >> /var/log/amos.log 2>&1
}
stop() {
exec pkill java
}
case $1 in
start|stop) "$1" ;;
esac
cd "$CURDIR"
Run Code Online (Sandbox Code Playgroud)
当我最初运行该服务而不对目录进行任何修改时,这意味着属于 root 并且 amos.service 没有 User not Group 参数,一切运行良好!
一旦我将目录权限更改为 amos:amos 并添加 amos.service 用户和组,该服务将无法工作,我得到以下信息:见附图
services ×10
systemd ×3
init-script ×2
accounts ×1
centos ×1
cron ×1
daemon ×1
init ×1
init.d ×1
linux ×1
mount ×1
nfs ×1
scheduling ×1
shell-script ×1
sysvinit ×1
users ×1
virtualbox ×1