Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

simplest/recommended way to run something at startup

New to Debian (Or Linux in general)? Ask your questions here!
Post Reply
Message
Author
alete
Posts: 19
Joined: 2017-05-19 16:42

simplest/recommended way to run something at startup

#1 Post by alete »

Hi everyone. I'm starting with debian, my linux knowledge is very little.
I'm trying to get a Bitcoin full-node up un running. Actually I already did and everything is working as expected.

I was wondering which is the simplest but recommended method to run something at startup, and I'll describe you what I read.
1) crontab: it seem pretty simple just adding a line @reboot bitcoind -daemon, but I read that @reboot only executes on actual reboots and not after system halted, that's not what I'm looking for.
2) edit /etc/rc.local: I wasn't able to find this in my debian stretch, I read that it was replaced with systemd or something? (remember, beginner here)

so, what is a simple way to run something at startup?

The idea is that bitcoin daemon run even BEFORE any user autenticates on every startup for whatever reason.

Sorry for my non-native english and thanks in advance for your advices.

edit: it should be BEFORE, not after any user logins.
Last edited by alete on 2017-06-12 11:26, edited 1 time in total.

User avatar
orythem27
Posts: 252
Joined: 2017-05-11 07:59
Location: P.R. China

Re: simplest/recommended way to run something at startup

#2 Post by orythem27 »

alete wrote:The idea is that bitcoin daemon run even after any user autenticates on every startup for whatever reason
Does that mean after user has logged in from the "graphical login screen" into the desktop on system startup, not after unlocking the screen or switch user?
If so:
If you are running Bitcoin Core GUI, then you can configure autostart behaviour in the Bitcoin Core GUI options.
If you only have Bitcoin Core Daemon, then the easiest way to run it as the regular user is to add the startup command to your desktop environment's "Startup Applications" config tool such as this and this.
alete wrote: edit /etc/rc.local: I wasn't able to find this in my debian stretch, I read that it was replaced with systemd or something
Systemd still provides rc-local.service. The content of /etc/rc.local will be executed towards the end of multi-user.target if /etc/rc.local is marked executable. But you might not want this since (1) By default it execute commands as root; (2) It will be executed before user has logged in.

User avatar
pylkko
Posts: 1802
Joined: 2014-11-06 19:02

Re: simplest/recommended way to run something at startup

#3 Post by pylkko »

A Systemd service file is easy to make, is very flexible and works/debugging easy. But if you require a desktop and a graphical instance of a programming then you should use your DE's autostart.

alete
Posts: 19
Joined: 2017-05-19 16:42

Re: simplest/recommended way to run something at startup

#4 Post by alete »

I'm sorry, I just edited the original post. :oops: :oops: :oops: :oops:
I mixed 'before' and 'after' somehow.
I'm trying to run bitcoind -daemon (without GUI) BEFORE any user logins. I'm running debian in my LattePanda which is a mini-pc like raspberry-pi but with an intel x64(x86) processor, and it is headless, I only access through SSH.

So I guess that I'll look for a way to start it with systemd like you suggested.

Thank you both.

alete
Posts: 19
Joined: 2017-05-19 16:42

Re: simplest/recommended way to run something at startup

#5 Post by alete »

Hi, Obviously I got troubles with this.
this my bitcoind.service

Code: Select all

[Unit]
Description=Bitcoin Daemon Service

[Service]
ExecStart=/usr/local/bin/bitcoind -daemon -datadir=/media/alete/SD/bitcoinData #I tried with ExecStart=bitcoind -daemon ...

[Install]
WantedBy=multi-user.target
then I:
systemctl enable bitcoind.service

then I sudo shutdown -r and nothing changed :s

Any advice? Thank you guys.

User avatar
orythem27
Posts: 252
Joined: 2017-05-11 07:59
Location: P.R. China

Re: simplest/recommended way to run something at startup

#6 Post by orythem27 »

You may want to add more configuration into the unit file. Start with skimming through `man systemd.service`.

1. When you execute `bitcoind -daemon` in a terminal, does it immediately returns you to the command prompt? Can you close the terminal and bitcoind would still be running in background?

If so, consider adding `Type=forking` to [Service]


2. Daemonized process usually use some pidfile to identify the main process, e.g. it could be located in /var/run or any other self-defined location.

Locate the pidfile and add `PIDFile=</path/to/pidfile>` to [Service]


3. Does bidcoind requires internet connection?

If so, consider adding `After=network.target` to [Unit]


4. You might not want to run bitcoind as root due to safety concerns.

If so, consider configuring "User" and "Group" in [Service]


Consult http://freedesktop.org/wiki/Software/systemd/Debugging/ if you would like to investigate the situation further.

You could always revert to /etc/rc.local if you couldn't make the systemd unit work.

User avatar
orythem27
Posts: 252
Joined: 2017-05-11 07:59
Location: P.R. China

Re: simplest/recommended way to run something at startup

#7 Post by orythem27 »

Oh, it seems that Bitcoin Core has already provided an "official" systemd unit file.
https://github.com/bitcoin/bitcoin/blob ... nd.service

Ignore me. :oops:

alete
Posts: 19
Joined: 2017-05-19 16:42

Re: simplest/recommended way to run something at startup

#8 Post by alete »

orythem27 wrote:Oh, it seems that Bitcoin Core has already provided an "official" systemd unit file.
https://github.com/bitcoin/bitcoin/blob ... nd.service

Ignore me. :oops:
:oops: that was a good call!
Thank you

Post Reply