[Terminal] BUG:systemctl start启动命令不返回,一直光标闪烁
Tofloor
poster avatar
深圳市耀影科技有限公司
deepin
2021-06-03 06:36
Author

我遇到了类似systemctl的问题,其中start败,但服务其实已经正常运行并正确启动.
当我跑的时候“sudo systemctl start xxxx.service” 它不返回/退出,

-只是一直停留在那里光标闪烁。

我已经确认服务器已经启动并运行,所以服务器似乎运行良好-

 

我不知道为什么systemctl start从不退出。  

 

但我认为这意味着出了问题.您是否知道此消息的含义以及我可以采取的措施?

 

因为这个错误不返回,已经影响Unit 配置启动依赖“Requires=”的问题 出现错误判断依赖启动项没有启动成功

 

 

 

Reply Favorite View the author
All Replies
deepinuser17
deepin
2021-06-03 07:53
#1

查看xxxx.service文件的内容. 运行程序没有自动进入后端运行, 可能是在前端运行.

xxxx.service 文件被存在/lib/systemd/system 或 /etc/systemd/system 文件夹里.

 

运行程序如果没有daemon状态, 在运行命令后面加"&"

Reply View the author
深圳市耀影科技有限公司
deepin
2021-06-03 18:38
#2

加入& 确实可以返回结果,但是默认不应该是这样的,这里是否是一个BUG呢?

文件1  postgresql.service  内容和路径如下

“sudo deepin-editor /etc/systemd/system/postgresql.service”

[Unit]
Description=PostgreSQL database server
Documentation=man:postgres(1)

[Service]
Type=notify
User=postgres
ExecStart=/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0

[Install]
WantedBy=multi-user.target

 

 

 

文件2  odoo14.service,内容路径如下

`sudo deepin-editor /etc/systemd/system/odoo14.service`

[Unit]
Description=odoo14
Requires=postgresql.service
After=network.target postgresql.service
[Service]
Type=simple
SyslogIdentifier=odoo14
PermissionsStartOnly=true
User=yaoying
Group=yaoying
ExecStart=/home/yaoying/.pyenv/versions/3.9.5/envs/odoo14/bin/python3 /home/yaoying/odoo/odoo-bin -c /etc/odoo14.conf
StandardOutput=journal+console
[Install]
WantedBy=multi-user.target

 

 

因为文件2 

依赖启动配置关联的这个Requires=postgresql.service,服务不返回参数,导致Rrquires 配置的postgresql.service认为没有启动,因此当前文件2 odoo14.service 直接不执行启动

Requires=postgresql.service

After=network.target postgresql.service

Reply View the author
深圳市耀影科技有限公司
deepin
2021-06-03 18:39
#3
deepinuser17

查看xxxx.service文件的内容. 运行程序没有自动进入后端运行, 可能是在前端运行.

xxxx.service 文件被存在/lib/systemd/system 或 /etc/systemd/system 文件夹里.

 

运行程序如果没有daemon状态, 在运行命令后面加"&"

是否有办法呢?因为在之前的系统版本并没有存在这个问题,当前系统DEEPIN V20.2.1

Reply View the author
深圳市耀影科技有限公司
deepin
2021-06-03 20:07
#4

问题好像出现在“sudo deepin-editor /etc/systemd/system/postgresql.service”

 

Type=notify 这个配置,

Reply View the author
deepinuser17
deepin
2021-06-04 08:00
#5
深圳市耀影科技有限公司

问题好像出现在“sudo deepin-editor /etc/systemd/system/postgresql.service”

 

Type=notify 这个配置,

这个命令的结果是打开深度编辑器. 打开以后要做修改吗? 还是只是打开?

 

把xxxx.service的内容发一下.

Reply View the author
深圳市耀影科技有限公司
deepin
2021-06-04 17:43
#6
deepinuser17

这个命令的结果是打开深度编辑器. 打开以后要做修改吗? 还是只是打开?

 

把xxxx.service的内容发一下.

 

我是在源码编译安装PGSQL

sudo apt-get update && sudo apt-get install libreadline-dev
wget https://ftp.postgresql.org/pub/source/v13.3/postgresql-13.3.tar.gz
gunzip postgresql-13.3.tar.gz
tar xf postgresql-13.3.tar
cd ./postgresql-13.3
./configure
make
sudo make install  
sudo adduser postgres    #创建用户postgres
sudo mkdir -p /data/usr/local/pgsql/data     #生成数据库文件目录data
sudo chown postgres /data/usr/local/pgsql/data  #授权data授权用户postgres用户文件访问权限变更
su - postgres  #切换到数据库用户postgres

