Reboot and poweroff 'destructive' on Ubuntu 16.04 - ubuntu-16.04

When I try to reboot or turn off my laptop, it doesn't work. After investigating a little further:
$ systemctl status reboot.target
● reboot.target - Reboot
Loaded: loaded (/lib/systemd/system/reboot.target; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:systemd.special(7)
reboot is disabled. However, trying to enable it with systemctl enable reboot.target results in this output:
Failed to execute operation: File exists
After running reboot, I get the following error:
Failed to start reboot.target: Transaction is destructive.
See system logs and 'systemctl status reboot.target' for details.
I have no idea what to do; for now I'll just force poweroff, but I'd like to be able to use the reboot and shutdown functionality without cutting power every time I want to turn it off.

As documented in man systemctl, "enabling" a service typically means that you want it to run at boot. If the "reboot" target was enabled, you would be instructing your laptop to be rebooted as part of the boot process. That's probably not what you want.
In /etc/systemd/journald.conf, set Storage=persistent.
Then:
systemctl daemon-reload
After your next failed sudo reboot, check the contents of your systemd journal file to see if you can find something hanging during shutdown.

Related

How to run tailscale daemon with the --state=mem: flag

I want to run tailscale with the --state=mem: flag set on my server in order to gain the feature released in version 1.30.0 that will "delete node immediately if tailscaled exists and was using mem: state storage";
In the tailscale docs it says the following:
Can I create an ephemeral node without an auth key?
Yes, running Tailscale v1.22 or later. You can run tailscaled with the --state=mem: flag. tailscaled is the Tailscale daemon that runs on devices that have installed the Tailscale client. The --state=mem: flag registers the node as an ephemeral node so that the daemon stores state in memory, instead of writing it to disk.
How do I modify this flag on the tailscale daemon since it's not an option on the normal tailscale CLI?
systemctl edit tailscaled will open an editor to edit an file of customizations for tailscaled.service. You can add a FLAGS environment variable:
[Service]
Environment=FLAGS="--state=mem:"
Then run these commands to make it take effect:
sudo systemctl daemon-reload
sudo systemctl restart tailscaled

bindIP on CentOS for MongoDB process exited with error code

I'm editing a mongod.conf file to try and add a specific IP to be able to access the database with.
From what I've read I just need to edit this one file and add a second entry to bindIp
Like so:
net:
port: 27017
bindIp: 127.0.0.1, 11.222.333.44
Then save, close and run sudo systemctl restart mongod
Only when I run the restart I run into:
Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.
But when I run mongo I'm able to connect to the mongo shell locally but unable to connect remotely as the IP binding failed.
If you are able to connect locally, you are most likely connecting to an old process which means either:
process restart didn't work in that it failed to terminate the old process
your configuration is invalid, and restart process identified this and stopped
you have a mongod process running on the default port that you started manually and systemd can't stop it
Verify:
your configuration is correct
you don't have any mongod processes running
Then (re)start again.
Also, review the logs using the commands indicated.

PostgreSQL Services

Can someone give a detailed explanation of how the postgresql service(s) works on Ubuntu [16.04]? The behavior that leads me to ask is the following. I use the command sudo systemctl start postgresql to start my postgresql service. When I run systemctl list-units | grep post I see
UNIT LOAD ACTIVE SUB DESCRIPTION
postgresql.service loaded active exited PostgreSQL RDBMS
postgresql#9.6-main.service loaded active running PostgreSQL Cluster 9.6-main
system-postgresql.slice loaded active active system-postgresql.slice
and when I run sudo systemctl stop postgresql both postgresql.service and postgresql#9.6-main.service disappear. What is each of these three services doing?
I assume postgresql#9.6-main.service is registered service for PostgreSQL Cluster 9.6-main cluster. This is the one that actually controls postgres on your system.
I assume postgresql.service is the effect desribed here
I assume system-postgresql.slice is a postgres slice unit
none of above are critical for running postgres. You can start/stop the cluser with just pg_ctl, without registering it with your services. But if you wonder which service runs it in your case - then it is postgresql#9.6-main.service

Weird systemctl behavior

I installed Postgres9.6 on my Ubuntu 16.04 through apt-get. and I installed the same version on an AWS ubuntu instance to try replication.
I was following the steps from this blog:
http://www.rassoc.com/gregr/weblog/2013/02/16/zero-to-postgresql-streaming-replication-in-10-mins/
Now I can log to the postgres user on both machines, and run psql and execute all database operations. But when I check the status of the server (on both machines) using sudo systemctl status postgres.service, I get this:
● postgres.service Loaded: not-found (Reason: No such file or
directory) Active: inactive (dead)
Which is weird because I can run psql, right?
And this prevents me from creating remote connections.

How to restart Postgresql

I have PostgreSQL 9.3 and 9.4 installed on my Linux Mint machine.
How can I restart PostgreSQL 9.4?
A method to restart both versions together is also fine.
Try this as root (maybe you can use sudo or su):
/etc/init.d/postgresql restart
Without any argument the script also gives you a hint on how to restart a specific version
[Uqbar#Feynman ~] /etc/init.d/postgresql
Usage: /etc/init.d/postgresql {start|stop|restart|reload|force-reload|status} [version ...]
Similarly, in case you have it, you can also use the service tool:
[Uqbar#Feynman ~] service postgresql
Usage: /etc/init.d/postgresql {start|stop|restart|reload|force reload|status} [version ...]
Please, pay attention to the optional [version ...] trailing argument.
That's meant to allow you, the user, to act on a specific version, in case you were running multiple ones. So you can restart version X while keeping version Y and Z untouched and running.
Finally, in case you are running systemd, then you can use systemctl like this:
[Uqbar#Feynman ~] systemctl status postgresql
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2017-11-14 12:33:35 CET; 7min ago
...
You can replace status with stop, start or restart as well as other actions. Please refer to the documentation for full details.
In order to operate on multiple concurrent versions, the syntax is slightly different. For example to stop v12 and reload v13 you can run:
systemctl stop postgresql-12.service
systemctl reload postgresql-13.service
Thanks to #Jojo for pointing me to this very one.
Finally Keep in mind that root permissions may be needed for non-informative tasks as in the other cases seen earlier.
You can also restart postgresql by using this command, should work on both the versions:
sudo service postgresql restart
On Windows :
1-Open Run Window by Winkey + R
2-Type services.msc
3-Search Postgres service based on version installed.
4-Click stop, start or restart the service option.
On Linux :
sudo systemctl restart postgresql
also instead of "restart" you can replace : stop or status.
This should work:
sudo systemctl stop postgresql
sudo systemctl start postgresql
The right way to restart postgres server is to use
pg_ctl restart -D /home/postgres/postgresdbdata/
pg_ctl is usually found in location usr/local/pgsql/bin/pg_ctl if u dont have it added to your path.
Documentation can be found here
https://www.postgresql.org/docs/13/app-pg-ctl.html
This has more details on Start,Stop,Restart,etc of the postgres server.
You can firstly check for the postgress process running
ps -ef | grep post
You might need to use (post|pg) on the grep side, to discover the process for the Postgres service running on your machine, it might depend on your OS.
And you can just kill the child process since most of this process should restart automatically.
sudo kill $pid_of_the_child_process
macOS:
On the top left of the MacOS menu bar you have the Postgres Icon
Click on it this opens a drop down menu
Click on Stop -> than click on start