2 ## 初始化系统数据库
`/usr/local/pgsql/bin/initdb -D /data/usr/local/pgsql/data`

# 开机启动
http://www.postgres.cn/docs/13/server-start.html


您可以使用以下命令创建服务
`sudo deepin-editor /etc/systemd/system/postgresql.service`
打开文件后,添加以下行:

```
[Unit]
Description=PostgreSQL database server
Documentation=man:postgres(1)

[Service]
Type=notify
User=postgres
ExecStart=/usr/local/pgsql/bin/postgres -D /data/usr/local/pgsql/data
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0

[Install]
WantedBy=multi-user.target
```

保存并关闭文件,然后systemd使用以下命令重新加载守护程序列表:下一步我们需要使用如下命令来注册这个新服务:
`sudo systemctl daemon-reload`
现在,您可以启动Odoo 14服务,并使用以下命令使其在启动时启动:
```
sudo systemctl start postgresql
sudo systemctl enable postgresql
```
现在,您可以通过以下方式验证Odoo 14服务的状态:
 `sudo systemctl status postgresql`

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

这个就是XXXX.service 内容,sudo deepin-editor 是打开编辑的命令,打开后就是一个可视化文本编辑器,把一下内容放进去然后保存就行 

“sudo deepin-editor /etc/systemd/system/postgresql.service”

[Unit]
Description=PostgreSQL database server
Documentation=man:postgres(1)

[Service]
Type=notify
User=postgres
ExecStart=/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0

[Install]
WantedBy=multi-user.target
Reply View the author
deepinuser17
deepin
2021-06-04 20:45
#7

查看postgresql.service是否正常运行.

 

systemctl status postgresql.service

 

/usr/local/pgsql/data 这个文件夹的用户是postgres.
Reply View the author
深圳市耀影科技有限公司
deepin
2021-06-05 01:23
#8
deepinuser17

查看postgresql.service是否正常运行.

 

systemctl status postgresql.service

 

/usr/local/pgsql/data 这个文件夹的用户是postgres.

/usr/local/pgsql/data 这个文件夹的用户是postgres. 是的,这个是postgres用户

 

 

运行是正常的,但是它不返回参数  光标一直闪烁

Reply View the author
deepinuser17
deepin
2021-06-05 18:57
#9

PostgreSQL官方提供了编译好的PostgreSQL 13发行版. 除非有特别的需要, 一般尽量避免自己编译.

 

 

在Debian平台上, PostgreSQL官方的启动文件是, /lib/systemd/system/postgresql@.service. 其内容如下:

[Unit]
Description=PostgreSQL Cluster %i
AssertPathExists=/etc/postgresql/%I/postgresql.conf
RequiresMountsFor=/etc/postgresql/%I /var/lib/postgresql/%I
PartOf=postgresql.service
ReloadPropagatedFrom=postgresql.service
Before=postgresql.service
After=network.target

[Service]
Type=forking
ExecStart=-/usr/bin/pg_ctlcluster --skip-systemctl-redirect %i start
TimeoutStartSec=0
ExecStop=/usr/bin/pg_ctlcluster --skip-systemctl-redirect -m fast %i stop
TimeoutStopSec=1h
ExecReload=/usr/bin/pg_ctlcluster --skip-systemctl-redirect %i reload
PIDFile=/run/postgresql/%i.pid
SyslogIdentifier=postgresql@%i
OOMScoreAdjust=-900

[Install]
WantedBy=multi-user.target

 

可见启动命令已经变成了pg_ctlcluster.

 

通过PostgreSQL官方源安装PostgreSQL 13的步骤如下:

sudo apt update
sudo apt -y install gnupg2
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" |sudo tee  /etc/apt/sources.list.d/pgdg.list

sudo apt update
sudo apt -y install postgresql-13 postgresql-client-13

 

安装后PostgreSQL 13自动开始运行. 用下面这个命令查看运行状态:

systemctl status postgresql@13-main.service

 

对于手动编译的PostgreSQL, 试试把启动命令改成:

ExecStart=/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data  -c config_file=/usr/local/etc/postgresql/postgresql.conf

确认config_file的实际路径, 并替换.

Reply View the author
深圳市耀影科技有限公司
deepin
2021-06-12 23:32
#10
deepinuser17

PostgreSQL官方提供了编译好的PostgreSQL 13发行版. 除非有特别的需要, 一般尽量避免自己编译.

 

 

在Debian平台上, PostgreSQL官方的启动文件是, /lib/systemd/system/postgresql@.service. 其内容如下:

[Unit]
Description=PostgreSQL Cluster %i
AssertPathExists=/etc/postgresql/%I/postgresql.conf
RequiresMountsFor=/etc/postgresql/%I /var/lib/postgresql/%I
PartOf=postgresql.service
ReloadPropagatedFrom=postgresql.service
Before=postgresql.service
After=network.target

[Service]
Type=forking
ExecStart=-/usr/bin/pg_ctlcluster --skip-systemctl-redirect %i start
TimeoutStartSec=0
ExecStop=/usr/bin/pg_ctlcluster --skip-systemctl-redirect -m fast %i stop
TimeoutStopSec=1h
ExecReload=/usr/bin/pg_ctlcluster --skip-systemctl-redirect %i reload
PIDFile=/run/postgresql/%i.pid
SyslogIdentifier=postgresql@%i
OOMScoreAdjust=-900

[Install]
WantedBy=multi-user.target

 

可见启动命令已经变成了pg_ctlcluster.

 

通过PostgreSQL官方源安装PostgreSQL 13的步骤如下:

sudo apt update
sudo apt -y install gnupg2
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" |sudo tee  /etc/apt/sources.list.d/pgdg.list

sudo apt update
sudo apt -y install postgresql-13 postgresql-client-13

 

安装后PostgreSQL 13自动开始运行. 用下面这个命令查看运行状态:

systemctl status postgresql@13-main.service

 

对于手动编译的PostgreSQL, 试试把启动命令改成:

ExecStart=/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data  -c config_file=/usr/local/etc/postgresql/postgresql.conf

确认config_file的实际路径, 并替换.

手动编译安装 比较方便配置和查找目录, DEB安装 有很多目录,按理说源码编译安装更好吧

Reply View the author
deepinuser17
deepin
2021-06-15 07:01
#11

系统安装的软件容易管理, 升级也容易. 而且不会因为系统升级而出现问题.

 

查看系统安装的软件目录非常方便:

 

比如查看某个软件是否安装:

dpkg -l | grep -i postgresql

 

查看某个软件包安装的所有文件:

$ dpkg -L openssh-server
/.
/etc
/etc/default
/etc/default/ssh
/etc/init.d
/etc/init.d/ssh
/etc/pam.d
/etc/pam.d/sshd
/etc/ssh
/etc/ssh/moduli
/etc/ufw
/etc/ufw/applications.d
/etc/ufw/applications.d/openssh-server
/lib
/lib/systemd
/lib/systemd/system
/lib/systemd/system/rescue-ssh.target
/lib/systemd/system/ssh.service
/lib/systemd/system/ssh.socket
/lib/systemd/system/ssh@.service
/usr
/usr/lib
/usr/lib/openssh
/usr/lib/openssh/ssh-session-cleanup
/usr/sbin
/usr/sbin/sshd
/usr/share
/usr/share/apport
/usr/share/apport/package-hooks
/usr/share/apport/package-hooks/openssh-server.py
/usr/share/doc
/usr/share/doc/openssh-client
/usr/share/doc/openssh-client/examples
/usr/share/doc/openssh-client/examples/ssh-session-cleanup.service
/usr/share/man
/usr/share/man/man5
/usr/share/man/man5/moduli.5.gz
/usr/share/man/man5/sshd_config.5.gz
/usr/share/man/man8
/usr/share/man/man8/sshd.8.gz
/usr/share/openssh
/usr/share/openssh/sshd_config
/usr/share/openssh/sshd_config.md5sum
/usr/share/doc/openssh-server
/usr/share/man/man5/authorized_keys.5.gz

 

查看某个文件是从哪个软件包安装的.

$ dpkg -S /usr/bin/deepin-movie
deepin-movie: /usr/bin/deepin-movie

$ dpkg -S /usr/bin/deepin-editor
deepin-editor: /usr/bin/deepin-editor

$ dpkg -S /lib/systemd/system/ssh.socket
openssh-server: /lib/systemd/system/ssh.socket
Reply View the author